Summary
PR #1821 moved cache point injection from the last assistant message to the last user message. This causes a ValidationException when the user message contains non-PDF document content blocks (.md, .docx, .csv, .xlsx, .html, .txt).
PDF documents are unaffected — only non-PDF document formats trigger the error.
Error
botocore.errorfactory.ValidationException: An error occurred (ValidationException)
when calling the ConverseStream operation: The model returned the following errors:
messages.0.content.3.type: Field required
Root Cause
When CacheConfig(strategy="auto") is enabled, _inject_cache_point() appends {"cachePoint": {"type": "default"}} to the end of the last user message's content array. When that message contains a document block, the resulting content looks like:
[
{"text": "Analyze this file\n\n[Attached files: README.md]"}, # index 0
{"document": {"format": "md", "name": "readme", "source": {"bytes": b"..."}}}, # index 1
{"cachePoint": {"type": "default"}} # index 2 — causes the error
]
Bedrock cannot translate the cachePoint block to the Anthropic API format when it follows a non-PDF document block. The Anthropic model validation rejects it because the translated block is missing the required type field.
PDFs work because Anthropic natively supports PDF documents in their API, so the conversion path handles the cache point correctly.
Where the Issue Was Introduced
Reproduction
- Configure a Strands Agent with
CacheConfig(strategy="auto") and a Bedrock model (e.g., us.anthropic.claude-haiku-4-5-20251001-v1:0)
- Send a message with a non-PDF document attachment (
.md, .docx, etc.) as a document content block
- The
converse_stream call fails with the ValidationException above
Suggested Fix
_inject_cache_point() should skip appending a cache point to user messages that contain document blocks (with non-PDF formats), or place the cache point before the document block rather than after all content blocks.
Environment
strands-agents==1.32.0
bedrock-agentcore==1.4.7
- Model:
us.anthropic.claude-haiku-4-5-20251001-v1:0
- Region:
us-west-2
Related
Summary
PR #1821 moved cache point injection from the last assistant message to the last user message. This causes a
ValidationExceptionwhen the user message contains non-PDFdocumentcontent blocks (.md,.docx,.csv,.xlsx,.html,.txt).PDF documents are unaffected — only non-PDF document formats trigger the error.
Error
Root Cause
When
CacheConfig(strategy="auto")is enabled,_inject_cache_point()appends{"cachePoint": {"type": "default"}}to the end of the last user message's content array. When that message contains adocumentblock, the resulting content looks like:[ {"text": "Analyze this file\n\n[Attached files: README.md]"}, # index 0 {"document": {"format": "md", "name": "readme", "source": {"bytes": b"..."}}}, # index 1 {"cachePoint": {"type": "default"}} # index 2 — causes the error ]Bedrock cannot translate the
cachePointblock to the Anthropic API format when it follows a non-PDFdocumentblock. The Anthropic model validation rejects it because the translated block is missing the requiredtypefield.PDFs work because Anthropic natively supports PDF documents in their API, so the conversion path handles the cache point correctly.
Where the Issue Was Introduced
documentblocks, so this issue did not exist.Reproduction
CacheConfig(strategy="auto")and a Bedrock model (e.g.,us.anthropic.claude-haiku-4-5-20251001-v1:0).md,.docx, etc.) as adocumentcontent blockconverse_streamcall fails with theValidationExceptionaboveSuggested Fix
_inject_cache_point()should skip appending a cache point to user messages that containdocumentblocks (with non-PDF formats), or place the cache point before the document block rather than after all content blocks.Environment
strands-agents==1.32.0bedrock-agentcore==1.4.7us.anthropic.claude-haiku-4-5-20251001-v1:0us-west-2Related