Skip to content

Conversation

@samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Jul 17, 2025

@DouweM @Kludex I think there were some issues about this, can you remember?

maybe fixes #527?

Although the OpenAI SDK claims to return a Pydantic model (ChatCompletion) from the chat completions endpoint:

  • it hasn't actually performed validation (presumably they're creating the model with model_construct or something?!)
  • if the endpoint returns plain text, the return type is a string

Thus we validate it fully here.

@github-actions
Copy link

github-actions bot commented Jul 17, 2025

Docs Preview

commit: 4936d3b
Preview URL: https://590247dd-pydantic-ai-previews.pydantic.workers.dev

Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you generating those tests? Manually? 🤔

@samuelcolvin
Copy link
Member Author

How are you generating those tests? Manually? 🤔

I generated them by changing the URL to something that returned text from a post request, then setting the URL back.

@samuelcolvin samuelcolvin merged commit 772af1d into main Jul 22, 2025
18 checks passed
@samuelcolvin samuelcolvin deleted the check-openai-reponse-type branch July 22, 2025 01:51
KRRT7 pushed a commit to aseembits93/pydantic-ai that referenced this pull request Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Error responses are not handled correctly for google openai/openrouter

4 participants