Getting started Community Training Tutorials Documentation APIs, AI & Tools
Bedrock Runtime Endpoint
Policy Name |
A2A v1 Bedrock Guardrails Policy |
Summary |
Evaluates A2A v1.0 agent requests and responses against Amazon Bedrock guardrails for content safety, PII detection, and contextual grounding |
Category |
A2A |
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 A2A v1 Bedrock Guardrails policy provides comprehensive content moderation for A2A v1.0 (Agent-to-Agent) traffic by evaluating the entire request and response payloads against Amazon Bedrock guardrails. This policy works with both JSON-RPC and HTTP+JSON transports.
The policy integrates with AWS Bedrock’s Guardrails feature to enforce content safety policies including:
Content filters: Detects and blocks harmful content across six categories (hate, insults, sexual, violence, misconduct, prompt attacks) 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 agent responses are grounded in provided reference text and relevant to the user query (hallucination detection)
The policy enforces the rules you configure for the specific guardrail in AWS.
The policy operates in two independent phases:
Request phase — Moderates user messages before they reach the upstream agent, preventing harmful or inappropriate prompts from being processed.
Response phase — Moderates agent responses before they reach the client, ensuring outputs comply with safety policies. Streaming responses (text/event-stream) aren’t moderated in v1.
When content violates guardrail policies, the request is rejected with a 403 error code and never reaches the upstream agent (request phase) or the client receives a 403 instead of the agent 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. Accepts either:
When the full URL is provided, the policy derives the region, guardrail identifier, and guardrail version, unless if you explicitly configure those values. |
AWS Credentials |
Yes |
AWS credentials and region for signing requests to the Bedrock API. See AWS Credentials. |
Guardrail Identifier |
Conditional |
The unique ID of the Bedrock guardrail to apply (for example, Required unless provided in the Bedrock Runtime Endpoint URL. |
Guardrail Version |
No |
Version of the guardrail to apply.
Required unless provided in the Bedrock Runtime Endpoint URL. |
Moderate Request |
No |
When enabled (default: |
Moderate Response |
No |
When enabled (default: |
The policy uses AWS Signature V4 to authenticate with the Bedrock API and supports both long-lived IAM credentials and temporary STS credentials.
| Element | Required | Description |
|---|---|---|
Access Key ID |
Yes |
AWS access key ID, either:
|
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 |
Conditional |
AWS region of the Bedrock Runtime endpoint (for example, Set explicitly for custom domains or VPC endpoints. Optional when the region is provided in the Bedrock Runtime Endpoint host. |
| Element | Required | Description |
|---|---|---|
Grounding Source Selector |
No |
DataWeave expression that extracts the reference text for contextual grounding from the request body. Required only when the AWS guardrail has contextual grounding enabled. Must be configured together with Grounding Query Selector. Example for JSON-RPC: Example for HTTP+JSON: 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 the AWS guardrail has contextual grounding enabled. Must be configured together with Grounding Source Selector. Example for JSON-RPC: Example for HTTP+JSON: See Contextual Grounding for more information. |
Max Payload Bytes |
No |
Maximum request or response body size (in bytes) sent to Bedrock.
The |
Sampling Rate Percent |
No |
Percentage of sessions to sample for moderation (0-100).
Sampling is deterministic per session. The same session is always or never sampled. |
Session Key Selector |
No |
DataWeave expression that extracts the session identifier used for sampling. By default, the key selector resolves to A2A v1.0 Only used when Sampling Rate Percent is less than 100. |
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:
When enabled, failures are logged and the |
The A2A v1 Bedrock Guardrails policy integrates with AWS Bedrock’s content moderation service to evaluate complete A2A request and response payloads against configurable safety policies.
The policy supports independent evaluation for requests and responses. The two phases mirror AWS Bedrock’s INPUT and OUTPUT scopes:
Request Phase (when moderateRequest is enabled):
The policy extracts the entire request body.
The policy sends the complete JSON payload to Bedrock’s ApplyGuardrail API.
If the content violates any guardrail policies, the policy blocks the request and returns a 403 error code to the client.
If the content passes, the policy forwards the original request to the upstream agent.
Response Phase (when moderateResponse is enabled):
The policy intercepts the agent response.
The policy sends the complete 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. Only non-streaming (application/json) responses are moderated.
|
The policy supports these A2A v1.0 transports:
JSON-RPC
HTTP+JSON
The policy doesn’t support gRPC traffic (application/grpc or application/grpc+proto) and it passes through without moderation. When gRPC traffic is detected, the policy emits these observability headers:
x-flex-bedrock-guardrails-action: skip
x-flex-bedrock-guardrails-reason: unsupported_transport_v1
The policy only evaluates SendMessage and SendStreamingMessage methods. Other methods (for example, GetTask, ListTasks, SubscribeToTask, agent card requests) pass through without moderation.
Contextual grounding helps detect hallucinations by scoring agent 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 for 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 from message metadata or context)
Query: The user’s actual question (often from message parts)
Both parameters must be configured together. Configuring only one causes the Bedrock API to return a 400 error code.
DataWeave selectors bind to the raw request body differently for different transports:
JSON-RPC
For JSON-RPC, A2A parameters are under payload.params.*. For example:
advancedConfiguration:
groundingSourceSelector: "#[payload.params.message.metadata.context]"
groundingQuerySelector: "#[payload.params.message.parts[0].text]"
HTTP+JSON
For HTTP+JSON, A2A parameters are at the top level (payload.*). For example:
advancedConfiguration:
groundingSourceSelector: "#[payload.message.metadata.context]"
groundingQuerySelector: "#[payload.message.parts[0].text]"
Every moderated response includes observability headers:
| Header | Values | Description |
|---|---|---|
|
|
Final moderation decision. |
|
|
Which phase performed the moderation. Useful for understanding whether the request or response was blocked. |
|
|
Why the content was rejected or skipped. Multiple reasons are comma-separated if the content violated multiple policies. |
- policyRef:
name: a2a-v1-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"
- policyRef:
name: a2a-v1-bedrock-guardrails-policy-v1-0-impl
config:
bedrockEndpoint: https://bedrock-runtime.us-east-2.amazonaws.com/guardrail/2dxe6otc16kv/version/DRAFT/apply
awsCredentials:
accessKeyId: "${AWS_ACCESS_KEY_ID}"
secretAccessKey: "${AWS_SECRET_ACCESS_KEY}"
- policyRef:
name: a2a-v1-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: a2a-v1-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.params.message.metadata.context]"
groundingQuerySelector: "#[payload.params.message.parts[0].text]"
apiTimeoutMs: 8000
failOpen: false
- policyRef:
name: a2a-v1-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
samplingRatePercent: 50 # Moderate 50% of sessions
| Condition | Status Code | Description |
|---|---|---|
Content violates guardrail (request phase) |
403 Forbidden |
Request blocked before reaching the agent. Response body contains A2A error envelope with reason details. |
Content violates guardrail (response phase) |
403 Forbidden |
Response blocked and replaced with A2A error envelope. Original response is not returned. |
Bedrock API failure (fail-open disabled) |
503 Service Unavailable |
Bedrock service error or timeout with fail-open disabled. Traffic is blocked. |
Bedrock API failure (fail-open enabled) |
Varies |
Traffic proceeds unmoderated. Observability headers indicate |
Payload exceeds size limit (fail-open disabled) |
403 Forbidden |
Payload larger than |
Payload exceeds size limit (fail-open enabled) |
Varies |
Oversized payload passes through unmoderated. Observability headers indicate |
Sampled-out session |
Varies |
Session not selected for moderation. Traffic passes through with |
gRPC traffic |
Varies |
gRPC traffic passes through unmoderated with |
Streaming responses: Streaming responses (text/event-stream) aren’t moderated and pass through unchanged.
gRPC traffic: gRPC traffic isn’t moderated and passes through with observability headers.
Payload size: Payloads exceeding maxPayloadBytes (default 25,000 bytes) can’t be evaluated synchronously by Bedrock.
JSON envelope: Bedrock evaluates the complete JSON payload, including A2A protocol fields, not just the natural language content. This may affect classifier confidence scores compared to evaluating bare text.
Use versioned guardrails in production: Pin to a numeric guardrail version instead of DRAFT for consistent, repeatable behavior.
Monitor observability headers: Track x-flex-bedrock-guardrails-reason headers to understand why content is blocked or skipped.
Start with sampling in production: Use samplingRatePercent: 50 or lower initially to control costs while establishing baseline behavior.
Enable fail-open for availability: Consider failOpen: true in production to prevent Bedrock outages from blocking all agent traffic.
Test grounding with representative payloads: If using contextual grounding, validate with full A2A JSON payloads, not just extracted text fields.
Use temporary credentials: Rotate temporary STS credentials instead of long-lived IAM keys for improved security.
Amazon Bedrock Guardrails - AWS documentation
ApplyGuardrail API Reference - AWS API documentation
Amazon Bedrock Guardrails Policy - LLM Gateway version
A2A v1 PII Detector Policy - Alternative PII detection for A2A v1.0
A2A Proxy - Overview of A2A Proxy and agent routing