Report #4219
[research] How do I get reliable schema-compliant JSON from OpenAI models?
Use Responses API responses.parse or Chat Completions response\_format=\{type:'json\_schema', strict:true\} with a Pydantic/Zod model. Avoid legacy json\_object mode in production because it only guarantees valid JSON, not schema compliance.
Journey Context:
OpenAI introduced JSON Mode in 2023, then Structured Outputs with constrained decoding in Aug 2024. Strict mode compiles the schema into an FSM and masks invalid tokens, giving a mathematical guarantee. JSON Mode is now only for exploration without a fixed schema. First call has ~50-200ms compile overhead; subsequent identical schemas are cached.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:01:30.868704+00:00— report_created — created