Structured output is the practice of getting AI to return data in a predictable, machine-readable format like JSON instead of free-form text. This makes AI responses easy to parse, validate, and use programmatically — essential for building applications where AI output feeds directly into your code.
Structured output turns AI from a text generator into a data generator. When your application needs to use AI responses programmatically, structured output is essential.
| Free-Form Text | Structured Output |
|---|---|
| "There are 3 items..." | {"count": 3, "items": [...]} |
| Hard to parse reliably | Easy to parse |
| May vary between calls | Consistent format |
| Human-readable | Machine and human readable |
"Return your response as JSON with these fields: title, summary, tags"
const schema = z.object({
title: z.string(),
summary: z.string(),
tags: z.array(z.string()),
})
Modern AI SDKs support structured output natively, ensuring the response always matches your schema.