diff --git a/docs/user-guide/concepts/model-providers/amazon-bedrock.md b/docs/user-guide/concepts/model-providers/amazon-bedrock.md index 9cd05c03..4b317300 100644 --- a/docs/user-guide/concepts/model-providers/amazon-bedrock.md +++ b/docs/user-guide/concepts/model-providers/amazon-bedrock.md @@ -179,6 +179,7 @@ The [`BedrockModel`](../../../api-reference/models.md#strands.models.bedrock) su | [`guardrail_redact_input_message`](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_GuardrailStreamConfiguration.html) | If a Bedrock guardrail triggers, replace the input with this message | "[User input redacted.]" | | [`guardrail_redact_output`](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_GuardrailStreamConfiguration.html) | Flag to redact output if guardrail is triggered | False | | [`guardrail_redact_output_message`](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_GuardrailStreamConfiguration.html) | If a Bedrock guardrail triggers, replace output with this message | "[Assistant output redacted.]" | +| [`guardrail_last_turn_only`](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_GuardrailStreamConfiguration.html) | Flag to send only the last turn to guardrails instead of full conversation | False | | [`additional_request_fields`](https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html) | Additional inference parameters that the model supports | - | | [`additional_response_field_paths`](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html#bedrock-runtime_ConverseStream-request-additionalModelResponseFieldPaths) | Additional model parameters field paths to return in the response | - | | `additional_args` | Additional arguments to include in the request. This is included for forwards compatibility of new parameters. | - | @@ -290,7 +291,8 @@ bedrock_model = BedrockModel( 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_last_turn_only=False # Default: False - Set to True to evaluate only the last turn ) guardrail_agent = Agent(model=bedrock_model) @@ -303,6 +305,7 @@ When a guardrail is triggered: - 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 +- Last turn only (disabled by default): When enabled, only the last conversation turn (most recent user message and the assistant's response to it, if present) is sent to guardrails instead of the full conversation history. This allows conversations to recover after guardrail interventions. ### Caching diff --git a/docs/user-guide/safety-security/guardrails.md b/docs/user-guide/safety-security/guardrails.md index f0bf97ac..c3f17061 100644 --- a/docs/user-guide/safety-security/guardrails.md +++ b/docs/user-guide/safety-security/guardrails.md @@ -33,6 +33,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_last_turn_only=False, # Set to True to evaluate only the last turn ) # Create agent with the guardrail-protected model @@ -51,6 +52,8 @@ if response.stop_reason == "guardrail_intervened": print(f"Conversation: {json.dumps(agent.messages, indent=4)}") ``` +**Performance Optimization**: Set `guardrail_last_turn_only=True` to evaluate only the most recent conversation turn (user message and assistant's response to it, if present) instead of the full history. This allows conversations to recover after guardrail interventions. 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: @@ -149,4 +152,4 @@ Ollama doesn't currently provide native guardrail capabilities like Bedrock. Ins * [Amazon Bedrock Guardrails Documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails.html) * [Allen Institute for AI: Guardrails Project](https://www.guardrailsai.com/docs) -* [AWS Boto3 Python Documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/apply_guardrail.html#) \ No newline at end of file +* [AWS Boto3 Python Documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/apply_guardrail.html#)