-
Notifications
You must be signed in to change notification settings - Fork 746
Description
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
- PR: fix: place cache point on last user message instead of assistant #1821 — "fix: place cache point on last user message instead of assistant"
- Commit: b0fc796
- Previous behavior: Cache point was appended to the last assistant message, which never contains
documentblocks, so this issue did not exist.
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 adocumentcontent block - The
converse_streamcall fails with theValidationExceptionabove
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.0bedrock-agentcore==1.4.7- Model:
us.anthropic.claude-haiku-4-5-20251001-v1:0 - Region:
us-west-2