Start studying
Module 7 · Prompt Engineering Module contents
Module 7  ·  Card 12 / 17beginner

Structured Outputs

Structured output means the model returns machine-parseable data such as JSON.

You supply the schema and the model fills it in.

Many APIs can enforce the schema so parsing never fails.

This is what lets an LLM slot into a normal software pipeline.

Prefer enforced schemas over asking politely and hoping for valid JSON.

Learn in depth ↓
Module 07 · Prompt Engineering · 17 concepts
In depth  /  15 lines

Structured Outputs, in more detail

Structured output means the model returns data your code can parse, usually JSON.

It is what lets a language model sit inside an ordinary software pipeline.

Free prose has to be parsed with regular expressions, which breaks the moment wording shifts.

The weak version is asking for JSON in the prompt and hoping.

That mostly works and fails often enough to hurt at scale.

Typical failures are a stray sentence before the JSON, a trailing comma, or a fenced code block.

The strong version is schema enforcement offered by the API itself.

You supply a JSON Schema and the decoder is constrained to tokens that keep the output valid.

Invalid JSON then becomes impossible rather than unlikely.

Field names carry meaning, so calling a field urgency_score guides what goes in it.

Adding a short description to each field improves the values noticeably.

Enumerations are better than free strings whenever the set of answers is known.

Ask for a reasoning field before the answer field if you want the reasoning to help.

Order matters, since a field generated after the answer cannot have influenced it.

Always validate on your side anyway, because a schema constrains shape and not sense.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
Why are enforced JSON schemas better than asking the model politely for JSON?
Prompt Engineering

17 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close