Structured Output Patterns#
Agents need structured data from LLMs – not free-form text with JSON somewhere inside it. When an agent asks a model to classify a bug as critical/medium/low and gets back a paragraph explaining the classification, the agent cannot act on it programmatically. Structured output is the bridge between LLM reasoning and deterministic code.
Three Approaches#
JSON Mode#
The simplest approach. Tell the API to return valid JSON and describe the shape you want in the prompt.