-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Ignore empty text parts in GoogleModel
#3360
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
Ignore empty text parts in GoogleModel
#3360
Conversation
|
Here's an example of how ctx.state.message_history looks when we hit this case (last few model response / requests). So in this case, before we even get back the tool return, there's a TextPart with the content, and then we get an empty TextPart afterwards. |
|
@naveen-corpusant What do you think about instead not creating That'd mean changing pydantic-ai/pydantic_ai_slim/pydantic_ai/models/google.py Lines 825 to 829 in 4b46b1e
And here: pydantic-ai/pydantic_ai_slim/pydantic_ai/models/google.py Lines 680 to 686 in 4b46b1e
|
|
@DouweM good suggestion- was thinking about this as I was planning to monkey patch for current usage, and realized it'd be cleaner to do this at the google level rather than apply it to all models at the _agent_graph. Let's go with that, I'll update the PR now. |
|
updated! thanks for the review |
GoogleModel
We observe when using gemini 2.5 pro, a significant number of errors with the message
Please return text or call a tool. On debugging, it seems gemini 2.5 will sometimes return an empty text part after a tool call + tool return node, rather than a message with no parts.This updates the check to handle this case as well. There's a few threads like this one: https://discuss.ai.google.dev/t/gemini-2-5-pro-with-empty-response-text/81175 that discuss why gemini is returning an empty text response, but from my testing, this happens even when there is a successful tool call and return
Example of empty message