Structured outputs: LLM answers as JSON

Structured outputs make a language model answer in a fixed format such as JSON. Benefits, how to implement them and the limits when connecting to software.

Last updated:

A language model answers in running text by default. If you want to process the answer in software, for example to write fields into a database, you need a fixed format instead. Structured outputs make the answer follow a given schema, typically JSON with named fields and allowed values.

What is it used for?

The typical use is pulling information out of text: from an inquiry email you get name, request and urgency, from an invoice the amount, date and supplier. It also covers sorting items into categories, filling in forms and letting AI agents call tools, where every call must follow a precise format.

How do you implement it?

There are three levels. The simplest is to ask in the prompt for JSON only, in a named shape, with an example. This usually works but not always. More reliable is a schema supplied through the provider's interface: the model receives a description of the fields and is constrained to produce output that matches it. The third level is validation on your side: the program checks every answer against the schema and asks again or rejects it if it does not fit.

What stays uncertain?

The format is then right, but the content is not necessarily. A model can fill a field cleanly and still enter a wrong value, or invent something when the information is missing, see AI hallucinations. It helps to allow "unknown" as a value in the schema, so that the model has an honest way out, and to check important fields against the source.

What should you consider when designing the schema?

Keep the schema small and unambiguous: meaningful field names, few nested levels and fixed choice lists instead of free text wherever possible. Short descriptions of the fields help the model fill them correctly. The less room for interpretation, the more stable the results.

Frequently asked questions

Is JSON output the same as valid content?

No. The schema ensures the form, not the correctness of the values. Check important details against the source as well.

Is a smaller model enough for this?

Often yes. Extracting clearly defined fields frequently works with a smaller model, which is cheaper and faster. A test with your own examples shows whether it is enough.

What if the answer does not match the schema?

Validate every answer in your program. If it fails, retry once or route the case to a person instead of passing bad data on.

Let us talk about your project

Write to kontakt@phronox.de or use the contact form.

Request a project Book a consultation