AWS Bedrock Guardrails
AWS Bedrock Guardrails let you define content policies in the AWS console and apply them to LLM traffic passing through the agentgateway prxoy. When a request or response violates a guardrail policy, agentgateway blocks the interaction and returns an error.
AWS Bedrock Guardrails are model-agnostic and can be applied to any Large Language Model (LLM), whether it is hosted on AWS Bedrock, another cloud provider (like Google or Azure), or on-premises.
Before you begin
- Install the
agentgatewaybinary. - Create a guardrail in the AWS console or via the AWS CLI.
- Retrieve your guardrail identifier by running:
aws bedrock list-guardrails --region <aws-region> - Authenticate with AWS Bedrock using the standard AWS authentication sources. Make sure that you have permission to invoke the Bedrock Guardrails API.
Configure Bedrock Guardrails
Configure the guardrails field under llm.models[] in your agentgateway configuration. You can apply guardrails to the request phase, the response phase, or both.
cat <<'EOF' > config.yaml
# yaml-language-server: $schema=https://agentgateway.dev/schema/config
llm:
models:
- name: "*"
provider: openAI
params:
model: amazon.titan-text-express-v1
apiKey: "$BEDROCK_API_KEY"
guardrails:
request:
- bedrockGuardrails:
guardrailIdentifier: <your-guardrail-id>
guardrailVersion: DRAFT
region: us-west-2
policies:
backendAuth:
aws: {}
response:
- bedrockGuardrails:
guardrailIdentifier: <your-guardrail-id>
guardrailVersion: DRAFT
region: us-west-2
policies:
backendAuth:
aws: {}
EOF| Setting | Description |
|---|---|
guardrailIdentifier | The identifier of the Bedrock guardrail to apply. Retrieve this by running aws bedrock list-guardrails. |
guardrailVersion | The version of the guardrail. Use DRAFT for development or a specific version number for production. |
region | The AWS region where the guardrail is configured, such as us-west-2. |
policies.backendAuth.aws | AWS authentication configuration. Agentgateway uses the credentials available in the environment, such as environment variables or an instance profile. |
When a request or response matches a guardrail policy, agentgateway blocks the interaction and returns an error such as: The request was rejected due to inappropriate content.