openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

BaseModel to jsonschema for Structured Outputs

Open federicoromeo opened this issue 10 months ago • 1 comments

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • [x] This is a feature request for the Python library

Describe the feature or improvement you're requesting

Do you provide any helper function to generate the correct jsonschema starting from a pydantic BaseModel, to provide it to the response_format?

It's a big struggle not to have it. Imagine like in the Batch API in which i cannot provide the Pydantic instance

I tried with to_strict_json_schema but it doesn't work as expected, it puts keys like $defs and $refs.

Additional context

No response

federicoromeo avatar Feb 05 '25 14:02 federicoromeo

I found: from openai.lib._parsing._completions import type_to_response_format_param

federicoromeo avatar Feb 06 '25 14:02 federicoromeo

from openai.resources.responses.responses import _type_to_text_format_param

HamzaYslmn avatar Sep 26 '25 12:09 HamzaYslmn