TechniquesGlossary
Structured Output
Structured output turns LLM generation into an API you can actually call from code. Modern providers (OpenAI, Anthropic, Google) all support some form of schema-guided decoding where the model is literally prevented from emitting tokens that would violate the schema.
Two modes: JSON mode (guarantees valid JSON but not your specific schema) and schema mode (guarantees your exact JSON Schema). Use schema mode whenever you have a concrete shape; JSON mode is a weaker fallback.
Example
Extract event information as JSON matching this schema:
{
"type": "object",
"properties": {
"title": {"type": "string"},
"start": {"type": "string", "format": "date-time"},
"end": {"type": "string", "format": "date-time"},
"location": {"type": "string"}
},
"required": ["title", "start"]
}
Text: "Team standup tomorrow at 9am for 30 minutes in the Oak conference room."When to use it
- You're calling the model from code that parses the output
- Output drives downstream actions (DB writes, API calls)
- You need consistent fields across many invocations
- Human review isn't in the loop for every response
When not to use it
- Output is meant to be read by humans as prose
- The schema would be so complex it limits the model's expressiveness
- The task is genuinely unstructured (creative writing, exploration)
Articles that use this
- Grounding Prompts With Retrieved Context: The RAG Prompt Patterns That Stop Invented AnswersTechniques
- Adaptive Few-Shot Prompting: Use Semantic Retrieval to Pick Your Examples Instead of Hardcoding ThemTechniques
- XML vs Markdown Prompts: How to Format One Prompt for Claude, GPT and GeminiTechniques
- How to Prompt Reasoning Models: OpenAI's Seven-Part Prompt Structure, ExplainedTechniques
- Reasoning Effort: How to Set Thinking Depth Instead of Writing "Think Step by Step"Techniques

