New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
I built a Pydantic model with a couple of optional fields, wired it into a schema, and the strict-mode API call keeps rejecting it without saying which field is wrong.
What you'll have at the end
The same Pydantic model converted into a schema that OpenAI's strict-mode validator accepts on the first call
You need
A Pydantic model with at least one field you intend as optional, already wired into an OpenAI call asking for a schema-shaped reply with strict mode on, the setting that makes the API enforce your schema exactly instead of best-effort, plus the ability to see the raw text the call rejects with.
Not covered
What to do when the schema itself is accepted but the model still returns a wrong or made-up value for a field: that's a separate failure with its own fix.
Resubmit a rejected reply with the schema error attached
the schema itself now passes, but the model's actual reply still gets a field wrong and you want it to see the error and retry.
Write one JSON Schema that satisfies OpenAI and Claude's strict mode
the same schema also has to satisfy Claude's different, looser rules.
Checked 15 Aug 2026
Part of the Structured Output Generation with LLMs cookbook