AWS Bedrock Guardrails
AWS Bedrock Guardrails keep content policy in AWS, and AISIX applies the guardrail decision to gateway traffic. Requests can be checked before they reach the upstream model, and responses can be checked before they reach callers.
In this guide, you will create an AISIX Bedrock guardrail, send one allowed request, and send one blocked request that AISIX rejects before it reaches the upstream model.
Prerequisites
Before starting, prepare the following:
- Review Guardrail Behavior for hook points, enforcement modes, and remote failure handling.
- One of these configuration paths:
- AISIX Cloud with an environment, an attached gateway, and a write-scoped admin token. For On-Premises, follow the AISIX Cloud Quickstart. To request Hybrid Cloud access, contact API7.
- An open-source AISIX gateway that loads a declarative
resources.yamlfile.
- A working model alias and caller API key that can send Chat Completions requests.
- An AWS Bedrock guardrail in a supported region, with a word filter that blocks a unique test token such as
confidential-codename. - AWS credentials allowed to call
bedrock:ApplyGuardrailfor that guardrail. curl. The AISIX Cloud path also usesjq.
Create a Bedrock Guardrail
The example below checks both requests and responses with a Bedrock guardrail. Choose one configuration path, then use the shared verification procedure.
Export the gateway values used by both paths:
# AISIX_PROXY has no trailing slash or endpoint path.
# The local quickstarts use http://127.0.0.1:3000.
export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"
export AISIX_API_KEY="YOUR_CALLER_API_KEY"
export AISIX_MODEL="gpt-4o-mini"
export AWS_ACCESS_KEY_ID="YOUR_AWS_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET_ACCESS_KEY"
AISIX Cloud
Export the control-plane connection details:
# AISIX_CP includes /api and has no trailing slash.
# The local On-Premises quickstart uses http://localhost:8080/api.
export AISIX_CP="YOUR_AISIX_CLOUD_ADMIN_API_URL"
export AISIX_TOKEN="YOUR_ADMIN_TOKEN"
export ENV_ID="YOUR_ENVIRONMENT_ID"
Create a Bedrock guardrail in AISIX, and capture its ID for the attachment step:
export GUARDRAIL_ID=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/guardrails" \
-H "Authorization: Bearer $AISIX_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "bedrock-review",
"enabled": false,
"hook_point": "both",
"fail_open": false,
"enforcement_mode": "block",
"kind": "bedrock",
"config": {
"guardrail_id": "YOUR_BEDROCK_GUARDRAIL_ID",
"guardrail_version": "DRAFT",
"region": "us-east-1",
"aws_credentials": {
"kind": "static",
"access_key_id": "'"${AWS_ACCESS_KEY_ID}"'",
"secret_access_key": "'"${AWS_SECRET_ACCESS_KEY}"'"
},
"output_fail_open": false,
"latency_mode": {
"kind": "timed",
"timeout_ms": 2000
}
}
}' | jq -r '.guardrail.id')
❶ both checks caller requests and model responses. See Guardrail Hook Point.
❷ fail_open: false blocks the request if AWS Bedrock Guardrails fails or times out. This is the default.
❸ enforcement_mode: block rejects matching content. This is the default. See Enforcement Modes.