LESSON · 1 OF 4

Why structured output

Why structured output

So far you've read the model's replies with your own eyes. A paragraph of prose is fine for a person to read, but the moment you want a program to use the answer, prose gets in the way. Code can't reliably pull a name out of a sentence like "Sure! The customer seems to be Priya and her email is priya@acme.io." A friendly wrapper, a stray "Sure!", a reworded reply the next time you run it - any of these breaks code that expects the value in a fixed place.

What code wants instead is a predictable shape: the same fields, in the same place, every time. That shape is JSON.

Prose versus a parseable object

Ask a model to pull the contact details out of a message and it might answer:

text
The name is Priya Nair and the email is priya@acme.io. She's asking about billing.

Readable, but to get the email your code has to guess where it sits in the sentence. Ask for the same thing as JSON and you get:

json
{"name": "Priya Nair", "email": "priya@acme.io", "topic": "billing"}

Now the email is always at the email field. Your program reads it by name, not by scanning words. Run it a hundred times and the field is always there.

Where this shows up

Any time an LLM sits inside a larger system, its output feeds the next step: routing a support ticket to the right queue, filling a row in a database, deciding which function to call. Every one of those steps needs values it can look up by name, not a paragraph to interpret. JSON is the common language for passing data between programs, so a model that speaks JSON drops straight into code you already write.

Next: how to actually get JSON out of a model, and why you have to ask firmly.


Your lab setup

This VM comes preconfigured with your AI keys - just type claude to get started. Your key and URL are already set as $OPENAI_BASE_URL and $OPENAI_API_KEY.

Spin up a fresh environment and practice live.
linux-basic-ai · fresh machine · ready in under a minute