Structured output

Updated November 24, 2026

Structured output is model output that follows a schema the developer supplies, usually JSON Schema, instead of free text. The API constrains generation so the required fields and allowed values appear in the expected shape, and the application can parse the reply directly. It differs from JSON mode, which produces valid JSON without guaranteeing that it matches a schema.

In short: Structured output is schema-constrained model generation, where an API makes the model's reply follow a supplied JSON Schema so applications can parse required fields and enum values reliably.

How structured output works

A developer writes a schema for the reply in JSON Schema, a declarative language for defining the structure and constraints of JSON data 2. The API then constrains the model's output to that schema, so a completed reply contains the required fields and only allowed enum values 1.

OpenAI offers two ways to apply a schema 1. A json_schema response format shapes the reply the model gives the user, and function calling shapes the arguments the model sends to a tool 1. The guide suggests the response format when the schema describes how the model responds to the user, and function calling when the model connects to the application's own functions and data 1. The second route is tool calling with strict mode switched on.

The Python and JavaScript libraries can define the schema in code, as a Pydantic model or a Zod object, and parse the reply back into a typed object 1. The application gets a parsed object instead of a string to clean up.

Schema adherence does not remove every failure. The guide says applications still need to handle refusals, incomplete responses and API errors, and validate any business rules the schema does not express 1. Safety refusals are programmatically detectable, so code can branch on a refusal instead of searching a text field for one 1.

Structured output also differs from JSON mode. Both produce valid JSON, and only Structured Outputs ensures that the JSON adheres to the schema 1. OpenAI calls Structured Outputs the evolution of JSON mode and recommends it where possible 1.

Availability and setup cost vary by model. OpenAI lists support for both Structured Outputs and JSON mode in the Responses, Chat Completions, Assistants, Fine-tuning and Batch APIs 1. For fine-tuned models, the first request with a new schema carries extra latency while the API processes it, and later requests with the same schema do not 1. Other models do not have this limitation, so a pipeline that reuses one schema pays that cost once at most 1.

Schema limits and the MCP structuredContent field

Structured Outputs supports a subset of JSON Schema 1. Supported types are string, number, boolean, integer, object, array, enum and anyOf, and keywords such as pattern, format, minimum and maximum add constraints to some types 1. Several limits apply on top of that.

Size. A schema may have up to 5000 object properties in total, with up to 10 levels of nesting 1. Property names, definition names, enum values and const values together cannot exceed 120,000 characters, and a schema may have up to 1000 enum values 1.

Closed objects. additionalProperties must be set to false on every object, because the feature only generates the keys and values the schema specifies 1.

Unsupported keywords. Composition keywords such as allOf, not, if, then and else are not yet supported, and a request with strict set to true and an unsupported schema returns an error 1.

Key order. Outputs are produced in the same order as the keys in the schema 1.

MCP uses the term with a different meaning. A tool result can carry structuredContent, a JSON value that conforms to the tool's outputSchema if one is defined 3. The specification says structuredContent is server-produced result data and is unrelated to LLM structured outputs, which it describes as schema-constrained model generation 3. One constrains what a model writes, and the other describes what a server returns. Both can appear in the same agent, for example when a model reads an MCP tool result and then answers in a constrained format.

Example of structured output

A RevOps team scores inbound accounts against its ideal customer profile. For each account, the pipeline calls RichAPI's enrich_company endpoint and passes the record to a model with a response schema.

json
{"type": "object",
 "properties": {
   "score": {"type": "integer", "enum": [1, 2, 3, 4, 5]},
   "segment": {"type": "string", "enum": ["core", "adjacent", "out_of_scope"]},
   "reason": {"type": "string"}},
 "required": ["score", "segment", "reason"],
 "additionalProperties": false}

RichAPI's LangChain guide describes the same pattern, wrapping the enriched company in llm.with_structured_output to get a typed score with a reason field from live data, without an agent loop 4.

Each reply now parses straight into CRM fields. The reason field gives a reviewer a sentence to check, and the segment enum stops the model from inventing a fourth label such as maybe. The schema lists score first, so the reply does too.

The schema guarantees shape only. A top score for a company outside the target market is still a valid reply, so the team spot-checks scores against the enriched fields and keeps the rules that code can check, such as an excluded country, out of the model step.

The paid step is enrichment. RichAPI's enrich_company bills on any successful 2xx response, including an empty one, so the pipeline checks that a record came back before it spends a model call on scoring 4. Accounts with no record go to a separate queue instead of getting a score built from nothing.

Structured output vs tool calling

OpenAI applies schemas in both places and explains when to use each 1. Structured output shapes the reply, and tool calling shapes the request the model sends to a function.

Structured outputTool calling
What it answersWhat shape must the reply take?Which function runs, with which arguments?
InputA response schemaTool definitions with argument schemas
OutputA JSON reply that matches the schemaA call the application must execute
Cost driverTokens for one constrained replyModel turns plus each tool call
Main riskA valid shape with wrong contentThe wrong tool or bad arguments
Use it whenThe app needs typed data from the modelThe model needs data or actions from the app
Read the reference →

Frequently asked questions

What is the difference between structured output and JSON mode?

JSON mode makes the model produce valid JSON, but it does not check that JSON against a schema. Structured Outputs adds schema adherence, so required fields and enum values follow the supplied schema. OpenAI recommends Structured Outputs instead of JSON mode when possible 1.

Does structured output stop hallucinations?

No. It controls the shape of the reply only. The model can still put a wrong value in a valid field, and the guide says applications must validate business rules the schema does not express 1. Check important values against the source data before they reach a CRM or a customer.

Which JSON Schema features does structured output support?

OpenAI supports a subset that includes string, number, boolean, integer, object, array, enum and anyOf 1. Composition keywords such as allOf and not are not yet supported, and every object must set additionalProperties to false 1. Test complex schemas before production.

Is MCP structuredContent the same as structured output?

No. The MCP specification says structuredContent is result data produced by a server and is unrelated to schema-constrained model generation 3. A tool can describe that data with an outputSchema, while structured output constrains what the model itself writes 3.

The bottom line

Structured output makes a model's reply follow a supplied JSON Schema, so applications get typed fields and allowed values instead of free text to parse 1. It does not check facts, so validate business rules in code and handle refusals and incomplete replies 1. Keep schemas small, close every object, stay inside the supported subset and keep it distinct from MCP structuredContent, which is data a server returns 3.

Sources

  1. Structured model outputs, OpenAI
  2. What is JSON Schema?, JSON Schema
  3. Tools (specification, version 2026-07-28), Model Context Protocol
  4. LangChain integration guide, RichAPI

More terms