# Structured output

> Structured output is data returned in a predictable, machine-readable shape, such as JSON that matches a declared schema, instead of free-form text. In AI systems it usually means making a language model respond with fields of known names and types, so that code or another agent can consume the result directly without parsing prose.

Source: https://similariq.ai/glossary/structured-output · Updated 2026-11-25

## What structured output is

Structured output is a response with a fixed shape. Every field has a name, a type and a defined meaning, and the same request always produces the same set of fields. JSON is the most common carrier, though CSV, XML and typed objects in a programming language are all forms of the same idea. The opposite is unstructured output: a paragraph of text that a person can read but a program can only guess at.

The term is used in two overlapping senses. In general software, it describes any API that returns well-defined data. In AI engineering, it refers specifically to getting a language model, which naturally produces free text, to produce data that conforms to a schema. A schema is a formal description of the expected shape: which keys exist, what type each value has, which are required and what values are allowed.

## Why it matters

Software cannot act on a sentence the way it acts on a field. If a step in a pipeline needs a company's domain, a confidence number and a category label, it needs them in known places with known types. When a model returns those inside prose, a developer must write fragile parsing code, and the first time the model phrases something differently the pipeline breaks. Structured output removes that fragility by making the shape a contract.

This matters most when the consumer is another program or an [AI agent](https://similariq.ai/glossary/ai-agent). An agent that receives a clean list of records can filter, sort and count it reliably, and can pass individual values to its next tool. An agent that receives a narrative has to interpret it first, which costs tokens and introduces mistakes. Predictable shapes also make results easy to store, compare over time and load into spreadsheets or databases.

## How structured output is produced

There are three broad ways to get structured data out of a language model, in increasing order of reliability. The first is instruction: you ask for JSON in the prompt and show an example. This usually works and sometimes does not, because nothing prevents the model from adding a preamble or dropping a brace. The second is a JSON mode, where the platform ensures the output is syntactically valid JSON but does not enforce your particular fields.

The third is schema-constrained generation. You supply a schema, and the system restricts what the model may emit at each step so that the finished output must conform. Missing required keys and wrong types become impossible by construction. [Tool calling](https://similariq.ai/glossary/tool-calling) relies on the same idea: the arguments a model passes to a function are structured output matched against the tool's input schema. Whichever method is used, validating the result in your own code remains good practice.

- Prompt instruction: flexible, weakest assurance.
- JSON mode: valid syntax, no promise about fields.
- Schema-constrained output: fields and types enforced.
- Tool arguments: structured output used as the input to a function.
- Post-validation: your code checks the result and retries or rejects on failure.

## A hypothetical example

Suppose a support team wants to triage incoming emails. Asked in plain language, a model might reply: this looks like a billing issue and seems fairly urgent. A person understands that. A routing system does not. So the team defines a schema with three fields: `category`, a string limited to billing, technical or account; `urgency`, an integer from 1 to 5; and `summary`, a string of at most 200 characters.

With schema-constrained output, the same email yields `{"category":"billing","urgency":4,"summary":"Customer charged twice for one order."}`. The routing code reads `category` to choose a queue and `urgency` to set priority, with no parsing. If a new category is needed, the team changes the schema and the downstream code together. The shape is explicit, versioned and testable, which free text never was.

## Designing a good schema

A schema is an interface, and the usual rules of interface design apply. Use clear, specific field names. Prefer enumerated values over open strings wherever the set of possibilities is known, since a fixed list is easier for a model to fill correctly and for code to branch on. Give numbers explicit ranges and units. Keep nesting shallow. Add a short description to each field, because models read those descriptions when deciding what to put there.

Decide how absence is represented. If a value may be unknown, say so in the schema with an optional field or an explicit null, and tell the model to use it. Otherwise the model will invent something to satisfy a required field. Think about stability as well. Adding an optional field is usually safe for existing consumers. Renaming or removing one is a breaking change and should be treated as a new version.

## Common mistakes

The central mistake is confusing valid structure with correct content. A schema ensures the output has an integer in the urgency field. It does not ensure the integer is right. Teams that adopt structured output sometimes stop checking the values because the format looks authoritative. Format and accuracy need separate tests.

Other mistakes are in the design. Schemas grow so large and deeply nested that the model fills them poorly. Every field is marked required, which forces fabricated values. Free-text fields are used where an enumeration would do, pushing the parsing problem downstream. Long outputs are cut off by a length limit, leaving truncated JSON that fails to parse. And consumers are written to assume fields that the schema calls optional, so they crash on the first record that omits one.

## How to evaluate structured output

Measure three layers. Parse rate: what share of responses is syntactically valid? Schema conformance: what share has every required field with the correct type and an allowed value? Field accuracy: for a labelled test set, how often is each field's value actually right? The first two should be at or near complete with constrained generation. The third is where the real work is, and it should be tracked per field, since some will be much harder than others.

When evaluating a data provider's API instead of a model, the questions are similar. Is there a published schema or specification? Are field names and types consistent across endpoints? Are enumerated values documented? Does the response distinguish an empty result from an error? An API with a machine-readable specification lets you generate client code and lets an agent learn the shape without trial and error.

## How it shows up in SimilarIQ

SimilarIQ returns structured data from every interface. A search response is JSON carrying `domain`, `searchId`, `totalCompetitors`, `likelyCompetitors`, `elapsedSeconds` and `creditsRemaining`, plus a ranked list of up to 100 results. Each result has the same fields: `rank`, `company`, `domain`, `matchScore` from 0 to 100, `type` with one of four values (Direct, Indirect, Adjacent, Emerging), `confidence` from 0 to 100 and `likelyCompetitor` as true or false. The shape is published in the [OpenAPI spec](https://similariq.ai/features/openapi-spec) at `/openapi.json`.

The same records are available as [CSV and JSON exports](https://similariq.ai/features/csv-json-export), including CSVs laid out for Salesforce Accounts and HubSpot Companies imports, and through the [REST API](https://similariq.ai/features/rest-api), SDKs, CLI and MCP tools. This describes the response format only, not how results are generated. Note what the structure does not include: there are no contact, revenue, headcount or location fields, so those must be joined from your own data. The [RAG knowledge base use case](https://similariq.ai/use-cases/rag-knowledge-base) shows one way to store the records.

## Related terms

Structured output is closely tied to tool calling, which applies it to function arguments, and to AI agents, which depend on it to chain steps. JSON Schema is the most widely used language for describing the shape. An OpenAPI specification applies the same idea to a whole HTTP API, covering every endpoint, parameter and response.

Downstream, [data normalization](https://similariq.ai/glossary/data-normalization) is the work of bringing values into a consistent format once you have them, and entity resolution is deciding when two records refer to the same real-world company. Structured output makes both easier, because the fields arrive in known positions and only their contents need attention.

## Frequently asked questions

### What is structured output in AI?

It is a model response that follows a defined shape, usually JSON matching a schema, instead of free-form text. Each field has a known name and type, so software can read the result directly without interpreting prose.

### What is the difference between JSON mode and structured output?

JSON mode ensures the response is syntactically valid JSON but does not enforce particular fields. Schema-constrained structured output goes further and requires the response to match a schema you supply, including required keys, types and allowed values.

### Does structured output make a model more accurate?

It makes the format reliable, not the content. A schema ensures a field exists and has the right type. Whether the value in that field is correct still depends on the model and the information available to it, and needs its own testing.

### How is structured output related to tool calling?

Tool calling uses structured output for a specific purpose. When a model requests a tool, the arguments it supplies are structured data matched against the tool's input schema. Structured output more broadly also covers the final answer a model returns.

### What is a schema?

A schema is a formal description of the shape data must have: the field names, the type of each value, which fields are required and which values are permitted. JSON Schema is a common way to write one.

### What format does SimilarIQ return results in?

JSON from the API and MCP tools, with CSV and JSON exports from the app and CLI. Every result has the same fields: rank, company, domain, matchScore, type, confidence and likelyCompetitor. An OpenAPI specification is published at /openapi.json.
