Skip to content

[BUG] BedrockModel doesn't handle cachePoint content blocks in messages, causes ValidationException #1219

@kazmer97

Description

@kazmer97

Bug Description

When using BedrockModel with Anthropic Claude models and adding cachePoint content blocks to messages (as documented in the integration tests), the Bedrock API throws a ValidationException because the _format_bedrock_messages method passes through cachePoint blocks as-is without proper transformation.

Error:

botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the ConverseStream operation: The model returned the following errors: messages.0.content.2.type: Field required

Steps to Reproduce

from strands import Agent
from strands.models import BedrockModel
from strands.types.content import Messages

model = BedrockModel(
    model_id="us.anthropic.claude-sonnet-4-20250514-v1:0",
    region="us-east-2"
)

messages: Messages = [
    {
        "role": "user",
        "content": [
            {"text": "Some long text..." * 1000},
            {"cachePoint": {"type": "default"}},  # This causes the error
        ],
    },
]

agent = Agent(model=model, messages=messages)
agent("What is the content about?")

Expected Behavior

The cachePoint content block should be properly handled, similar to how AnthropicModel handles it (see src/strands/models/anthropic.py:186-188). The cache point should be applied to the previous content block and then the cachePoint block itself should be removed from the content array before sending to Bedrock.

Actual Behavior

The cachePoint block is passed through as-is in the content array to Bedrock's API, which doesn't recognize it as a valid content block type (expecting types like text, image, document, etc.). This causes a validation error.

Root Cause

In src/strands/models/bedrock.py:276-354, the _format_bedrock_messages method doesn't handle cachePoint content blocks. It only filters:

  • SDK_UNKNOWN_MEMBER blocks
  • DeepSeek reasoningContent blocks
  • Cleans toolResult blocks

But it doesn't handle cachePoint blocks like the Anthropic model provider does.

Proposed Fix

Add cache point handling in _format_bedrock_messages, similar to the Anthropic model:

# Handle cache points by applying them to the previous content block
if "cachePoint" in content_block:
    if cleaned_content:
        # Add cachePoint to the previous block
        cleaned_content[-1] = {**cleaned_content[-1], "cachePoint": content_block["cachePoint"]}
    continue

Additional Context

Environment

  • Strands SDK version: [latest from repo]
  • Python version: 3.12.11
  • boto3 version: [latest]
  • Model: us.anthropic.claude-sonnet-4-20250514-v1:0
  • Region: us-east-2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions