Structured Output
ELI5 — The Vibe Check
Structured output means getting the AI to respond in a specific format — like JSON or a filled-in form — instead of just freeform text. It's the difference between the AI writing a paragraph about a user and returning a clean JSON object with name, email, and role fields. It makes AI outputs machine-readable, so your code can actually USE the response without parsing poetry.
Real Talk
Structured output constrains LLM responses to follow a specific schema, typically JSON matching a predefined structure. Modern APIs support this via JSON mode, function calling schemas, or grammar-constrained generation. This ensures programmatic reliability — outputs can be parsed, validated, and consumed by downstream code without string manipulation or error-prone extraction.
Show Me The Code
// Structured output with OpenAI
const response = await openai.chat.completions.create({
model: "gpt-4o",
response_format: {
type: "json_schema",
json_schema: {
name: "user",
schema: {
type: "object",
properties: {
name: { type: "string" },
age: { type: "integer" },
role: { type: "string" }
}
}
}
},
messages: [{ role: "user", content: "Extract: John, 32, engineer" }]
});
When You'll Hear This
"Use structured output so we can parse the model's response reliably." / "Structured output eliminated all our JSON parsing errors."
Related Terms
API (Application Programming Interface)
An API is like a menu at a restaurant. The kitchen (server) can do a bunch of things, but you can only order what's on the menu.
Function Calling
Function Calling is the OpenAI term for what Anthropic calls Tool Use — teaching the AI to call your code functions.
Guardrails
Guardrails are the safety nets you put around AI applications — rules and checks that prevent the AI from going rogue.
Tool Use
Tool use is when an AI can call external functions, APIs, or programs to do things it can't do alone.