PRODUCTION SCENARIO
An extraction app must always return a JSON object with name, date, and guests fields. JSON mode returns valid JSON, but the keys drift and fields go missing.
Which approach guarantees the schema?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: Structured outputs with a strict json_schema response format
Structured outputs make the model follow a JSON Schema supplied as part of the inference call; for Chat Completions the schema goes in response_format with strict set to true. JSON mode is the older feature that guarantees valid JSON but cannot ensure adherence to the schema. Client-side Pydantic validation detects a bad payload after the fact rather than preventing one. strict on a function tool constrains tool arguments, not the response body.