Structured output

Structured output is a feature of AI model APIs that forces a model's response to follow a format the developer specifies, usually a JSON schema, so software can read it reliably.

Language models produce free text, but most software needs data in a fixed shape: a name field, a date field, a true-or-false flag. For years developers asked models nicely for JSON and then wrote code to catch the times they got it wrong. Structured output replaces asking with enforcing. The developer supplies a schema, typically in the JSON Schema standard, and the API guarantees the response matches it.

The enforcement happens during generation, through a technique called constrained decoding. OpenAI, which launched Structured Outputs in its API on August 6, 2024, explained that it converts the schema into a context-free grammar. After each token, the inference engine works out which next tokens would keep the output valid and masks out all the others, so an invalid token has effectively zero probability of being chosen. On OpenAI's evaluation of complex schemas, gpt-4o-2024-08-06 with the feature scored 100%, against under 40% for the older gpt-4-0613 without it.

This differs from the earlier JSON mode, which guaranteed only that the output was valid JSON, not that it had the right fields. Anthropic offers structured outputs for Claude in two forms: a JSON schema for the response itself, and strict tool use, which validates the names and inputs of tool calls. The same idea underlies reliable function calling in AI agents.

The guarantee covers form, not truth. OpenAI notes that a response can match the schema perfectly and still contain wrong values. Not every schema feature is supported: Anthropic's documentation, for example, rejects recursive schemas and numeric limits such as minimum and maximum. The first request with a new schema is slower while the grammar is compiled, and a response cut off by a token limit or a refusal can still fail to match.

For anyone building products on language models, structured output turns extraction jobs such as pulling details from invoices, emails or forms into dependable plumbing. It removes a whole class of parsing failures, but the extracted data still needs the same checks as any other model output.

Common questions

What is structured output in an LLM?

It is an API feature that makes a model's response conform to a format the developer defines, usually a JSON schema. The provider enforces the format during generation, so software can parse the output reliably, apart from refusals and responses cut off by a token limit.

What is the difference between structured outputs and JSON mode?

JSON mode guarantees only that the response is valid JSON. Structured outputs guarantee that it also matches a specific schema, with the required fields and types. OpenAI introduced Structured Outputs in August 2024 as a step beyond its earlier JSON mode.

How does constrained decoding work?

The schema is turned into a grammar, and at each step of generation the model is only allowed to pick tokens that keep the output valid under that grammar. All other tokens are masked out. The model still chooses the content; the grammar only rules out invalid structure.

Can structured output still be wrong?

Yes. The format is guaranteed, but the values inside it are not. A model can return a perfectly valid record with a wrong date or an invented name, so extracted data should still be validated against the source where accuracy matters.

Finding more

Search for "structured outputs", "constrained decoding" or "JSON schema LLM" to see how different providers implement the feature. The providers' API documentation lists which schema features are supported and is the reliable reference, since support differs between them. Open-source libraries for constrained generation have documentation explaining the grammar techniques in more depth.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.