AWS Bedrock Guardrails
AWS Bedrock Guardrails let you define content policies in the AWS console and apply them to LLM traffic passing through agentgateway. When a request or response violates a guardrail policy, agentgateway blocks the interaction and returns an error.
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 promptGuard policy under policies.ai 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
binds:
- port: 3000
listeners:
- routes:
- backends:
- ai:
name: bedrock
provider:
openAI:
model: amazon.titan-text-express-v1
policies:
backendAuth:
key: "$BEDROCK_API_KEY"
ai:
promptGuard:
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.