-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
bugSomething isn't workingSomething isn't working
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
When using GPT 5 series model getting below exception:
venv/lib/python3.13/site-packages/pydantic_ai/_agent_graph.py", line 488, in _run_stream
async for event in self._events_iterator:
yield event
venv/lib/python3.13/site-packages/pydantic_ai/_agent_graph.py", line 484, in _run_stream
raise exceptions.UnexpectedModelBehavior('Received empty model response')
pydantic_ai.exceptions.UnexpectedModelBehavior: Received empty model response
While searching over web, i have found below solution:
where they mentioned:
from openai import AsyncOpenAI
client = AsyncOpenAI()
response = await client.responses.create(
model="gpt-5-mini",
input=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello in one sentence."}
],
max_output_tokens=50,
)
print(f"output_text: '{response.output_text}'") # Empty!
print(f"output[0] type: {response.output[0].type}") # reasoning
Temporary Workaround
Force the output format to text so the model returns a message item:
response = await client.responses.create(
model="gpt-5-mini",
input=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello in one sentence."}
],
text={"format": {"type": "text"}},
max_output_tokens=200,
)
print(response.output_text) # Works now
https://community.openai.com/t/gpt-5-mini-responses-api-empty-output-text-issue/1342786
So, i think this needs to be handled in pydanticAI as well for GPT series model.
Example Code
Python, Pydantic AI & LLM client version
Python version: 3.11
Pydantic: 0.7.4
LLM Client : OpenAIModel(
'gpt-5-mini',
provider=AzureProvider(
azure_endpoint=azure_endpoint,
api_version=api_version,
api_key=api_key,
),
)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working