JSON mode (basic)
- It only guarantees valid JSON is returned, but field names / types may not match what you expect.
- You must hint “return JSON” in the prompt, or the model may refuse due to safety policy.
JSON Schema (strict)
strict: true makes the model apply token-level constraints during generation, so the output is 100% schema-compliant.
Supported models
- OpenAI:
gpt-5.5/gpt-5.4-mini/ theo3series. - Claude: supported indirectly (prompt guidance + tool enforcement).
- Gemini: equivalent constraints via
responseSchema.
Python (Pydantic)
The OpenAI Python SDK provides aparse method that takes a Pydantic model directly:
Gemini
Claude
Claude has no dedicatedresponse_format, but you can achieve an equivalent effect with tool enforcement:
Notes
- JSON Schema constraints slightly increase latency and cost (the model re-validates during generation).
- Even with
stricton, make the schema as explicit as possible (useenum,pattern,min/max, etc.). - Nesting depth ≤ 5, ≤ 100 fields, arrays ≤ 5000 elements; the exact limits are set by the upstream.