Output Formatting Techniques
Reliably extract structured data — JSON, tables, lists — from AI responses.
Why Output Format Matters
Unstructured AI output is unusable in automated pipelines. To build reliable systems, you need predictable output formats that can be parsed and processed downstream.
The good news: modern models are excellent at following format instructions when you give them explicitly.
Requesting JSON Output
Extract the following information from the text and return it as valid JSON.
Schema:
{
"company": string,
"revenue": number (in millions),
"employees": number,
"founded": number (year)
}
Text: "{paste text}"
Return only the JSON object. No explanation.
The "Return only the JSON object. No explanation." instruction is critical — without it, models wrap JSON in prose.
Markdown Structure
For human-readable structured output, specify markdown components:
Analyze the provided code. Format your response as:
## Summary
One paragraph overview.
## Issues Found
Bulleted list. Each item: [SEVERITY] Description
## Recommendations
Numbered list ordered by priority.
Extraction Chains
For complex extraction, chain multiple prompts:
- First prompt: extract raw data into a structured intermediate format
- Second prompt: transform and validate the intermediate format
This is more reliable than trying to do everything in one prompt.
Validation
Always validate AI-generated structured output before using it. Use Zod or similar schema validation:
const schema = z.object({
company: z.string(),
revenue: z.number(),
})
const validated = schema.parse(JSON.parse(aiOutput))
Never trust unvalidated AI output in production systems.