-
Notifications
You must be signed in to change notification settings - Fork 889
Issue with Bedrock and Claude Model: ValidationException on Blank Text Field #1678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@celeriev Since there's nothing in the code you've shared or PydanticAI that intentionally builds empty text parts, I'm guessing it's Bedrock/Claude itself that's generating them and sending them to us, we're sending them back as part of the chat history along with a tool call response, and then Bedrock is complaining about what's effectively its own output. To know exactly where to modify the code, we'll need to know a bit more about the type of content block the empty text appears on. Can you please add Logfire (https://ai.pydantic.dev/logfire/) and share the JSON body of the request that results in the error response? |
Thanks for your tips @DouweM. Here's what I got with the help of logfire: Error: JSON body of the message.25:
You guessed correctly, it seems like bedrock returns a message for a tool call with empty content, causing it to break. Happy to contribute to fixing this by the way Edit: Another example: JSON Body of message.17
|
@celeriev All right, looks like we need a check here for
Can you please try that out and submit a PR if it works? |
Hello @DouweM, it is ready for review. This solved the issue for me |
Uh oh!
There was an error while loading. Please reload this page.
Initial Checks
Description
While using pydantic Bedrock with Claude Model. I often reach the following issue:
It's not always messages 21, it can be another. But most of the time it happens after a number of tool calls, potentially unsuccessful.
Unfortunately, I'm not sure to understand how to best replicate this. The following snippet led me to face this error in 50% of cases, so it can be used for that. However, I'd need some help to create a more robust code snippet to replicate this error.
I believe we could solve this from ensuring content is not empty in https://github.com/pydantic/pydantic-ai/blob/240b0120bf542e8dbeeb52e7b0f4836f964ededa/pydantic_ai_slim/pydantic_ai/models/bedrock.py#L367C15-L367C28
Example Code
Python, Pydantic AI & LLM client version
The text was updated successfully, but these errors were encountered: