From cc7b65485a72b9c27f2000fc109c1b77aece24e8 Mon Sep 17 00:00:00 2001 From: Aleksei Iancheruk Date: Fri, 21 Nov 2025 15:09:49 +0100 Subject: [PATCH 1/3] docs(bedrock): add guardrail_last_turn_only docs --- docs/user-guide/concepts/model-providers/amazon-bedrock.md | 5 ++++- docs/user-guide/safety-security/guardrails.md | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/user-guide/concepts/model-providers/amazon-bedrock.md b/docs/user-guide/concepts/model-providers/amazon-bedrock.md index 9cd05c03..6d2ee4a8 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 (latest user message and previous assistant response) is sent to guardrails instead of the full conversation history. This can improve performance and reduce costs while allowing 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..361188e0 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 instead of the full history. This can improve performance, reduce costs, and allow conversations to recover more easily 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#) From 9bbb0d93adc78bbf8bfd38a8671b56a033d6db2a Mon Sep 17 00:00:00 2001 From: Aleksei Iancheruk Date: Fri, 21 Nov 2025 15:46:41 +0100 Subject: [PATCH 2/3] docs(bedrock): include assistant response in guardrail_last_turn_only context --- docs/user-guide/concepts/model-providers/amazon-bedrock.md | 2 +- docs/user-guide/safety-security/guardrails.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user-guide/concepts/model-providers/amazon-bedrock.md b/docs/user-guide/concepts/model-providers/amazon-bedrock.md index 6d2ee4a8..4b317300 100644 --- a/docs/user-guide/concepts/model-providers/amazon-bedrock.md +++ b/docs/user-guide/concepts/model-providers/amazon-bedrock.md @@ -305,7 +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 (latest user message and previous assistant response) is sent to guardrails instead of the full conversation history. This can improve performance and reduce costs while allowing conversations to recover after guardrail interventions. +- 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 361188e0..c3f17061 100644 --- a/docs/user-guide/safety-security/guardrails.md +++ b/docs/user-guide/safety-security/guardrails.md @@ -52,7 +52,7 @@ 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 instead of the full history. This can improve performance, reduce costs, and allow conversations to recover more easily after guardrail interventions. See the [Amazon Bedrock documentation](../concepts/model-providers/amazon-bedrock.md#guardrails) for more details. +**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. From 69a4fcccd84e493c4a55e8877b8d912a5a7743d6 Mon Sep 17 00:00:00 2001 From: Aleksei Iancheruk Date: Wed, 7 Jan 2026 17:13:43 +0100 Subject: [PATCH 3/3] docs: fix guardrail parameter name to match SDK implementation --- docs/user-guide/concepts/model-providers/amazon-bedrock.md | 5 ++--- docs/user-guide/safety-security/guardrails.md | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/user-guide/concepts/model-providers/amazon-bedrock.md b/docs/user-guide/concepts/model-providers/amazon-bedrock.md index 31023a02..b7d8981e 100644 --- a/docs/user-guide/concepts/model-providers/amazon-bedrock.md +++ b/docs/user-guide/concepts/model-providers/amazon-bedrock.md @@ -380,7 +380,7 @@ For a complete list of input types, please refer to the [API Reference](../../.. 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_last_turn_only=False # Default: False - Set to True to evaluate only the last turn + guardrail_latest_message=False # Default: False - Set to True to evaluate only the latest user message ) guardrail_agent = Agent(model=bedrock_model) @@ -395,7 +395,7 @@ 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 - - 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. + - 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") }} @@ -831,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 25f6d4b1..880e366a 100644 --- a/docs/user-guide/safety-security/guardrails.md +++ b/docs/user-guide/safety-security/guardrails.md @@ -35,7 +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_last_turn_only=False, # Set to True to evaluate only the last turn + guardrail_latest_message=False, # Set to True to evaluate only the latest user message ) # Create agent with the guardrail-protected model @@ -54,7 +54,7 @@ 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. +**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.