Skip to content

Conversation

@minorun365
Copy link
Contributor

@minorun365 minorun365 commented Jan 27, 2026

Summary

Add regression test to verify that cachePoint content blocks are correctly formatted as standalone blocks (not merged into previous content blocks).

This test confirms that the fix from PR #1438 works correctly for the scenario reported in Issue #1219, where cachePoint blocks following text blocks were causing ValidationException errors.

What this PR does:

Background

Issue #1219 reported that cachePoint blocks after text/document content caused ValidationException. This was already fixed by PR #1438 (which added proper cachePoint handling in _format_request_message_content).

This PR adds a regression test to ensure the fix continues to work.

Test plan

  • Added unit test test_format_request_cachepoint_after_text_separate_blocks
  • Test passes locally with hatch test tests/strands/models/test_bedrock.py::test_format_request_cachepoint_after_text_separate_blocks

Closes #1219

🤖 Generated with Claude Code

# See: https://github.com/strands-agents/sdk-python/issues/1219
if "cachePoint" in content_block:
if cleaned_content:
cleaned_content[-1]["cachePoint"] = {"type": content_block["cachePoint"]["type"]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey thanks for raising this but it seems like this would still fail if we have

content = [
    {"document": {"format": "pdf", ...}},
    {"document": {"format": "pdf", ...}},
    {"cachePoint": {"type": "default"}}  # ← standalone, causes ValidationException
]

transformed into

content = [
    {"document": {"format": "pdf", ...}},
    {"document": {"format": "pdf", ...}, "cachePoint": {"type": "default"}}  # ← merged
]

no?

If not, great but lets add/modify integ tests to prove that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! You were absolutely right - my original approach was incorrect.

After investigating further, I discovered:

  1. The merging approach violates Bedrock's tagged union structure - content blocks can only have one key (text, document, cachePoint, etc.), so merging cachePoint into a document block like {"document": {...}, "cachePoint": {...}} causes ParamValidationError

  2. Issue [BUG] BedrockModel doesn't handle cachePoint content blocks in messages, causes ValidationException #1219 was already fixed by PR feat(bedrock): add automatic prompt caching support #1438 - The _format_request_message_content method already handles cachePoint blocks correctly by returning {"cachePoint": {"type": "..."}} as a standalone block (line 478-479)

I've updated this PR to:

  • Remove my incorrect merging logic
  • Add a regression test to verify cachePoint blocks are correctly formatted as separate blocks

The test confirms that:

content = [
    {"text": "Some text"},
    {"cachePoint": {"type": "default"}}
]

is correctly preserved as two separate blocks, not merged.

Thanks for catching this! 🙏

@github-actions github-actions bot added size/m and removed size/s labels Jan 28, 2026
Add test to verify cachePoint blocks are formatted as standalone blocks
and not merged into previous content blocks. This confirms the fix from
PR strands-agents#1438 works correctly for the scenario reported in Issue strands-agents#1219.

Closes strands-agents#1219
@minorun365 minorun365 force-pushed the fix/bedrock-cachepoint-in-messages branch from e1930f7 to 45c2488 Compare January 28, 2026 17:11
@github-actions github-actions bot added size/s and removed size/m labels Jan 28, 2026
@minorun365 minorun365 changed the title fix(bedrock): merge cachePoint into previous content block in messages test(bedrock): add regression test for cachePoint as separate block Jan 28, 2026
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] BedrockModel doesn't handle cachePoint content blocks in messages, causes ValidationException

2 participants