What Are Structured Outputs?

Structured outputs are language model responses that follow a schema the developer provides, so the application receives data with known field names and types rather than free text. The schema is usually written in JSON Schema, the standard vocabulary for describing and validating JSON documents. With structured outputs enabled, the API constrains generation so the result matches the schema, instead of asking the model nicely and hoping.

How It Works

The developer sends a schema with the request: for example, an object with a required vendor name as text, a total as a number and a list of line items. The provider restricts which tokens the model can produce at each step so the output can only be valid against that schema. This is called constrained decoding. The application then parses the response directly into a typed object.

OpenAI’s documentation describes the feature as constraining “completed, non-refusal model output” to the supplied schema, enabled in strict mode (OpenAI Structured Outputs). Other major providers, including Anthropic and Google, offer equivalent features. Each supports a subset of JSON Schema; recursive structures, some formats and some validation keywords may not be supported, so schemas should be kept simple.

Structured Outputs vs JSON Mode vs Function Calling

ApproachWhat is guaranteed
Prompt instructions onlyNothing; the model usually complies
JSON modeThe output is valid JSON, of any shape
Structured outputsThe output is valid JSON that matches your schema
Function calling in strict modeThe tool arguments match the tool’s schema

Function calling and structured outputs use the same mechanism. The difference is purpose: function calling asks the model to request an action, structured outputs shape its final answer.

What Structured Outputs Do Not Guarantee

  • Correct values. The schema guarantees that the total is a number, not that it is the right number. A model can return a well-formed invoice with a wrong amount.
  • Business rules. “End date after start date” or “line items add up to the total” are usually beyond what a schema expresses. Validate them in code.
  • A response at all. OpenAI’s guide notes that refusals may not follow the schema and that responses can be incomplete when they hit the output token limit. Check both before parsing.
  • Good reasoning. Forcing a model straight into a rigid format can hurt answer quality on hard tasks. A common fix is a free-text reasoning field before the result fields, or a separate step that formats the answer.

Where Structured Outputs Are Used

  • Extraction. Pulling fields from invoices, contracts, emails and forms into a database.
  • Classification. Assigning a ticket a category, priority and team from fixed lists.
  • Agents. Passing typed results between steps and between agents, so one agent’s output is another’s reliable input.
  • UI generation. Returning data that a front end renders, rather than Markdown it must interpret.

In Practice

Alltegrio teams define each schema once, as a Pydantic model in Python or a Zod schema in TypeScript, and generate the JSON Schema from it, so the API contract and the application types cannot drift apart. A response that matches the schema can still be wrong, so validation code then checks business rules, such as dates in the right order or line items that add up to the stated total. Extracted fields keep a pointer to the source text, so a reviewer can check each value. This pattern appears in our natural language processing and AI agent development work, and in compliance checking systems like the one in our generative AI cloud solution case.

Back to Glossary

Let's talk about your project

We'll help you harness AI and ML technologies to create innovative software solutions

File requirements: pdf, doc, docx, rtf, ppt, pptx — max 15 MB

No file selected