Summary
Structured Output prompting ensures LLM responses conform to predefined schemas or formats. By specifying output structures (JSON, XML, specific formats), outputs become machine-readable and directly usable in downstream systems. This technique reduces parsing errors and enables reliable integration with APIs and databases.
Common formats
- JSON: API responses, data structures
- Markdown: Documentation, formatted text
- Tables: Tabular data presentation
- Code blocks: Programming language output
Implementation approaches
- Explicit instruction: Describe format in natural language
- Schema specification: Provide JSON schema or type definition
- Few-shot examples: Show desired output format
- Constrained decoding: Use API-level format controls
Validation checklist
- Schema matches actual output
- Required fields are present
- Type constraints are respected
- Edge cases are handled
- Error recovery is planned