Structured Output: Getting JSON You Can Use

Structured Output

Part of: Prompt Engineering

A model that replies "Sure! The customer seems happy, sentiment is positive" is useless to your code. Your program can't reliably pull "positive" out of that sentence. What you want is {"sentiment": "positive"}, clean, parseable, predictable. Getting that consistently is structured output , and it's where prompt engineering stops being a chat trick and becomes real software engineering. What it is Structured output is model output in a fixed, machine-readable shape, almost always JSON : that your code can parse with one line instead of fragile string-hunting. Instead of a sentence, you get {"name": "Maria", "age": 34}: defined keys, predictable types, no surprises. Why plain prose breaks your code When a model answers in free-form text, every response is shaped a little differently. "She is 34" one time, "Maria, age thirty-four" the next. Parsing that means brittle string-hunting that falls apart the moment the phrasing shifts. Structured output flips this: you tell the model the exact shape you want, and you get back something json.loads() can swallow every time. How it works: asking for JSON The simplest approach is to just demand it clearly, ideally with an example of the shape:

Challenge: Validate the Structured Output