Structured Outputs is a capability in the Chat Completions API that guarantees every model response conforms exactly to a JSON schema you define. Unlike JSON mode — which only ensures the model emits valid JSON — Structured Outputs enforces 100% schema adherence: every required field is present, every type matches, and no extraneous properties appear. This makes it possible to consume model output directly in typed application code without defensive parsing or error handling.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openai/openai-cookbook/llms.txt
Use this file to discover all available pages before exploring further.
Why Structured Outputs matters
Before Structured Outputs, extracting structured data from model responses required prompt engineering (“respond only with JSON”), fragile regex parsing, or retry loops to handle malformed output. Even with JSON mode enabled, the model might omit optional fields, use wrong types, or include keys not in your schema. Structured Outputs eliminates this class of problem entirely. The constraint is enforced at the sampling layer — the model literally cannot produce a token sequence that violates your schema.100% schema adherence
Every field, type, and constraint in your schema is enforced. No parsing surprises in production.
Pydantic integration
Pass a Pydantic model directly and get back a fully-typed Python object via
.parsed.Refusal handling
When the model declines to answer, the refusal is surfaced cleanly so you can handle it explicitly.
Function calling support
Use
strict: true on function definitions to enforce schemas on tool call arguments too.Using Pydantic models with .parse()
The simplest way to use Structured Outputs is with the client.beta.chat.completions.parse() method and a Pydantic model. The SDK automatically converts your model into a JSON schema, sends it to the API, and deserializes the response into a typed object.
.parsed attribute contains a fully-typed CalendarEvent instance — no json.loads() required.
Nested models
Pydantic supports arbitrarily nested models, which the SDK converts into a nested JSON schema automatically.Using the JSON Schema approach
If you prefer not to use Pydantic, or need to define schemas dynamically at runtime, you can pass a raw JSON schema via theresponse_format parameter with type: "json_schema".
additionalProperties: false and all fields listed under required are mandatory when strict: true is set. The API will reject schemas that do not satisfy these constraints.Structured Outputs with function calling
You can also applystrict: true to function definitions to guarantee that the arguments the model passes to your function match the schema exactly.
Handling refusals
When the model determines it cannot fulfill a request — due to safety policies or content concerns — it returns a refusal rather than structured output. Check for this before accessing.parsed.
Supported schema types and limitations
Structured Outputs supports a rich subset of JSON Schema, but not every feature:- Supported
- Not supported
- Primitive types:
string,number,integer,boolean,null objectwith required properties andadditionalProperties: falsearraywith a singleitemsschemaenumwith string valuesanyOffor optional fields (e.g.,anyOf: [{type: "string"}, {type: "null"}])- Nested objects and arrays up to 5 levels deep
Optional fields must be expressed using
anyOf with a null type, not by omitting the field from required. All fields must be listed in required when strict: true is enabled.Common use cases
Data extraction
Extract structured records from unstructured text — receipts, contracts, support tickets — and write them directly to a database without a parsing layer.
UI rendering
Generate structured content that maps directly to UI components — steps, cards, tables — without post-processing.
Next steps
Responses API intro
Learn about the stateful Responses API with built-in tools for web search, file search, and code interpreter.
File search
Upload documents to a vector store and query them with the file search tool in the Responses API.