Skip to content

Conversation

@aiancheruk
Copy link
Contributor

@aiancheruk aiancheruk commented Nov 21, 2025

Description

This PR adds a new guardrail_latest_message parameter to the BedrockModel that allows users to send only the last user message to AWS Bedrock Guardrails for evaluation, instead of the entire conversation history.

Key changes:

  • Added guardrail_latest_message: bool = False parameter to BedrockConfig
  • Modified _format_bedrock_messages() adding latest user message to guardContent when guardrail_latest_message=True
  • Added comprehensive unit tests for the helper method and request formatting
  • Added integration tests to verify the feature works end-to-end with AWS Bedrock Guardrails

Benefits:

  • Reduces token usage and costs when using guardrails
  • Enables conversation recovery after guardrail interventions (blocked content in history won't block future messages)

Follow up:
Use coding agent to add image in GuardContent

Related Issues

#999

Documentation PR

strands-agents/docs#340

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aiancheruk
Copy link
Contributor Author

Related: #999

@JackYPCOnline JackYPCOnline self-requested a review December 17, 2025 17:12
@JackYPCOnline
Copy link
Contributor

JackYPCOnline commented Dec 17, 2025

@aiancheruk Thank you for raising this PR! Could you refine the helper function a bit? Once that's done, I'll be happy to merge it.
Update: I'll update the PR based on your code to expedite the merge.

JackYPCOnline
JackYPCOnline previously approved these changes Dec 19, 2025
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/models/bedrock.py 87.50% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@pgrayy pgrayy self-requested a review December 22, 2025 20:10
pgrayy
pgrayy previously requested changes Dec 22, 2025
@github-actions github-actions bot added size/m and removed size/m labels Dec 29, 2025
@github-actions github-actions bot added size/s and removed size/m labels Jan 2, 2026
@JackYPCOnline JackYPCOnline changed the title feat(bedrock): add guardrail_last_turn_only option feat(bedrock): add guardrail_latest_message option Jan 2, 2026
@JackYPCOnline JackYPCOnline requested a review from Unshure January 2, 2026 21:32
@JackYPCOnline JackYPCOnline enabled auto-merge (squash) January 7, 2026 15:52
@JackYPCOnline JackYPCOnline removed the request for review from pgrayy January 7, 2026 15:52
@JackYPCOnline JackYPCOnline dismissed pgrayy’s stale review January 7, 2026 15:53

he was out, this PRs has been reviewed by Nick

@JackYPCOnline JackYPCOnline merged commit 08bf563 into strands-agents:main Jan 7, 2026
12 of 15 checks passed
@aiancheruk
Copy link
Contributor Author

Thanks for your help @JackYPCOnline @Unshure @pgrayy!

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.

[FEATURE] Add GuardrailConverseContent Support for Bedrock Guardrails to supportive selective Guarding

5 participants