diff --git a/docs/user-guide/concepts/model-providers/amazon-bedrock.md b/docs/user-guide/concepts/model-providers/amazon-bedrock.md index 8d7ac628..b7d8981e 100644 --- a/docs/user-guide/concepts/model-providers/amazon-bedrock.md +++ b/docs/user-guide/concepts/model-providers/amazon-bedrock.md @@ -369,10 +369,6 @@ For a complete list of input types, please refer to the [API Reference](../../.. Amazon Bedrock supports guardrails to help ensure model outputs meet your requirements. Strands allows you to configure guardrails with your [`BedrockModel`](../../../api-reference/models.md#strands.models.bedrock): - ```python - from strands import Agent - from strands.models import BedrockModel - # Using guardrails with BedrockModel bedrock_model = BedrockModel( model_id="anthropic.claude-sonnet-4-20250514-v1:0", @@ -383,9 +379,10 @@ For a complete list of input types, please refer to the [API Reference](../../.. guardrail_redact_input=True, # Default: True guardrail_redact_input_message="Blocked Input!", # Default: [User input redacted.] guardrail_redact_output=False, # Default: False - guardrail_redact_output_message="Blocked Output!" # Default: [Assistant output redacted.] + guardrail_redact_output_message="Blocked Output!", # Default: [Assistant output redacted.] + guardrail_latest_message=False # Default: False - Set to True to evaluate only the latest user message ) - + guardrail_agent = Agent(model=bedrock_model) response = guardrail_agent("Can you tell me about the Strands SDK?") @@ -398,10 +395,10 @@ For a complete list of input types, please refer to the [API Reference](../../.. - Input redaction (enabled by default): If a guardrail policy is triggered, the input is redacted - Output redaction (disabled by default): If a guardrail policy is triggered, the output is redacted - Custom redaction messages can be specified for both input and output redactions + - Latest message only (disabled by default): When enabled, only the latest user message (text and image content) is wrapped for guardrail evaluation instead of the full conversation history. This can help conversations recover after guardrail interventions and reduces evaluation overhead. {{ ts_not_supported_code("Guardrails are not yet supported in the TypeScript SDK") }} - ### Caching Strands supports caching system prompts, tools, and messages to improve performance and reduce costs. Caching allows you to reuse parts of previous requests, which can significantly reduce token usage and latency. @@ -834,4 +831,3 @@ This is very likely due to calling Bedrock with an inference model id, such as: - [Amazon Bedrock Documentation](https://docs.aws.amazon.com/bedrock/) - [Bedrock Model IDs Reference](https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html) - [Bedrock Pricing](https://aws.amazon.com/bedrock/pricing/) - diff --git a/docs/user-guide/safety-security/guardrails.md b/docs/user-guide/safety-security/guardrails.md index 49a12214..880e366a 100644 --- a/docs/user-guide/safety-security/guardrails.md +++ b/docs/user-guide/safety-security/guardrails.md @@ -35,6 +35,7 @@ bedrock_model = BedrockModel( guardrail_id="your-guardrail-id", # Your Bedrock guardrail ID guardrail_version="1", # Guardrail version guardrail_trace="enabled", # Enable trace info for debugging + guardrail_latest_message=False, # Set to True to evaluate only the latest user message ) # Create agent with the guardrail-protected model @@ -53,6 +54,8 @@ if response.stop_reason == "guardrail_intervened": print(f"Conversation: {json.dumps(agent.messages, indent=4)}") ``` +**Performance Optimization**: Set `guardrail_latest_message=True` to evaluate only the latest user message instead of the full conversation history. This can help conversations recover after guardrail interventions and reduces evaluation overhead. See the [Amazon Bedrock documentation](../concepts/model-providers/amazon-bedrock.md#guardrails) for more details. + Alternatively, if you want to implement your own soft-launching guardrails, you can utilize Hooks along with Bedrock's ApplyGuardrail API in shadow mode. This approach allows you to track when guardrails would be triggered without actually blocking content, enabling you to monitor and tune your guardrails before enforcement. Steps: