Structured output

When you need to use AI output downstream, ask for it in a structure, not prose.

What you will learn

  • Pick a structure (JSON, markdown table, bulleted fields) that matches the downstream use
  • Lock the shape so the model cannot improvise extra fields
  • Recover from malformed output without re-running the whole prompt

Concept

If you are pasting AI output back into a tool (a CRM, a spreadsheet, another prompt), prose is the wrong format. You are forcing yourself to do parsing work that the model could have done for you. Structured output solves this.

The first decision is the shape. JSON works when the consumer is another script or AI step. A markdown table works when the consumer is you, scanning a page. Numbered bullets with labelled fields work when the structure is shallow and you want the model to keep its reasoning visible. Pick the lightest structure that survives the use case.

The second decision is the schema. State every field name, every type, and what to do when a field is unknown. "Return a JSON object with keys title (string), audience (string), priority (one of: high, medium, low), and rationale (string, max 30 words). If priority cannot be determined, return medium." That last sentence prevents the model from inventing a fourth priority value or leaving the field blank.

The third decision is what happens at the boundaries. Models love to wrap structured output in conversational scaffolding ("Sure, here is the JSON you asked for!"). Tell them not to. "Return only the JSON object. No preamble, no markdown code fences, no closing remarks." When you are going to parse the output, every extra character is a parsing bug waiting to happen.

When structured output goes wrong, it is almost always because the schema was implicit. The fix is to make it explicit: list the fields, list the allowed values, list the formatting rule for the response wrapper. If you find yourself writing a regex to clean the output, the prompt is doing too little work.

Worked example

Before

Summarise this customer support ticket and tell me how urgent it is.

After

Summarise the customer support ticket below. Return only a JSON object with these keys: summary (string, max 25 words), category (one of: billing, bug, feature_request, account_access, other), urgency (one of: low, medium, high), suggested_owner (one of: support, engineering, sales). No preamble, no markdown fences.

Ticket: [paste ticket text here]
Why it worksEvery consumer of this output, whether a triage script or a dashboard, can rely on the same shape. The enum values prevent the model from inventing a new category. The "no preamble" rule prevents the response from breaking a JSON parser.

Try it

Remove the "no preamble" rule and run it again. See how the model adds conversational wrapper text that would break a parser.

Save your variant

Saved variants stay in your browser only. Clearing site data removes them.