Index Ai Academy
Phase 1 · Building with LLMs · Prompting

Structured output

Get reliable JSON back that your code can use.

About 30 minutes · Free account required

Open this lesson Create a free account

Why it matters

Most LLM features that do real work end with code reading the model's answer: a lead gets added to the CRM, a review gets a tag, a product gets a category. That only works if every reply arrives in the exact shape your code expects. Structured output is how you get that guarantee. Validating what comes back is what keeps a well-formed but wrong answer from flowing into your systems.

What you'll be able to do

  • Explain why asking for JSON in the prompt isn't enough when code depends on the reply
  • Describe the data you want back as a JSON schema
  • Request schema-constrained output with `output_config.format` and parse the reply
  • Validate parsed data against business rules, and handle replies you can't use

Before this lesson

Next in this phase: Prompt chaining