Output Formatting
Platforms:
claudeopenaigeminim365-copilot
What It Is
Section titled “What It Is”Output formatting means telling the model exactly how to structure its response — whether that’s a table, JSON, bullet list, specific sections, or a template you define. Instead of hoping the model picks a useful format, you specify it upfront. This makes outputs immediately usable without manual reformatting.
Why It Works
Section titled “Why It Works”LLMs (large language models) are very good at following structural instructions because they’ve seen millions of formatted documents during training. Specifying format reduces ambiguity about what “a good response” looks like, and makes outputs immediately usable in downstream workflows. However, note that format restrictions can sometimes degrade reasoning performance — Tam et al. (2024) found a tradeoff between structure and thinking quality. For complex analysis, consider letting the model reason freely first, then reformatting.
When to Use It
Section titled “When to Use It”- Output needs to feed into another system (JSON, CSV, XML)
- Reports or analyses that need consistent structure across runs
- Comparing multiple items side-by-side (tables)
- When you’ll reuse the same prompt and need predictable output
- When output will be parsed programmatically
The Pattern
Section titled “The Pattern”{Task description}
Format your response as:{Format specification — template, example structure, or explicit format name}Filled-in example:
Summarize the three main risks of migrating our database from MySQL to PostgreSQL.
Format your response as a markdown table with these columns:| Risk | Likelihood (High/Med/Low) | Impact | Mitigation |Examples in Practice
Section titled “Examples in Practice”Example 1 — Table format
Section titled “Example 1 — Table format”Context: You need to compare tools and want a scannable side-by-side view.
Compare the following 4 project management tools on these dimensions: price, team sizelimit, integrations, and learning curve. Tools: Asana, Linear, Monday.com, Notion.
Present as a markdown table with tools as columns and dimensions as rows.Why this works: Tables make comparisons scannable, and specifying rows vs. columns removes ambiguity about the layout.
Example 2 — JSON output
Section titled “Example 2 — JSON output”Context: You’re extracting structured data from unstructured text for use in an application.
Extract the following fields from this job posting: title, company, location,salary_range, required_skills (as an array), experience_years.
Return as valid JSON with no additional text or explanation.
Job posting:[paste job posting text here]Why this works: The schema is fully specified — field names, types (array for skills), and the instruction to return only JSON ensures clean, parseable output.
Example 3 — Template-based
Section titled “Example 3 — Template-based”Context: You want a consistent format for a recurring report.
Write a weekly status update following this exact structure:
## Completed This Week- [bullet items]
## In Progress- [bullet items with % complete]
## Blocked- [bullet items with blocker description]
## Next Week- [planned items]
Here's what happened this week: shipped the auth module, 60% done with the dashboardredesign, waiting on API credentials from the vendor, and next week we start load testing.Why this works: The exact template is provided, so the model fills in the structure rather than inventing its own — ensuring consistency across weeks.
Common Pitfalls
Section titled “Common Pitfalls”Related Techniques
Section titled “Related Techniques”- Direct Instruction — be explicit about what you want the model to do
- Few-Shot Learning — show format by example
- Summarization and Distillation — formatting is especially important for summaries
- Prompt Engineering Overview
- Data Analysis use case — structured output is critical for data workflows
Further Reading
Section titled “Further Reading”- Tam et al. 2024 — Let Me Speak Freely? A Study on the Impact of Format Restrictions on Performance — arxiv.org/abs/2408.02442
- Liu et al. 2024 — “We Need Structured Output”: Towards User-centered Constraints on LLM Output — arxiv.org/abs/2404.07362