Output Formatting

Why Output Format Matters

Without a format instruction, LLMs default to flowing prose. For conversational use that is fine. For a production system where the output feeds into code, a database, or a UI component, unstructured prose is unusable.

The Opportunity

Format instructions are one of the most reliable types of prompt instruction — models follow explicit format requests very consistently. This makes output formatting one of the highest-value areas to specify carefully in any non-conversational prompt.

Common Output Formats

01

JSON — the standard format for programmatic output; use when the output will be parsed by code, stored in a database, or consumed by an API

02

Markdown table — use for comparisons, feature lists, or structured data that will be rendered in a UI or documentation tool

03

Numbered list — use for steps, rankings, or any output where order matters

04

Bullet points — use for unordered collections of items, key takeaways, or scannable summaries

05

Code block — use when the output is code, a command, a config file, or any technical syntax that should be rendered verbatim

06

Plain prose — use when the output will be displayed as natural text, read by a human, or used in a document context

How to Specify Format

Be explicit. Do not assume the model will infer the format you want from context.

Weak format instruction

"Give me the product information."

Format is unspecified. The model will produce prose, a list, or a table — whichever it predicts is most likely from context. Output will vary.

Strong format instruction

"Return a JSON object with exactly these keys: product_name (string), price (number), in_stock (boolean)."

Format type, field names, and field types are all specified. Output is predictable and parseable.

What to Specify
  • Format type — JSON, list, table, prose, code block
  • Exact structure — field names and types for JSON; column names for tables
  • What to include — only the fields or sections you actually need
  • What to omit — explicitly suppress explanation, preamble, or metadata you do not want

Telling the Model What Not to Output

Often as important as specifying format: telling the model what to leave out. Models add explanation by default. Suppressing it when you do not need it keeps output clean and consistent.

01

"Return only the corrected code. Do not explain the changes." — strips prose explanation from a code output

02

"Return only the JSON object. No preamble, no explanation." — prevents the model from narrating what it's about to do before outputting

03

"Give the answer only. Do not repeat the question." — common for systems where question repetition wastes tokens and clutters output

04

"Do not include any commentary outside the JSON." — ensures a parser can read the output without stripping prose around the structured data

Format in Production Pipelines

Why Consistency Is a Hard Requirement

In production systems where model output is parsed by code, format inconsistency breaks the pipeline. A response that is sometimes JSON and sometimes a prose explanation will cause a JSON parser to throw an error. Reliability is a first-class concern, not a nice-to-have.

01

Use few-shot examples — show the model the exact format you want with 2–3 demonstrations before the actual task

02

Specify field names and types explicitly — ambiguous fields invite the model to invent its own schema

03

Suppress everything else — "Return only the JSON. Nothing else." is not redundant; it significantly improves consistency

04

Validate the output in code — always verify that the output parses correctly before using it; never trust a single prompt instruction to guarantee format in every case

When Format Instructions Break Down

Common Failure Modes and Fixes

Model explains the format instead of using it — add "Return ONLY the [format]. Do not describe what you are returning."

Format drifts in long outputs — the model loses the constraint partway through; add a few-shot example that demonstrates the full format across a similarly long output.

Model adds text before or after the structured output — add "Your entire response must be only the JSON object, with no text before or after it."

Summary

Key Takeaways
  • LLMs default to prose without format instructions; explicit format instructions are highly reliable
  • Common formats: JSON (code), markdown tables (comparisons), numbered lists, bullets, code blocks, prose
  • Strong format instructions specify the format type, exact structure, and what to omit
  • Telling the model what NOT to output is often as important as specifying what to produce
  • In production pipelines, combine format instructions, few-shot examples, suppression, and output validation
  • When format fails, add a demonstration example or add "Return ONLY the [format], nothing else"

Need Help?

Ask the AI if you need help understanding output formatting, how to write format instructions for JSON or tables, how to suppress unwanted prose in model output, or how to ensure format consistency in a production pipeline.