# Structured output

> Structured output is a way of making an AI model return its answer in a fixed, machine-readable format, typically JSON matching a defined schema, so that other software can use the result without guessing at free text.

Also called: JSON mode, structured outputs, schema output, JSON schema output, constrained decoding. Category: Models and training. Source: https://aibuildindex.com/glossary/structured-output

## In the index

- Document data extraction: median $1,400, middle half $250 to $5,000, 423 priced briefs (https://aibuildindex.com/cost/document-data-extraction)
- Invoice and receipt extraction: median $1,000, middle half $200 to $4,600, 119 priced briefs (https://aibuildindex.com/cost/invoice-extraction)
- AI model integration: median $4,000, middle half $700 to $12,180, 1,858 priced briefs (https://aibuildindex.com/skills/ai-model-integration)

A person can read a chatty answer and pick out what matters. Software cannot. When an AI model's output feeds a database, a CRM or the next step of an automation, it needs to arrive in a predictable shape: these fields, these types, nothing else. Structured output is the set of techniques for getting that. It is one of the less glamorous parts of an AI build and one of the most important for reliability.

## How it works

The builder defines a schema, usually in JSON Schema form, describing the fields expected, their types and which are required. For an invoice, that might be supplier name as text, invoice date as a date, total as a number and a list of line items.

There are several ways to make the model comply, from weakest to strongest:

- **Prompt instructions.** Asking for JSON in the prompt and showing an example. Works often, fails occasionally.
- **JSON mode.** A provider setting that guarantees valid JSON but not that it matches your schema.
- **Schema-constrained output.** Several providers can enforce a supplied schema during generation, so the response always fits the structure.
- **[Function calling](https://aibuildindex.com/glossary/function-calling).** Defining the schema as a tool's input, which the model fills in.

Even with enforcement, the content can still be wrong. A model can put a plausible but incorrect date into a perfectly valid date field. So builds validate values after the model returns them, for example checking that line items add up to the total, and route failures to retry or human review as part of [error handling](https://aibuildindex.com/glossary/error-handling).

## What it means for cost

Structured output reduces build and maintenance cost wherever AI feeds other systems, because it removes fragile text parsing and makes failures detectable. Designing a good schema takes thought: deciding which fields are truly needed, how to represent missing values, and how to handle documents that do not fit the pattern.

For [data extraction](https://aibuildindex.com/glossary/data-extraction) and [intelligent document processing](https://aibuildindex.com/glossary/intelligent-document-processing) builds, validation rules and exception handling are usually a large share of the work. Ask a builder what schema the build uses, what happens when a value fails validation, and how often outputs go to manual review in testing.

## Common questions

### Does structured output make the answers more accurate?

It makes them more usable, not necessarily more correct. The format is guaranteed or nearly so, but the values still need checks against sources or business rules.

### What is JSON and why is it used?

JSON is a simple, widely supported text format for structured data, made of named fields and lists. Almost every programming language and automation tool can read it, which makes it the default choice for passing AI results between systems.

### Can structured output handle long or nested documents?

Yes, schemas can include nested objects and lists, such as invoice line items. Very complex schemas can lower quality or hit provider limits, so large documents are sometimes processed in sections.

## Related terms

- [Function calling](https://aibuildindex.com/glossary/function-calling): Function calling is a capability that lets a language model request that the application run a defined tool, such as a database lookup, an API call or a calculation, by returning the tool's name and structured arguments instead of plain text.
- [Data extraction](https://aibuildindex.com/glossary/data-extraction): Data extraction is the process of pulling specific fields or records out of unstructured or semi-structured sources, such as documents, emails, web pages or transcripts, and returning them in a consistent, structured format.
- [Intelligent document processing (IDP)](https://aibuildindex.com/glossary/intelligent-document-processing): Intelligent document processing is the automated reading of business documents such as invoices, forms and contracts, combining OCR, layout analysis and language models to turn them into checked, structured data that other systems can use.
- [Prompt engineering](https://aibuildindex.com/glossary/prompt-engineering): Prompt engineering is the practice of designing, testing and refining the instructions, context and examples given to an AI model so that it produces accurate, consistent and correctly formatted output for a specific task.
- [Error handling and retries](https://aibuildindex.com/glossary/error-handling): Error handling and retries are the parts of an automation or AI system that detect failed steps, try them again where that is safe, and report or park the work that still fails, so problems are noticed rather than silently lost.
