Structured Output
Definition
A model capability that constrains generation to match a specific schema — JSON, XML, or custom format — rather than freeform text. Structured output ensures that model responses are machine-parseable, type-safe, and schema-compliant. Implementations include: JSON mode (constrain to valid JSON), schema mode (constrain to a specific JSON schema), and grammar-based decoding (constrain to a formal grammar). Structured output is essential for agents because every tool call, database write, and API interaction requires predictable data formats.
Builder Context
Always use structured output for agent tool calls and data extraction. The reliability gap between 'ask the model to output JSON' and 'constrain the model to output JSON matching this schema' is enormous in production. Use response_format with json_schema for OpenAI, tool_use for Anthropic, or response_mime_type for Gemini. For complex schemas, break them into smaller sub-schemas and compose — models struggle with deeply nested schemas (>3 levels).