-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Getting pydantic_ai.exceptions.ModelHTTPError: status_code: 400, model_name: gemini-3-pro-preview, body: {'error': {'code': 400, 'message': 'Unable to submit request because it must include at least one parts field, which describes the prompt input. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini', 'status': 'INVALID_ARGUMENT'}} from gemini3 randomly (at about 10% rate)
What happens:
At some point the gemini generates a response that look as follows. For some reason the model decided to respond with empty text (which is odd, but technically it seems like an ok thing to do - it shouldn't result in the agent crashing).
{
"content": {
"role": "model",
"parts": [
{
"text": ""
}
]
},
"finishReason": "STOP"
}
Pydantic accepts this response and adds previous response with "parts": [{ "text": ""}] into the next model request, but it seems to leave out the empty text string - the request contains "parts": [] - and that results in getting HTTP 400 from the Gemini backend.
The request indeed contains an empty "parts": "parts": [], so getting back HTTP 400 is to be expected, but the agent fails because of this.
[
{
"parts": [
{
"text": "\n__REDACTED_PROMPT_HERE__\n"
}
],
"role": "user"
},
{
"parts": [],
"role": "model"
},
{
"parts": [
{
"text": ""
}
],
"role": "user"
}
]
Looks like the bug is either in Pydantic AI or in the underlying libraries (google genai) - but regardless Pydantic AI should have a better way of handling thi
Example Code
Python, Pydantic AI & LLM client version
pydantic AI 1.21.0
Python 3.13.0
google-genai 1.52.0