Skip to content

GPT-5/o4-mini empty summary responses and AG-UI integration #2687

@Joakim-T

Description

@Joakim-T

Initial Checks

Description

Struggling with Pydantic AI, GPT-5 and the AG-UI integration.

Perhaps a related issue: #2645

OpenAI Responses API using GPT-5, o4-mini etc. send empty reasoning summary every single time even with summary set to None. This according to OpenAI is just how it is..

Problem

Pydantic AI's AG-UI integration generates invalid ThinkingTextMessageContentEvent objects with empty delta strings when using OpenAI reasoning models, causing AG-UI protocol validation failures that crash the streaming response.

This currently makes it impossible to use any OpenAI reasoning model (GPT-5 model/o4-mini etc.) with Pydantic AI's AG-UI integration, unless i missed something during all my debugging.

Error Output

The streaming starts successfully but then crashes:

data: {"type":"RUN_STARTED","threadId":"test-thread-123","runId":"test-run-456"}
data: {"type":"THINKING_TEXT_MESSAGE_START"}
data: {"type":"RUN_ERROR","message":"1 validation error for ThinkingTextMessageContentEvent\n  Value error, Delta must not be an empty string [type=value_error, input_value={'type': <EventType.THINKING_TEXT_MESSAGE_CONTENT>, 'delta': ''}, input_type=dict]"}

Expected vs Actual Behavior

Expected: Thinking events should either contain non-empty delta strings or be filtered out entirely if empty.

Actual: PydanticAI generates ThinkingTextMessageContentEvent objects with delta: '' (empty string), which fails AG-UI protocol validation.

The issue appears to be in PydanticAI's AG-UI event generation logic where:

  1. The reasoning model generates thinking content (working correctly)
  2. PydanticAI processes this into AG-UI events (working correctly)
  3. Some thinking chunks result in empty delta strings (bug here)
  4. AG-UI protocol validation rejects empty deltas (working correctly)

Workarounds

Use a Non-reasoning model
Just swapping to GPT-4.1 with no other changes works straight away.

Set "summary": detailed
Works whenever the model occasionally feels like generating a summary.

Custom Event Filtering
Would require require bypassing handle_ag_ui_request entirely so not ideal.

Suggested fix

AG-UI event generation should filter out or skip ThinkingTextMessageContentEvent objects when the delta is empty, rather than generating invalid events that fail protocol validation.

Example Code

Python, Pydantic AI & LLM client version

- **PydanticAI Version**: `pydantic-ai-slim==0.7.6`
- **Model**: `gpt-5` (OpenAI Responses API)
- **GPT-5 settings**: "reasoning": {"effort": "low", "summary": None},
"text": {"verbosity": "low"}
I have tested with text={"format": {"type": "text"}} also.
- **Integration**: `handle_ag_ui_request()` with FastAPI
- **Provider**: Azure OpenAI with `OpenAIResponsesModel`
Not using AsyncAzureOpenAI since Azure launched the new v1 APIs.

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