Skip to main content
Guardrails allows you to deploy a dedicated server to run guard executions while continuing to use the Guardrails SDK as you do today. In this guide we show an example of deploying a containerized version of Guardrails API into AWS leveraging AWS ECS.
  • Read the quick start guide on using Guardrails on the server here
  • Find generalized information on deploying Guardrails here

Step 1: Containerizing Guardrails API

Updating Guardrails config + guard/validator definitions

Guardrails supports creating Guards from predefined templates.
Running the command above will create 2 local artifacts: a config.py and chatbot.json which is referenced in the config. The chatbot.json contains definitions for guards, validators and validator configurations. Each entry in guards is equivalent to a JSON serialization of guard.to_dict(). A simple example is below:
A template can also be a local json file with the format above. A config for it can be generated via the command below:
The validator arguments and entries can be updated manually or programmatically. For example we could update kwargs to only identify and fix location:
It is recommended to keep a requirements.txt or equivalent project dependencies file and template json in source control to allow CI/CD, targeted deployments and rollback. config.py is automatically generated. In some cases config.py might need to be customized. A customized config.py should be kept in source control and COPY’ed in the docker build step (skipping a guardrails create step that would overwrite it).

Container build

Building a guard can be achieved with docker. An example build file is below. It is recommended to keep the Dockerfile also in source control. Create a Dockerfile in a new working directory guardrails (or alternative).
The container above can be built and run locally with the following commands:

Step 2: Verification

Verification of guards should be done as programmatically as possible. Here is an example pytest that can test server based guards in a variety of ways. It is configured to run against the container above and do some basic tests around validation and integration with an LLM.

Step 3: Deploying infrastructure

By leveraging AWS ECS we can scale to handle increasing workloads by scaling the number of containers. Furthermore we can leverage a streamlined deployment process using ECS with rolling updates. We can now deploy the infrastructure needed for AWS ECS which includes:
  • Networking Resources (VPC, Load Balancer, Security Groups, Subnets, etc)
  • IAM Roles & Policies (ECS Task & Execution Role)
  • ECS Cluster (ECS Service, Task, Task Definition)
We start by initializing terraform with:
One can then copy the provided Terraform code or use their own by placing into our working directory and running:
Each can be configured based on your requirements. desired_count corresponds to the number of containers that should always be running. Alternatively one can configure a minimum & maximum count with some autoscaling policy. It is initially set to 0 since we have yet to upload the container to the AWS container registry (ECR).
Once the deployment has succeeded you should see some output values (which will be required if you wish to set up CI).

Step 4: Deploying Guardrails API

Manual

Firstly, create or use your existing guardrails token and export it to your current shell:
Run the following to build your container and push up to ECR:

Github Actions

Deployment can vary depending on hosting infrastructure and environment. For AWS we recommend using a service like ECS and triggering no downtime rolling deployments via something like Github actions. See the full Github Actions workflow example in the Guardrails repository.

Deployment/Update frequency

Generally guardrails core lib and validators are updated on a very regular basis (weekly) with bug fixes, security fixes and non-breaking feature updates. Every release is accompanied by release notes here. Large releases with breaking changes happen at a slower cadence and will be accompanied with migration guides. It is recommended to update on a semi-regular basis utilizing a CI/CD flow like the one outlined in this document. With the recommended steps below:
  1. Update the guardrails version tag
  2. Follow any migration guides that need to be applied
  3. Run build locally and verify tests pass
  4. Commit updates to source control
  5. Source control changes are approved and merged to main
  6. Github action triggers and updates are deployed

Remote inference

Validators that use LLMs and other models can often gain a large performance boost from running their inferences in batches on dedicated hardware with dedicated accelerators. It is also often advantageous to scale this infrastructure independently of the core guards and validators. Guardrails validators can run their ML models on a remote endpoint that you host yourself — point a validator at it with the validation_endpoint argument. (Guardrails’ previously free-hosted inference endpoints are being discontinued on August 6, 2026.) See more general information about remote inference here.

Using with SDK

You should be able to get the URL for your Guardrails API using:
By setting the above environment variable GUARDRAILS_BASE_URL the SDK will be able to use this as a backend for running validations.

Quick start repository template

We’ve conveniently packaged all the artifacts from this document in a github repository that can be used as a template for your own verification and deployment here.