Reliable JSON from AI Models: Designing Structured Output Schemas
How to get dependable JSON from language models with structured outputs: designing the schema, strict mode rules, validating replies and typed code.

Language models are excellent at reading messy input such as invoices, e-mails, support tickets and product pages, and turning it into tidy data. The weak point has always been the hand-over to code. Ask for JSON in the prompt and you get JSON most of the time, but sometimes with a friendly sentence in front, a missing field, a number written as text or an extra key nobody asked for. Each of those breaks a parser. Structured outputs fix the problem at the source by giving the model a schema it must follow. This guide explains how to design that schema well.
How structured outputs work
You send a JSON Schema with the request. With OpenAI's strict mode the model's output is constrained token by token so it can only produce JSON that matches. Gemini accepts a response schema together with a JSON response type. With Claude the common approach is to define a single tool whose input schema is your desired output and force the model to use it; the tool arguments are then your structured result. In every case, the schema is the contract.
Start from the data your code needs
Design the schema backwards from the code that will consume it. List the fields, their types and which ones can be missing. Open the Structured Output Schema Builder; it starts with an invoice extraction example containing a vendor, an invoice number, a date, a currency enum, a list of line items and totals.
Each field gets a description, and these matter more than people expect. The model reads them. A description such as ISO date, or company that issued the invoice, removes ambiguity that would otherwise show up as inconsistent results. Use enums whenever a field has a fixed set of values; a currency enum prevents the model from writing dollars in one reply and USD in the next. Use formats, ranges and length limits for dates, quantities and codes.
Strict mode rules, handled for you
Strict mode has rules that surprise newcomers. Every object must forbid additional properties. Every property must be listed as required. Optional information is expressed by allowing null rather than by leaving the field out. Some JSON Schema keywords are not allowed, and the root must be a plain object rather than a union.
With the strict switch on, the builder writes the schema in this form automatically. A field you mark as not required stays in the required list but accepts null. The checks panel then runs the strict rules and warns about deep nesting, very large property counts and long enum lists, which slow down the first request or make the schema harder for the model to fill.
Look at a sample before you ship
The sample output panel shows a realistic object generated from the schema. Reading it is a quick sanity check: does the shape look like what your code expects, are dates in the right format, does each line item carry what you need? Small design mistakes are easier to spot in an example than in the schema itself.
Validate real replies
Before enabling strict mode, or when using a provider or model without it, check actual replies. Paste a model's answer on the validate tab. The builder strips code fences and leading prose, warning you that it had to, then checks the JSON against the schema. Each problem has a precise path, such as the quantity of the second line item, and a clear message like should be number, got string. A button inserts a deliberately broken reply so you can see what failures look like.
Export the request and the types
The request snippets tab produces ready request bodies for OpenAI's Responses and Chat Completions APIs, an Anthropic request with a forced tool, a Gemini request with a response schema, and plain JSON Schema for your own validators. Model names are left as placeholders so you can fill in the model you use.
The code tab generates TypeScript interfaces and Python Pydantic models from the same schema, with descriptions carried over and optional values typed correctly. Using those types in the code that receives the reply closes the loop: the model, the schema and your application all agree on one shape.
A note on prompts
A schema does not replace instructions. Still tell the model what to extract and how to handle unclear cases, for example to return null when a due date is not printed rather than guessing. The schema guarantees the shape; the prompt guides the content.



