Structured output (JSON mode)

Definition

Structured output is a way of getting an AI model to return its answer in a fixed, machine-readable format, usually JSON with named fields, instead of free text. It lets another program read the answer reliably, for example to fill a spreadsheet row or pick the next step in a workflow.

By Ronan Liedmeier, fractional head of growth and course author · Published 17 October 2026 · Last updated 17 October 2026

Also called: JSON mode, Structured Outputs

You need it the moment an AI answer feeds an automation rather than a person. A human can read a paragraph and pick out the supplier name. A workflow step expecting a field called "supplier" breaks when it gets prose.

How it works

You give the model a schema: the field names, their types and, for some fields, a fixed list of allowed values (an enum). The model fills in those fields. Many APIs have a setting that enforces the format. OpenAI's documentation separates two levels: JSON mode, which guarantees valid JSON but does not check it against your schema, and Structured Outputs, which makes the response match the JSON Schema you supply.

A correctly shaped answer can still hold wrong values. Validate the output in your code before it changes anything, such as updating a CRM record or sending an email.

Example

An operations manager extracts details from supplier invoices into a sheet. Her schema has five fields: supplier, invoice_date, total, currency and category, where category is an enum of "software", "contractors", "ads" or "unknown". When an invoice is ambiguous, the model returns "unknown" and the workflow sends that row to her for a quick check instead of filing it under the wrong budget line.

Common mistake

Building a schema with no way to say "I don't know". If every field must hold a real value, the model guesses, and the guess looks as confident as a correct answer (a form of hallucination). Add an "unknown" option to enums and keep schemas small. A long schema asking for data the source document does not contain mostly produces invented values.

Learn it in AI Academy

Related terms

AI workflow
An AI workflow is a fixed series of steps, set in advance by a person or by code, in which an AI model handles one or more of the steps. The steps run in the same order every time, which makes a workflow easy to test and check.
API (application programming interface)
An API (application programming interface) is a set of requests a software service agrees to accept from other programs, a bit like a menu. A program sends a request such as "create a contact" and the service sends back data or a confirmation.
AI guardrails
AI guardrails are checks and limits placed around an AI system that block or flag unsafe or wrong inputs and outputs before they cause harm. The strongest ones run as code outside the model, so a cleverly worded request can't talk its way past them.
Hallucination
A hallucination is a false statement an AI model presents as fact, such as a made-up statistic, quote or source. It happens because language models are trained to produce likely-sounding text, and likely-sounding text is sometimes wrong.

Sources

Browse all terms

Find your next step with AI