Getting Structured Output from AI

Make the Answer Something a Program Can Read

A person can read a paragraph. A system cannot. To connect AI to your business systems, the model must return clean, structured data every time.

Ranjit Nethi

·

Getting Structured Output from AI

The short version

  • Business systems need structured data, such as named fields, not free text.
  • Ask for a fixed format, give a schema, and mark clearly where your data starts and ends.
  • Check every output with code before a system uses it. Reject and retry what does not fit.

The idea

When a model’s output feeds another program, the format must be exact. Four practices make that reliable.

Delimiters. Mark the parts of the prompt with clear tags, so the model can tell your instructions from the document it should process.

Output schema. Describe the exact fields, their types and allowed values. The common format is JSON, a simple way to write named fields that every system can read. Most providers now offer a structured output mode that forces the answer to match your schema.

Clear limits. State numbers: “at most three items”, “a date in the form YYYY-MM-DD”.

Positive instructions. Say what to do. “Return null when the field is missing” works better than “do not guess”.

Think of a paper form. A blank page invites an essay. A form with labelled boxes gets the facts you need in the place you expect them.

  1. Document
  2. Prompt with schema
  3. Model returns fields
  4. Code checks the fields
  5. System uses them

Validation is the last and most important step. Code checks that every required field is present and well formed. If not, the system retries or sends the case to a person.

An example

An order desk receives purchase orders as PDF attachments. The prompt asks for seven fields: customer number, order number, part number, quantity, unit, requested date and ship-to address. The schema says quantity must be a whole number and the date must use one format. Code checks each answer and confirms that the part number exists in the catalogue. Orders that pass go straight into the order system. Orders that fail go to a person with the problem field marked.

Common mistakes

  • Parsing free text with fragile pattern matching.
  • No rule for missing values, so the model fills the gap with a guess.
  • Trusting the format and never checking the content.
  • Schemas with vague field names that the model must interpret.

What to do this week

  1. Find one place where staff copy data from documents into a system.
  2. Write the schema: field names, types and allowed values.
  3. Test on 30 documents and count how many pass validation with no human fix.

The terms, in plain language

TermWhat it means
Structured outputAn answer in a fixed format that a program can read
JSONA common text format for named fields and values
SchemaThe definition of the fields and their allowed values
DelimiterA marker that separates parts of a prompt
ValidationCode that checks the output before it is used

Further reading

Section 2.4 of the AI Engineering Guide · Last reviewed November 2026

All parts of the guideChecklists and templates

About the author

Ranjit Nethi leads AI and data for commercial operations at a global industrial manufacturer. He writes about the operating model that turns AI pilots into results finance will sign. Kellogg Executive MBA; MS in Computer Science. This site is his own perspective and view, with no affiliation with any organization.