Fix/bedrock cache point messages #1305
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the
cachePointformatting issue inBedrockModelthat was causingParamValidationErrorwhen using prompt caching with system prompts.Problem: When using
cachePointin system prompts, Bedrock's API returned a validation error because the system content blocks were not being formatted correctly. Bedrock requirescachePointto be a separate content block (tagged union), not merged with other fields.Solution: Added
_format_bedrock_system_blocks()method that formats system content blocks using the same logic as message content blocks, ensuringcachePointblocks remain as separate content blocks.Verified: Cache metrics now show
cacheWriteInputTokenson first request andcacheReadInputTokenson subsequent requests, confirming prompt caching works correctly.Note: Bedrock expects
Related Issues
Fixes #1219
Documentation PR
N/A - No documentation changes needed
Type of Change
Bug fix
Testing
How have you tested the change?
All 92 bedrock unit tests pass (
hatch test -- tests/strands/models/test_bedrock.py)All 1608 unit tests pass (
hatch test)All 19 bedrock integration tests pass (
hatch run test-integ -- tests_integ/models/test_model_bedrock.py)Added 5 new tests specifically for cachePoint formatting
Verified cache metrics show actual cache hits with real Bedrock API calls
I ran
hatch run prepareChecklist
Output
Notes