[BUG] Bedrock Contextual Grounding Guardrail isn't integrated
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
Strands Version
1.10.0
Python Version
3.12.8
Operating System
macOS 15.7
Installation Method
pip
Steps to Reproduce
- Create a Bedrock Guardrail with the Contextual Grounding filters enabled and set to max threshold (0.99)
- Create a simple agent using a RAG tool like the AWS Knowledge MCP for example
- Ask it a question that requires searching through the knowledge base
...Something like the below:
from mcp.client.streamable_http import streamablehttp_client
from strands import Agent
from strands.models.bedrock import BedrockModel
from strands.tools.mcp import MCPClient
model = BedrockModel(
model_id="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
guardrail_id="YOUR-BEDROCK-GUARDRAIL-ID",
guardrail_version="DRAFT",
)
aws_docs_mcp = MCPClient(
lambda: streamablehttp_client(
url="https://knowledge-mcp.global.api.aws"
)
)
with aws_docs_mcp:
agent = Agent(
tools=[aws_docs_mcp.list_tools_sync()],
model=model,
name="guardrails-test",
)
agent(
"Check the AWS docs to find the model ID for Llama 3.1 8B instruct on Amazon Bedrock"
)
Expected Behavior
It should be possible to elicit a guardrail intervention for contextual grounding check failure.
Actual Behavior
Even with the relevance and grounding thresholds set to maximum in the guardrail on the complex AWS knowledge base, trying a range of questions... I'm not able to get the native Strands+Converse Guardrail to fail contextual grounding.
I'm pretty sure the BedrockModel guardrail integration is improperly set up for this feature, because I can make the check fail when instead using a custom hook to connect the guardrail.
Additional Context
Per the example here in the Converse+Contextual Grounding Guardrail docs, checking Contextual Grounding via the Converse API requires that the input messages be tagged with qualifiers to indicate what's the grounding_source, versus the original query being answered and the final response to be checked.
As far as I can tell from skimming through the implementation, Strands' BedrockModel seems to be OK to pass through guardContent blocks if they're already present in the input, but I can't see anywhere it (or anything else in Strands) would actively set them up.
...So as far as I can tell, Contextual Grounding checks are never being evaluated because nothing in Strands is indicating which parts of the Converse input correspond to these 3 roles of query / grounding_source / output.
As noted here in the docs the default behaviour of Converse when guardContent blocks are not provided is to check none of the System messages and all other messages. Not sure yet whether this extends to tool results being treated as user messages or not.
Possible Solution
I'd suggest that (while different tools are more or less search/RAG-like), it seems like treating toolResults as grounding_sources could be a sensible default? We could have the BedrockModel automatically add relevant guardContent wrappers in cases where a guardrail has been configured.
Whether toolResults should also be tagged for analysis with guard_content is probably more debatable... I could imagine different use-cases taking very different stances on how "trusted" tool responses are and what to do if they e.g. contain PII, toxic or excluded material.
We could potentially try to offer some level of configurability (for e.g. a mapping of how to treat different tools by tool name?), or equally just say some things are out-of-scope and should be addressed by hooks-based guardrail orchestration or custom model classes.
Even if the decision is not to change anything in the current implementation, I think I'd like to see a call-out in the documentation that Bedrock Guardrails' contextual grounding checks in particular probably don't work as expected out-of-the-box through the BedrockModel?
Related Issues
No response
I've noticed this as well, but haven't taken the time to investigate.
The integration gap is the guardContent tagging on Converse messages. Bedrock Contextual Grounding only fires when input messages have content blocks tagged with role=GROUND or role=QUERY, and Strands' BedrockModel currently sends raw text blocks without those tags.
Practical fix: when a guardrail is configured for grounding, intercept the Converse request and rewrap user-provided context as guardContent blocks with the right role tag. Tool outputs that carry retrieval results need the same treatment.
Without that, Contextual Grounding silently no-ops which makes it look like the grounding rules are wrong when really they're never being evaluated.
Happy to take the docs clarification here. The Python provider preserves explicit grounding/query qualifiers, but doesn't add them to tool results. I'll add a short example for that existing path and keep automatic tagging out of scope.
AI-assisted with Codex.