Skip to content

cachePoint after non-PDF document blocks causes ValidationException on Bedrock ConverseStream #1966

@philmerrell

Description

@philmerrell

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

  1. Configure a Strands Agent with CacheConfig(strategy="auto") and a Bedrock model (e.g., us.anthropic.claude-haiku-4-5-20251001-v1:0)
  2. Send a message with a non-PDF document attachment (.md, .docx, etc.) as a document content block
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions