Introduction
Structured Outputs is OpenAI's mechanism for constraining model responses to a JSON Schema. Released as a successor to JSON mode, it guarantees schema adherence rather than merely guaranteeing valid JSON. For production LLM applications, this distinction matters: JSON mode only promises that the output parses as JSON, while Structured Outputs ensures the output matches a declared schema, including field names, types, required fields, and enumerations. Teams building extraction, classification, tool-calling, and API-integration features can rely on Structured Outputs to reduce parsing failures, eliminate retry loops, and simplify downstream validation.
This guide explains how Structured Outputs works, when to use it, how to design schemas for production, how to handle refusals and partial results, and what limitations to plan around. It draws on OpenAI's official Structured Outputs documentation and the Responses API reference. All examples are hypothetical and meant to illustrate patterns, not to represent real customer data.
How Structured Outputs Differs from JSON Mode
JSON mode, introduced earlier, constrains the model to emit syntactically valid JSON but makes no promises about the shape of that JSON. A model can return {"status": "ok"} when the schema expects {"result": "ok"}, and JSON mode still considers it valid. Downstream code must then validate the payload again, often with a separate schema library, and handle mismatches case by case.
Structured Outputs constrains token generation itself so that every emitted token conforms to the provided JSON Schema. OpenAI documents that it supports schema adherence, explicit refusals, and simpler prompting. Because the model is guided toward the declared structure during generation, applications receive far fewer malformed responses. OpenAI recommends always preferring Structured Outputs over JSON mode when the target model supports it.
Structured Outputs is available in the latest OpenAI models, including the gpt-6-astra family and later. It works through the Responses API text.format parameter, preferably using native SDK schema helpers that generate the schema from language types.
Designing Schemas for Production
OpenAI enforces specific rules for schemas used with Structured Outputs. Understanding these rules before authoring schemas prevents runtime errors and schema-rejection surprises.
Root and Object Rules
The schema root must be an object, not a bare string, number, or array. Every field must be listed in the required array. OpenAI does not support optional fields in the traditional sense; to model a field that may be absent, include both string and null in its type union, such as ["string", "null"], and treat null as the absent case. Objects must set "additionalProperties": false, and the output key order matches the schema key order.
Supported Types and Constraints
Supported JSON Schema types include string, number, boolean, integer, object, array, enum, and anyOf. Supported constraints include pattern, format (such as date-time, email, and uuid), minimum/maximum, and minItems/maxItems. The "$defs" keyword and recursive schemas using "$ref" are supported.
Unsupported Keywords
OpenAI explicitly does not support allOf, not, dependentRequired, and if/then/else. Schema authors should flatten inheritance-like structures into a single object or use anyOf unions instead of allOf composition. There are also hard limits: at most 5,000 object properties, 10 nesting levels, 120,000 total characters across property, enum, and const names, and 1,000 enum values total.
A hypothetical customer-support schema might look like this:
{
"name": "support_ticket",
"strict": true,
"schema": {
"type": "object",
"additionalProperties": false,
"required": ["category", "priority", "summary"],
"properties": {
"category": {
"type": "string",
"enum": ["billing", "technical", "account", "general"]
},
"priority": {
"type": "string",
"enum": ["low", "medium", "high", "critical"]
},
"summary": {
"type": "string",
"maxLength": 200
},
"refund_amount": {
"type": ["number", "null"],
"minimum": 0
}
}
}
}
Setting strict: true tells OpenAI to enforce the schema during generation. The refund_amount field demonstrates the optional-field pattern: it can hold a number or be null when no refund applies.
When to Use Structured Outputs
Structured Outputs is well-suited to several production patterns.
Data Extraction
Extracting entities from unstructured text—such as invoice numbers, dates, and amounts from receipts—benefits from a fixed schema. The application can consume the model output directly without a second parsing pass.
Classification
Classifying user messages into predefined categories with priorities works cleanly with enum fields. Because the model cannot invent category values outside the enum, downstream routing logic remains predictable.
Tool Calling and API Integration
When an LLM must generate arguments for a function call or an API request, Structured Outputs guarantees that the argument object matches the API's expected shape. This reduces failed integrations caused by missing or mistyped fields.
Configuration Generation
Generating configuration files, feature flags, or rule sets in JSON form is safer when the schema enforces required fields and value constraints.
Handling Refusals and Partial Results
Even with Structured Outputs, a model may refuse to generate content matching the schema, or it may stop before completing the object. OpenAI documents that refusals and incomplete responses are communicated through the incomplete_details.reason field. Possible reasons include max_output_tokens when the response exceeds the output limit, and content_filter when the output triggers a safety filter.
Production code should inspect incomplete_details.reason on every response and decide how to handle each case. For max_output_tokens, the application can retry with a smaller requested scope or a higher output limit. For content-filter refusals, the application should surface a user-friendly message rather than retrying the same request.
Streaming is supported through the SDKs, allowing applications to handle text and refusal deltas incrementally. Streaming does not change the schema contract: the final assembled output must still conform to the schema.
Schema Drift and Type Safety
OpenAI recommends using SDK schema helpers or CI checks to prevent drift between JSON Schema and language types. When a schema changes—such as adding a required field or renaming an enum value—the language types and the schema must be updated together. A CI check that compares the schema used in production against the schema generated from code can catch drift before deployment.
For unrelated user input, add prompt guidance for empty or fallback responses, since the model may attempt to force unrelated content into the declared schema. Explicitly instructing the model to produce JSON also helps; without such instruction, the model may emit whitespace until token limits are reached.
Limitations and Operational Considerations
Structured Outputs is not a substitute for business-logic validation. A response can match the schema perfectly while containing semantically invalid data—for example, a future date in a birth-date field, or a refund amount that exceeds the original purchase price. Applications should still validate business rules after schema validation.
The model may hallucinate to fit the schema when the input lacks sufficient information. For example, if the user does not provide a category but the schema requires one, the model might guess. Prompt guidance should tell the model to use null or a designated "unknown" value when information is missing, rather than inventing a value.
Structured Outputs availability depends on the model. Older models may only support JSON mode. Applications should check model capabilities before assuming Structured Outputs is available, and should have a fallback path using JSON mode plus client-side validation for older models.
Conclusion
Structured Outputs gives production LLM applications a reliable way to obtain schema-conformant JSON from models, reducing parsing failures and simplifying downstream integration. By designing schemas with strict: true, listing all fields as required, using additionalProperties: false, and handling refusals through incomplete_details.reason, teams can build more predictable LLM features. Structured Outputs should be paired with business-logic validation and prompt guidance for missing information, and teams should verify model support before relying on it in production.
For related guidance on choosing between fine-tuning and RAG, see Fine-Tuning vs RAG: Production Decision Framework for LLM Apps.