How to get AI to consistently output structured data — JSON, CSV, markdown tables, and custom formats. Techniques for reliable, parseable AI output.
One of the most practical prompt engineering skills is getting AI to output data in a specific, parseable format. Whether you need JSON for an API, a table for a report, or structured text for processing, here's how to get it right every time.
AI models are text generators. They'll output any format — but only if you show them exactly what you want. The key is: specify the format AND provide an example.
Extract the following information from this text and return it
as a JSON object with these exact keys:
"name", "email", "company", "role"
Text: "Hi, I'm Sarah Chen from Acme Corp. I'm the VP of Engineering.
Reach me at sarah@acme.com"
Return a JSON object matching this exact schema:
{
"name": "string (full name)",
"email": "string (email address)",
"company": "string (company name)",
"role": "string (job title)",
"seniority": "junior | mid | senior | executive"
}
Do NOT include any text outside the JSON.
Start with { and end with }.
Example input: "John Doe, CTO at TechCo, john@techco.io"
Example output: {"name": "John Doe", "email": "john@techco.io",
"company": "TechCo", "role": "CTO", "seniority": "executive"}
Now process: "Sarah Chen, VP Engineering, Acme Corp, sarah@acme.com"
Create a comparison table with these exact columns:
| Feature | Tool A | Tool B | Tool C |
Include rows for: pricing, free tier, API access, support level.
Use ✅, ❌, or specific values in each cell.
Output the data in CSV format with headers.
Use double quotes around fields containing commas.
Do not include any explanation — just the raw CSV data.
Headers: name,email,company,role,location
"Return ONLY the JSON. No explanations, no markdown code fences, no additional text."
"Place the structured data between these delimiters:
[your JSON here]
"
"Begin your response with { " — this forces JSON mode in most models.
"Do NOT format it like this: 'The answer is: [data]' DO format it like this: [data]"
List exactly 5 action items. Format each as:
1. [ACTION VERB] [specific task] — [expected outcome]
For each finding, use this format:
- **Finding**: [what you found]
- **Impact**: [who/what is affected]
- **Priority**: HIGH / MEDIUM / LOW
- **Action**: [recommended next step]
In the API, set response_format: { type: "json_object" }. This forces valid JSON output. You still need to describe the schema in your prompt.
Claude responds well to XML-style structure:
Return your analysis in this format:
<analysis>
<summary>Brief overview</summary>
<findings>
<finding severity="high">Description</finding>
</findings>
<recommendation>What to do next</recommendation>
</analysis>
Both OpenAI and Anthropic now support structured output schemas in their APIs. If you're building an application, use these instead of prompt-based formatting.
| Problem | Solution |
|---|---|
| AI adds explanation before/after data | "Return ONLY the [format]. No other text." |
| JSON has trailing commas | Provide a valid example; use JSON mode API |
| Table columns misalign | Specify exact column names and provide one example row |
| Inconsistent key names | Use camelCase OR snake_case in your example — pick one |
| Missing fields | "If a field is unknown, use null (not empty string)" |
| Extra fields added | "Include ONLY these keys: ..." |
Structured output transforms AI from a conversation partner into a data processing tool. Master it, and you can automate workflows that would otherwise require manual formatting.
Sign in to join the discussion.
No comments yet. Share your thoughts on this article.