What Are Structured Outputs?
Force an LLM to return a specific format (JSON/typed object) rather than free text. The key to building reliable AI pipelines.
TL;DR: Force LLMs to return valid JSON. OpenAI uses response_format, Claude uses tool_choice, Instructor wraps multiple providers, Outlines open-source guided generation.
Method Comparison
1. OpenAI Structured Outputs — Server-side schema enforcement
2. Claude Tool Use — Schema enforcement via tool calls
3. Instructor — Multi-provider wrapper with retries
4. Outlines — Token-level guided generation for open-source models
Best Practices
- Keep schemas simple
- Add field descriptions
- Provide few-shot examples
- Validate business logic