-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
Description
When running Anthropic models with Pydantic AI, jobs consistently fail around message 10 due to this error: 'message': 'messages.12: all messages must have non-empty content except for the optional final assistant message'.
All of our messages have content in the Pydantic array, but when Pydantic AI converts to the Anthropic array, it injects additional empty messages - sometimes 2 or more - into the new array. In addition, message 12 in the Pydantic array is often mislabeled as a neighbor (see truncated json), meaning message 12 in neither array is actually empty - despite the error saying it is.
Included are these two arrays from a failing job - they have been truncated to address the "message 12" error. Notice the mismatch of indexes within each array, as well as the presence of a phantom empty "user" message in the Anthropic array. Both message arrays were grabbed from the "Raw Data" tab in Logfire.
truncated_anthropic_messages.json
truncated_pydantic_messages.json
Example Code
Not applicable - data mismatch in Pydantic AIPython, Pydantic AI & LLM client version
Python = 3.13.1
Pydantic AI = 0.2.11
LLM Client = claude-3-7-sonnet-20250219