Skip to content

Getting "Unable to submit request because it must include at least one parts field" after gemini model responds with empty text. #3504

@jtattermusch

Description

@jtattermusch

Initial Checks

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions