AWS Bedrock Guardrails

AWS Bedrock Guardrails provide content filtering, PII detection, topic restrictions, and word filters. You must create the guardrail policies in the AWS console and then apply them to LLM route that you want to protect. When a request or response violates a guardrail policy, the agentgateway proxy 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

  1. Set up an agentgateway proxy.
  2. Set up access to the OpenAI LLM provider.

Set up AWS Bedrock guardrails

  1. Create a guardrail in the AWS console or via the AWS CLI.

  2. Retrieve your guardrail identifier and version. For more information, see the AWS documentation.

    aws bedrock list-guardrails --region <aws-region>

    Example output:

    {
     "guardrails": [
         {
             "id": "a1aaaa11aa1a",
             "arn": "arn:aws:bedrock:us-west-2:11111111111:guardrail/a1aaaa11aa1a",
             "status": "READY",
             "name": "my-guardrail",
             "description": "Testing agentgateway bedrock guardrail integration ",
             "version": "DRAFT",
             "createdAt": "2026-02-09T17:59:29+00:00",
             "updatedAt": "2026-02-09T18:01:29.567223+00:00"
         }
     ]
    }
    
  3. Create a Kubernetes secret with your AWS credentials. Make sure that you have permission to invoke the Bedrock Guardrails API.

    kubectl create secret generic aws-secret \
      -n agentgateway-system \
      --from-literal=accessKey="$AWS_ACCESS_KEY_ID" \
      --from-literal=secretKey="$AWS_SECRET_ACCESS_KEY" \
      --from-literal=sessionToken="$AWS_SESSION_TOKEN" \
      --type=Opaque \
      --dry-run=client -o yaml | kubectl apply -f -
  4. Configure the prompt guard. Add the ID, version, and region of your guardrail.

    kubectl apply -f - <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayPolicy
    metadata:
      name: openai-prompt-guard
      namespace: agentgateway-system
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: HTTPRoute
        name: openai
      backend:
        ai:
          promptGuard:
            request:
            - bedrockGuardrails:
                identifier: <guardrail-ID>
                version: "<version>" 
                region: <region>>
                policies:
                  auth:
                    aws: 
                      secretRef:
                        name: aws-secret
            response:
            - bedrockGuardrails:
                identifier: <guardrail-ID>
                version: "<version>" 
                region: <region>>
                policies:
                  auth:
                    aws: 
                      secretRef:
                        name: aws-secret
    EOF
    ℹ️
    The aws: {} configuration uses the default AWS credential chain (IAM role, environment variables, or instance profile). For authentication details, see the AWS authentication documentation.
  5. Test the guardrail. The following commands assume that you set up your guardrail to block requests that contain email information.

    Cloud Provider LoadBalancer:

    curl "$INGRESS_GW_ADDRESS/v1/chat/completions" -H content-type:application/json  -d '{
     "model": "",
     "messages": [
       {
         "role": "user",
         "content": "My email is test@solo.io"
       }
     ]
    }' | jq

    Localhost:

    curl "localhost:8080/v1/chat/completions" -H content-type:application/json  -d '{
     "model": "",
     "messages": [
       {
         "role": "user",
         "content": "My email is test@solo.io"
       }
     ]
    }' | jq

    Cloud Provider LoadBalancer:

    curl "$INGRESS_GW_ADDRESS/openai" -H content-type:application/json  -d '{
     "model": "",
     "messages": [
       {
         "role": "user",
         "content": "My email is test@solo.io"
       }
     ]
    }' | jq

    Localhost:

    curl "localhost:8080/openai" -H content-type:application/json  -d '{
     "model": "",
     "messages": [
       {
         "role": "user",
         "content": "My email is test@solo.io"
       }
     ]
    }' | jq

    Example output:

    The request was rejected due to inappropriate content
    

Cleanup

You can remove the resources that you created in this guide.
kubectl delete AgentgatewayPolicy openai-prompt-guard -n agentgateway-system 
kubectl delete secret aws-secret -n agentgateway-system 
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.