Skip to content

Conversation

@austinmw
Copy link

Summary

  • Fixes guardrail_latest_message wrapping being lost after tool execution, when the last message is a toolResult with no text/image content
  • Pre-computes the index of the last user message containing text or image content before the formatting loop, so guardContent wrapping targets the correct message regardless of what follows it

Fixes #1651

Test plan

  • New test test_format_request_with_guardrail_latest_message_after_tool_use — verifies guardContent wraps the user text message when a toolResult follows
  • New test test_format_request_with_guardrail_latest_message_wraps_final_user_text — verifies existing behavior (last message is text) still works
  • Existing test test_format_request_with_guardrail_latest_message passes (no regression)
  • Full bedrock test suite passes (104 passed, 3 skipped)

🤖 Generated with Claude Code

When guardrail_latest_message=True, the guardContent wrapping was lost
after tool execution because the last message was a toolResult (with no
text/image content). Pre-compute the index of the last user message
containing text or image content so wrapping is applied correctly even
when subsequent toolResult messages follow.

Fixes strands-agents#1651

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] guardrail_latest_message wrapping lost after tool execution (toolResult becomes last message)

1 participant