Skip to content

AnthropicModel could respect thought signatures generated by BedrockConverseModel with Anthropic models #3757

@jerry-reevo

Description

@jerry-reevo

Initial Checks

Description

We're currently using AWS Bedrock as our main provider for Claude 4.5 with extended thinking enabled, however, they have not approved capacity for the 1M context window version, so we fallback on Anthropic when the context window exceeds the normal 200k tokens.

The issue, however, is when we fallback now, the Anthropic API rejects the message history with the following error (example):

pydantic_ai.exceptions.ModelHTTPError: status_code: 400, model_name: claude-sonnet-4-5-20250929, body: {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.15.content.0.type: Expected `thinking` or `redacted_thinking`, but found `text`. When `thinking` is enabled, a final `assistant` message must start with a thinking block (preceeding the lastmost set of `tool_use` and `tool_result` blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking'}, 'request_id': 'req_011CWCv4PotRxZ3b4h32C8b9'}

The preceeding error from Bedrock is:

pydantic_ai.exceptions.ModelHTTPError: status_code: 400, model_name: us.anthropic.claude-sonnet-4-5-20250929-v1:0, body: {'Error': {'Message': 'The model returned the following errors: Input is too long for requested model.', 'Code': 'ValidationException'}, 'ResponseMetadata': {'RequestId': '47d301d2-6c56-44d6-8c62-dd525f2284c6', 'HTTPStatusCode': 400, 'HTTPHeaders': {'date': 'Wed, 17 Dec 2025 20:47:35 GMT', 'content-type': 'application/json', 'content-length': '93', 'connection': 'keep-alive', 'x-amzn-requestid': '47d301d2-6c56-44d6-8c62-dd525f2284c6', 'x-amzn-errortype': 'ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/'}, 'RetryAttempts': 0}, 'message': 'The model returned the following errors: Input is too long for requested model.'}

Most confusing is the last message when I look at the run_result.all_messages() appears to be a successful completed response from Bedrock:

ModelResponse(parts=[
  ThinkingPart(content='****redacted****', signature='EpIDCkgIChABGAIqQLeXeNvacaf0LQl0gfMgACjIYBjJHP9LGYIEY6psbZ7+v9KXmeIUOmHxvtuiS6230LAC/v32Z7IvAK1Ouzrh4ZASDAnSg9mQmx7ogDj60xoM0ilkuUfGuNJsIVWaIjBgiAPUiQbID8APQVvE39SHLfdeO68/9PGMA0mlbmjZ5qo40YZEK3+GFcX1ROUqKBUq9wEaEIuDhgmCNEBX2/+vaSoxblXFxawDks1HG2Vk/Snup8poehpDnSos4DHcF9g+UN5NZs2HOZP9AL510grTstQfVYomhpkhiffOp5jUgnWv44DiSjtza/GPjj4NNp/9dnbklunTAtjBN/P0rQatORn4xXbHpN8BUr/jEfxHh+mjMCYaobB+xC6G+p3VGzBfJDjBOEg+EJcJYxfG1tz+cTRN7GVjqhRBSdt/UJr1z6Q/d9SsR+5ZofJcyrZzIGrAvMeltHaS8OC28JbigO5NUhM39FAsRbTOc2vxjQM9YaRV4mF0rVclsF53olXLHpro9t1m072mSLJ5GAE=', provider_name='bedrock'), 
  TextPart(content='Based on my analysis ****redacted****')
  ], 
  usage=RequestUsage(input_tokens=151045, cache_read_tokens=7159, output_tokens=951), 
  model_name='us.anthropic.claude-sonnet-4-5-20250929-v1:0', 
  timestamp=datetime.datetime(2025, 12, 17, 20, 47, 10, 400520, tzinfo=datetime.timezone.utc), 
  provider_name='bedrock', 
  provider_url='https://bedrock-runtime.us-west-2.amazonaws.com', 
  provider_details={'finish_reason': 'end_turn'}, 
  provider_response_id='5bca065d-0edc-4d1e-aa2d-08078c7bfa89', 
  finish_reason='stop', 
  run_id='aef4ca44-c0d6-4b20-a302-700b2808270e'
)

Example Code

Python, Pydantic AI & LLM client version

pydantic-ai 1.33.0
Python 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions