Step by Step
A
Ask explicitly — specify the exact format needed
Explicitly telling the model exactly what format to return (JSON, XML, Markdown, numbered list, table) dramatically improves the reliability of getting that format back.
Example: explicitly asking "Return ONLY this JSON: {name: string, date: string, amount: number, category: string}" rather than vaguely asking for "the information."
O
OpenAI Structured Outputs — API-level schema enforcement
OpenAI's Structured Outputs feature (2024) lets developers define a JSON schema, with the model guaranteed to return valid JSON conforming to that schema via constrained decoding at the API level.
Example: defining a strict JSON schema through OpenAI's Structured Outputs API and being guaranteed the model's response will conform to that exact schema, rather than hoping the model follows format instructions correctly.
X
Anthropic XML tags — organizing long structured outputs
Anthropic's models respond particularly well to XML tags for organizing long, structured outputs, providing a reliable way to demarcate different sections of a complex response.
Example: using XML tags like and to clearly organize distinct sections of a long, structured response from Claude.
V
Validate anyway — even reliable models occasionally fail
Even with reliable models and well-specified format instructions, occasional invalid JSON or malformed output can still happen, meaning output should always be validated programmatically rather than trusted blindly.
Example: a production system always running a JSON validation check on an LLM's output before using it downstream, even when using a highly reliable model and clear formatting instructions.
Applied Walkthrough
1
A developer builds a system that asks an LLM to extract structured data (name, date, amount, category) from unstructured text and return it as JSON.
2
They explicitly specify the exact JSON schema they want in the prompt, dramatically improving the reliability of getting correctly formatted JSON back compared to a vague request.
3
For even stronger guarantees, they could use OpenAI's Structured Outputs feature, which enforces the JSON schema at the API level via constrained decoding, rather than relying purely on the model following instructions.
4
Despite these strong reliability measures, the developer still includes a validation step in their production pipeline, since even reliable models and API-level enforcement can occasionally still produce unexpected or malformed output that needs to be caught before use.
Exam Application
Exams test whether you understand that explicit format instructions dramatically improve structured output reliability, whether you know OpenAI's Structured Outputs feature provides API-level schema enforcement (not just instruction-following), and whether you understand that validation remains necessary even with these strong reliability measures.
⚠ Common Trap
The most common trap is assuming a reliable model or a strong feature like OpenAI's Structured Outputs eliminates the need for validation entirely. Even with these strong reliability measures, occasional invalid or unexpected output can still occur, which is why programmatic validation remains a necessary safety net in production systems.
✓ Quick Self-Check
1. Why does explicitly specifying the desired output format improve reliability?
Because it gives the model a much clearer pattern to follow, rather than leaving the format ambiguous or open to interpretation.
Tap to reveal / hide
2. What does OpenAI's Structured Outputs feature guarantee, and how?
Valid JSON conforming to a defined schema, guaranteed via constrained decoding enforced at the API level.
Tap to reveal / hide
3. What do Anthropic's models respond particularly well to for organizing long outputs?
XML tags.
Tap to reveal / hide
4. Should you skip validating LLM output if you're using a reliable model with clear format instructions?
No — always validate output, since even reliable models can occasionally still produce invalid or malformed output.
Tap to reveal / hide
5. What year was OpenAI's Structured Outputs feature introduced?
2024.
Tap to reveal / hide