JSON Schema outputs: constrain a model’s response format and fields
JSON Schema output is a way to pass a schema to a generation API so the model’s response follows a predefined JSON structure. It can explicitly constrain field names, types, required fields, and allowed values—more precisely than a prompt that simply says “reply in JSON.” But a structurally valid response is not necessarily true or compliant with business rules. Meaning and application-level checks are still required.
JSON Schema outputs: constrain a model’s response format and fields
JSON Schema output is a way to pass a schema to a generation API so the model’s response follows a predefined JSON structure. It can explicitly constrain field names, types, required fields, and allowed values—more precisely than a prompt that simply says “reply in JSON.” But a structurally valid response is not necessarily true or compliant with business rules. Meaning and application-level checks are still required.
How do JSON, JSON Schema, and structured output differ?
JSON is a format for representing data as keys and values. JSON Schema describes which fields that data should contain and the types or conditions their values must satisfy. For example, a classification result might have category and priority fields, with category restricted to a few labels.
Asking for JSON in a prompt is a natural-language instruction. JSON mode can help generate parseable JSON, but it does not guarantee a particular field structure. OpenAI Structured Outputs accepts a supported JSON Schema through the API and constrains a completed, non-refusal response to follow it. Check that the API path and model you use support the feature. The structured prompt article covers human-readable headings and tags; this article focuses on the machine-readable output contract.
How do you design a small schema?
Start with only the fields downstream code actually needs. Assign a type to each field, and use enum when a field must be one of a fixed set of choices. In OpenAI strict Structured Outputs, every object field must be listed in required, and additionalProperties: false must disallow undefined keys. If a value may be absent, represent it with a type that includes null instead of omitting the field. These are constraints of this API feature; do not confuse them with all JSON Schema rules.
For example, a customer-message classification result could use this schema:
{
"type": "object",
"properties": {
"category": { "type": "string", "enum": ["refund", "shipping", "other"] },
"priority": { "type": "string", "enum": ["low", "normal", "high"] },
"order_id": { "type": ["string", "null"] }
},
"required": ["category", "priority", "order_id"],
"additionalProperties": false
}This is an example schema. All three fields must appear; category and priority must be allowed values; and order_id must be a string or null. It does not mean the model has found the correct order number. The schema constrains what type of value may appear in order_id; the application must check whether that string matches a real order.
What should you validate after connecting the API?
The OpenAI Responses API supports a Structured Outputs path that specifies JSON Schema as the text output format. Pass a schema name and object definition in the request and enable strict mode. Exact SDK syntax and supported keywords can change, so consult the current documentation for the SDK and model you use. OpenAI documents that an unsupported schema sent in strict mode can produce an API error.
Derive the required fields and types from the code that consumes the result.
Define a small object schema; decide required fields, enums, and extra-property rules.
Check model/API-mode compatibility and supported keywords, then add the schema to the request.
Handle completed responses, refusals, and incomplete responses such as token-limit stops.
Validate business rules separately and evaluate representative as well as boundary cases.
For example, whether high priority requires human review, whether order_id exists in the database, and whether the classification is supported by the message are business rules outside the schema. Passing JSON Schema validation does not check them. Handle refusals, interruptions, and API errors as normal branches, and never store incomplete output as a completed result.
When should you use it, and what are its limits?
Structured output is useful for classification, extraction, or tool-input construction when downstream code expects stable keys and types. If a person only needs to read a JSON example, a prompt instruction or JSON mode may suffice. A schema is more suitable when allowed values also need to be constrained, but you must follow the supported schema subset and model compatibility of the API.
An oversized schema can be hard to design, change, and keep compatible. Do not force unnecessary optional fields to be meaningful; define in your application contract whether null means “unknown,” “not applicable,” or “not extracted.” Strict formatting helps prevent malformed structure; it does not eliminate hallucinations, control permissions, or replace business validation.
Sources
[OpenAI API: Structured model outputs](https://developers.openai.com/api/docs/guides/structured-outputs) — schema constraints, Responses API, strict-mode limits, refusals, incomplete responses, and application validation. Read 2026-11-22.
[JSON Schema: object](https://json-schema.org/understanding-json-schema/reference/object) — `properties`, `required`, additional properties, and required versus nullable values. Read 2026-11-22.