Getting started Community Training Tutorials Documentation APIs, AI & Tools
Bedrock Runtime Endpoint
Policy Name |
Amazon Bedrock Guardrails Policy |
Summary |
Evaluates LLM prompts and responses against Amazon Bedrock guardrails for content safety, PII detection, and contextual grounding |
Category |
LLM |
First Omni Gateway version available |
v1.13.0 |
Release Notes |
|
Returned Status Codes |
403 - Forbidden: Content violates guardrail policies |
503 - Service Unavailable: Bedrock API call failed (only when fail-open is disabled) |
The Amazon Bedrock Guardrails policy provides comprehensive content moderation for LLM-based APIs by evaluating prompts and responses against Amazon Bedrock guardrails. The policy integrates with AWS Bedrock’s Guardrails feature to enforce content safety policies including:
The policy supports all Amazon Bedrock Guardrail features:
Content filters: Detects and blocks harmful content across four categories (hate, insults, sexual, violence) with configurable filter strengths (NONE, LOW, MEDIUM, HIGH).
Denied topics: Blocks content related to specific topics you define, for example, financial advice, medical diagnosis
Word filters: Blocks profanity and custom words or phrases you specify
PII detection: Detects and optionally redacts personally identifiable information, for example, names, addresses, SSNs, credit cards
Contextual grounding: Evaluates whether LLM responses are grounded in provided reference text and relevant to the user query (hallucination detection)
The guardrail’s configuration is managed entirely in AWS. The policy enforces whatever rules you’ve configured in the specified guardrail.
The policy operates in two independent phases:
Request phase — Moderates user prompts before they reach the upstream LLM, preventing harmful or inappropriate prompts from being processed.
Response phase — Moderates LLM responses before they reach the client, ensuring outputs comply with safety policies. Streaming responses (text/event-stream) aren’t moderated.
When content violates guardrail policies, the request is rejected with a 403 error code and never reaches the LLM (request phase) or the client receives a 403 instead of the LLM response (response phase).
Before configuring this policy, you need:
AWS Account with access to Amazon Bedrock
Bedrock Guardrail created and configured in AWS Console
IAM Credentials with permissions to call bedrock:ApplyGuardrail
Guardrail ID from the AWS Console
When you apply the policy from the UI, the following parameters are displayed:
| Element | Required | Description |
|---|---|---|
Bedrock Runtime Endpoint |
Yes |
Amazon Bedrock Runtime endpoint URL. Must match your AWS region, for example: |
AWS Credentials |
Yes |
AWS credentials and region used for signing requests to the Bedrock API. See AWS Credentials. |
Guardrail Identifier |
Yes |
The unique ID of the Bedrock guardrail to apply (for example, |
Guardrail Version |
No |
Version of the guardrail to apply.
|
Moderate Request |
No |
When enabled, evaluates the user prompt against the guardrail before forwarding to the upstream LLM. Rejected prompts never reach the LLM. |
Moderate Response |
No |
When enabled, evaluates the LLM response against the guardrail before returning to the client. Rejected responses return Note: Streaming responses ( |
The policy uses AWS Signature V4 to authenticate with the Bedrock API. Both long-lived IAM credentials and temporary STS credentials are supported.
| Element | Required | Description |
|---|---|---|
Access Key ID |
Yes |
AWS access key ID. Supports both:
|
Secret Access Key |
Yes |
AWS secret access key corresponding to the Access Key ID. |
Session Token |
Conditional |
Required when using temporary credentials (Access Key ID starting with |
Region |
Yes |
AWS region of the Bedrock Runtime endpoint (for example, |
| Element | Required | Description |
|---|---|---|
Grounding Source Selector |
No |
DataWeave expression that extracts the reference text for contextual grounding from the request body. Required only when contextual grounding is enabled on the AWS guardrail. Must be configured together with Grounding Query Selector. Example: See Contextual Grounding for more information. |
Grounding Query Selector |
No |
DataWeave expression that extracts the user query for contextual grounding from the request body. Required only when contextual grounding is enabled on the AWS guardrail. Must be configured together with Grounding Source Selector. Example: See Contextual Grounding for more information. |
API Timeout (ms) |
No |
Timeout in milliseconds for calls to the Bedrock
|
Fail Open |
No |
Determines behavior when the Bedrock API call fails or times out:
|
The Amazon Bedrock Guardrails policy integrates with AWS Bedrock’s content moderation service to evaluate LLM prompts and responses against configurable safety policies.
The policy supports independent evaluation for requests and responses. The two phases mirror AWS Bedrock’s INPUT and OUTPUT scopes, enabling you to apply different filter strengths to prompts versus responses when configuring the guardrail in AWS:
Request Phase (when moderateRequest is enabled):
The policy extracts the user prompt from the request.
The policy sends the prompt to Bedrock’s ApplyGuardrail API.
If the prompt violates any guardrail policies, the policy blocks the request and returns a 403 error code to the client.
If the prompt passes, the policy forwards the original request to the upstream LLM.
Response Phase (when moderateResponse is enabled):
The policy intercepts the LLM response.
The policy sends the response to Bedrock’s ApplyGuardrail API.
If the response violates any guardrail policies, the policy returns a 403 error code to the client.
If the response passes, the policy forwards the original response to the client.
Streaming responses (text/event-stream) are skipped and pass through without moderation.
|
Contextual grounding helps detect hallucinations by scoring LLM responses on two dimensions:
Grounding: Is the response derived from the provided reference text?
Relevance: Does the response actually answer the user’s question?
To enable contextual grounding:
Enable the contextual grounding feature on your AWS Bedrock guardrail.
Configure both Grounding Source Selector and Grounding Query Selector in the policy.
The selectors are DataWeave expressions that extract:
Grounding source: The reference text the answer should be based on (often the first message in a RAG conversation)
Query: The user’s actual question (often the last message)
Both must be configured together. Configuring only one causes the Bedrock API to return an 400 error code.
advancedConfiguration:
groundingSourceSelector: "#[payload.messages[0].content]"
groundingQuerySelector: "#[payload.messages[-1].content]"
Every moderated response includes observability headers:
| Header | Values | Description |
|---|---|---|
|
|
Final moderation decision. |
|
|
Which phase performed the moderation. Useful for understanding whether the prompt or response was blocked. |
|
|
Why the content was rejected. Multiple reasons are comma-separated if the content violated multiple policies. |
- policyRef:
name: bedrock-guardrails-policy-v1-0-impl
config:
bedrockEndpoint: https://bedrock-runtime.us-east-1.amazonaws.com
awsCredentials:
accessKeyId: "${AWS_ACCESS_KEY_ID}"
secretAccessKey: "${AWS_SECRET_ACCESS_KEY}"
region: us-east-1
guardrailIdentifier: "${GUARDRAIL_IDENTIFIER}"
guardrailVersion: "1"
moderateRequest: true
moderateResponse: true
- policyRef:
name: bedrock-guardrails-policy-v1-0-impl
config:
bedrockEndpoint: https://bedrock-runtime.us-east-1.amazonaws.com
awsCredentials:
accessKeyId: "${AWS_ACCESS_KEY_ID}"
secretAccessKey: "${AWS_SECRET_ACCESS_KEY}"
region: us-east-1
guardrailIdentifier: paccgfhgnj1dc
guardrailVersion: "1"
moderateRequest: true
moderateResponse: false
- policyRef:
name: bedrock-guardrails-policy-v1-0-impl
config:
bedrockEndpoint: https://bedrock-runtime.us-east-1.amazonaws.com
awsCredentials:
accessKeyId: "${AWS_ACCESS_KEY_ID}"
secretAccessKey: "${AWS_SECRET_ACCESS_KEY}"
sessionToken: "${AWS_SESSION_TOKEN}" # for temporary credentials
region: us-east-1
guardrailIdentifier: paccgfhgnj1dc
guardrailVersion: DRAFT
moderateRequest: false
moderateResponse: true
advancedConfiguration:
groundingSourceSelector: "#[payload.messages[0].content]"
groundingQuerySelector: "#[payload.messages[-1].content]"
apiTimeoutMs: 8000
failOpen: false
- policyRef:
name: bedrock-guardrails-policy-v1-0-impl
config:
bedrockEndpoint: https://bedrock-runtime.us-east-1.amazonaws.com
awsCredentials:
accessKeyId: "${AWS_ACCESS_KEY_ID}"
secretAccessKey: "${AWS_SECRET_ACCESS_KEY}"
region: us-east-1
guardrailIdentifier: paccgfhgnj1dc
guardrailVersion: "1"
moderateRequest: true
moderateResponse: true
advancedConfiguration:
failOpen: true # Allow traffic if Bedrock is unavailable
apiTimeoutMs: 3000
Amazon Bedrock Guardrails - AWS documentation
ApplyGuardrail API Reference - AWS API documentation
Creating and Managing Model Proxies - Overview of Model Proxy and routing
Applying Model Proxy Policies - Other LLM policies