To specify output format in an AI prompt: (1) decide who consumes the output, a person or a parser; (2) write the exact shape: fields and types, columns, or sections and length; (3) show one example of the finished output; (4) state the format before the task and repeat it at the end; (5) when code parses the result, enforce the schema with the provider's structured output API and validate it.
In our benchmark of 1,018 real prompts, the ones that declared an output format averaged 59.8 out of 100. The ones that didn't averaged 31.1. No other single habit we measured came close to that gap (State of Prompt Quality, 2026-Q3 edition).
You have probably seen the failure behind that number. You ask for a product list and get three paragraphs with the data scattered through the sentences. Run it again: a numbered list. Third run, bullets. Same prompt, three shapes, none of them the one your code expected.
This guide shows how to specify output format in AI prompts so the shape stops changing between runs, and what to do when a prompt instruction isn't enough. It was rewritten in September 2026 because the official APIs moved under our feet (details in the box below).
Written by Francisco Ferreira, who builds PromptEval. PromptEval is our product and appears in this guide; every technique below works no matter which tool you use to check it. Provider behavior was re-checked against each official guide on 22 September 2026.
- Claude has native JSON schema output. Structured Outputs is generally available and the beta
output_formatfield moved tooutput_config.format. Tool use is no longer the only route. - Prefilling Claude's reply is gone. From the Claude 4.6 models on, a prefilled last assistant turn returns a 400 error. Tutorials that still teach "start the answer with
{" break on current models. - OpenAI says prefer Structured Outputs over JSON mode whenever possible, and the Responses API takes the schema under
text.format. - Gemini's structured output guide now shows a
response_formatblock withmime_typeandschema.
Why the output format line is worth 29 points
An output format instruction is the part of a prompt that tells the model the shape of its answer: the container (JSON, table, list, prose), the fields or sections inside it, their order, and the length. It says nothing about the content. It removes one whole category of decisions the model would otherwise make on its own, differently on every run.
That is why format sits under the specificity dimension of a prompt. "Give me a summary" leaves length, container, detail level and headers open. The model resolves all four from whatever it saw most often in training for that kind of request, and small changes in the input tip it one way or the other.
Here is how format compares with the other habits we tracked across the 1,018 prompts in the Q3 dataset:
| HABIT IN THE PROMPT | AVG SCORE WITH | AVG SCORE WITHOUT | GAP | SHARE OF PROMPTS USING IT |
|---|---|---|---|---|
| Declares an output format | 59.8 | 31.1 | +29 | 79.2% |
| States constraints | 64.5 | 40.8 | +24 | 54.9% |
| Assigns a persona | 58.7 | 42.2 | +17 | 70.4% |
| Includes an example | 63.7 | 53.3 | +10 | 5.2% |
Source: PromptEval, State of Prompt Quality 2026-Q3 (CC BY 4.0). Scores are 0-100. Correlational: prompts people chose to submit, not a controlled test.
Two things stand out. One in five prompts still has no format line at all, and those sit in the bottom of the distribution. And almost nobody shows an example of the output they want (5.2%), even though an example is the most direct way to pin a format down. Step 3 below is about exactly that.
One honest limit on the table: people who write a format line probably write better prompts in general, so part of the 29 points belongs to the writer, not the sentence. The mechanism still holds on its own. Every open format decision is a place where two runs can disagree.
How to specify output format in 5 steps
- Pick the format from the consumer: JSON or a label for code, a table or Markdown for people.
- Write the exact shape: every field and type, every column, or the sections and length.
- Show one example of the finished output inside its own tags.
- State the format before the task and repeat a one-line reminder at the end.
- Enforce the schema in code with the provider's structured output API, then validate the values.
Step 1. Decide who consumes the output
Most format failures start here. People add "return as JSON" because it sounds rigorous, when the output goes straight into a chat window. Ask two questions: who reads it (a person or code), and what happens to it next.
| USE CASE | READER | BEST FORMAT | INSTRUCTION TO COPY |
|---|---|---|---|
| API response, downstream parsing | Code | JSON + schema | "Return only a JSON object: {name: string, score: number}." |
| Classification, routing | Code | One label from a fixed list | "Answer with exactly one of: billing, bug, feature_request, other." |
| Spreadsheet import | Person or code | CSV | "CSV with header row: name,price_usd,date. Quote fields that contain commas." |
| Comparison someone reads | Person | Markdown table | "Markdown table. Columns: Tool | Price | Best for. No intro paragraph." |
| Docs, reports, rendered UI | Person | Markdown with named elements | "Use ## for sections, - for bullets. Start with the first ## heading." |
| Text pulled out of a longer answer | Code | XML tags around the part you need | "Put the final email inside <email></email> tags." |
| Chat reply nobody copies | Person | Prose, with a length | "Two short paragraphs, plain text." |
Step 2. Write the shape, not an adjective
"Structured," "clean" and "well-organized" are not formats. A format names fields, types, columns or sections. Run "extract product details and return JSON" ten times and you'll get name, product_name, item and title for the same field. Valid JSON every time. Useless to a parser.
Extract the product details from this text and return JSON.
The model invents field names, types and nesting on every run.
Extract product details from the text inside <listing> tags. Return one JSON object with exactly these fields:
{"name": string, "price_usd": number, "features": string[], "in_stock": boolean}
If a value is missing from the text, use null. Return only the JSON object.
Field names, types and the missing-value rule are fixed. "Return only" stops the sentence of preamble that breaks json.loads().
Notice the missing-value rule. Without it the model has to invent something when the listing has no price, and invented prices are worse than a parse error. Deciding what happens on empty input is where format meets prompt robustness.
Same principle for human-facing formats. "Respond in Markdown" still lets the model mix heading levels and alternate dashes with asterisks. Name the elements: which heading level, which bullet character, what goes first.
Step 3. Show one example of the finished output
Anthropic's prompting guide calls examples "one of the most reliable ways" to steer Claude's output format, tone and structure. Our data agrees from the other side: only 5.2% of prompts include one, and those that do average 10 points higher.
A description tells the model the rules. An example shows it the rules already applied, including the details you forgot to describe (date format, capitalization, whether numbers carry units). Wrap it so it can't be mistaken for input:
{"name": "Aeron Chair", "price_usd": 1395, "features": ["adjustable arms", "mesh back"], "in_stock": true}
</example_output>
Match this shape exactly. Do not copy its values.
That last line matters. With a single example, models sometimes reuse its values or its length. If your outputs start looking like clones of the example, add a second one that differs in every value, or say which parts are placeholders.
Step 4. Put the format before the task and repeat it at the end
In a short prompt, placement barely matters. In a long one, it decides whether the format survives. OpenAI's GPT-4.1 prompting guide recommends a dedicated # Output Format section in its reference prompt structure, and for prompts with long context it says instructions placed at both the beginning and the end performed better than either position alone.
We call the pattern triple placement:
- System prompt: the standing rule and the full schema.
"You always answer with one JSON object matching this schema: {...}" - User turn, before the task:
"Return the JSON object described above. Task: extract..." - User turn, last line: a compressed reminder.
"JSON object only."
Keep the full schema in one place. Repeating a paraphrased version of it three times creates three slightly different specs, and the model will blend them. The reminders point back; they don't redefine.
Phrase the rule positively, too. Anthropic's guide gives the example directly: instead of "Do not use markdown in your response," try "Your response should be composed of smoothly flowing prose paragraphs." A prohibition tells the model what to avoid but not what to produce. The same guide notes that the style of your prompt leaks into the answer, so a prompt written in heavy Markdown tends to get Markdown back.
Check the format rules against the official guides before you wire up a parser. The Prompt Format Checker runs in your browser, needs no account, and marks each provider (GPT, Claude, Gemini) pass or fail with the documented rule and its source link.
Step 5. Enforce the schema in code when a parser depends on it
Prompt instructions ask the model to comply. Native structured output makes non-compliance impossible at generation time: the provider constrains decoding so only tokens that fit your schema can be produced. Use it once a format failure would break something silently, meaning no human looks at the output before your code does.
All three major providers now offer schema-constrained output. The parameter names are the part that keeps changing, so here they are as of this update.
What each provider's official guide says about output format
Short answer: all three say to be explicit about the format in the prompt, and all three offer a JSON schema parameter for when you need a guarantee. The differences are in the prompt-level advice and in the parameter names. Each row links to the primary source.
| PROVIDER | PROMPT-LEVEL ADVICE | NATIVE SCHEMA PARAMETER (SEP 2026) | WATCH OUT FOR |
|---|---|---|---|
| OpenAI prompting guide · structured outputs |
Dedicated "Output Format" section; Markdown headings recommended for sections; long context: instructions at start and end. | Responses API: text.format with type: "json_schema" and strict: trueChat Completions: response_format with type: "json_schema" |
Docs recommend Structured Outputs over JSON mode (JSON mode checks syntax, not your schema). Handle the refusal field. |
| Anthropic (Claude) prompting guide · structured outputs |
Say what to do instead of what not to do; XML format indicators; match prompt style to the output you want; use examples. | output_config.format with type: "json_schema" and your schemaTools: strict: true on the tool definition |
Prefill returns 400 from Claude 4.6 on. Schema subset: no minimum/maximum or minLength/maxLength, so check ranges in your validator. |
| Google (Gemini) structured output guide |
Use the schema's description fields to guide the model; strong types (integer, enum); state the task clearly. |
response_format with mime_type: "application/json" and a schemaOlder SDK code: response_mime_type + response_schema |
Only a subset of JSON Schema is supported; very large or deeply nested schemas can be rejected. Output is valid JSON, so validate the values yourself. |
Checked against each provider's documentation on 22 September 2026. These parameters have been renamed at least once in the past year; confirm against the linked page before copying into production code.
The prefill change deserves its own warning, because a lot of format advice still depends on it. For years the standard trick with Claude was to write the first character of its reply yourself, an opening {, so it had no choice but to continue in JSON. Anthropic's guide now lists this under "Migrating away from prefilled responses" and points format control to Structured Outputs. For stripping preambles, it suggests a direct instruction ("Respond directly without preamble") or asking for the answer inside XML tags.
If the same prompt has to run on more than one of these providers, format is usually the first thing that breaks in the move. Our guide to how to structure AI prompts covers the section layout that transfers best between them.
Schema details that decide whether parsing breaks
A schema that the API accepts can still produce outputs your application can't use. Four details cause most of the trouble we see:
A "status": string field comes back as "Open", "open" and "OPEN". "enum": ["open", "closed", "pending"] leaves one spelling. Add "other" so the model isn't forced into a wrong bucket.
OpenAI's docs suggest a reasoning field so the model can explain its logic before the final answer. List it first; a verdict written before the reasoning can't use it.
Mark every field required and set additionalProperties: false. Express "optional" as a nullable type so the key is always present and your code has one shape to handle.
Every key name is paid for in output tokens on every object. In an array of 200 rows, customer_full_legal_name costs you 200 times. See how to optimize prompt tokens.
Then validate, even with a guarantee. Structured output guarantees the shape, not the values: a price_usd of -40 is schema-valid. Define the model once in Pydantic (Python) or Zod (TypeScript), check it, and on failure send the validation error back for one retry:
from pydantic import BaseModel, Field, ValidationError
class Product(BaseModel):
name: str
price_usd: float | None = Field(default=None, ge=0)
features: list[str]
in_stock: bool
def parse_with_retry(raw: str, ask_model) -> Product:
try:
return Product.model_validate_json(raw)
except ValidationError as err:
# one retry, with the exact error, then fail loudly
fixed = ask_model(f"Your JSON failed validation:\n{err}\nReturn corrected JSON only.")
return Product.model_validate_json(fixed)
One retry catches most slips. If the second attempt also fails, raise and log it. A loop that retries until something parses hides a prompt problem you should fix upstream.
We learned this from our own pipeline. PromptEval's scoring call asks the model for JSON only, with the schema in the prompt, and our parser still carries three fallbacks: strip a Markdown code fence the model wrapped around the JSON, cut the text from the first { when a sentence of preamble slipped in, and close off an object that was truncated when the response hit its token limit. None of those failures is a schema problem, and a JSON schema alone wouldn't have caught the last one. Set max_tokens with room to spare for the largest object you expect. Repairing a truncated object keeps whatever arrived and drops the rest. That's a trade-off we chose; if every field matters to you, treat a truncated response as an error instead.
Format drift: when the model ignored your format
Format drift is when a model starts in the format you asked for and slides out of it: three clean JSON fields and then a sentence of explanation, or a table that turns into bullets halfway down. When we trace it back, it's almost always one of these five:
| SYMPTOM | LIKELY CAUSE | FIX |
|---|---|---|
| JSON followed by "Let me know if..." | A friendly system prompt competing with "JSON only" | Scope the conflict: "Be conversational in chat; for extraction tasks return JSON only." More in conflicting instructions in AI prompts. |
| Field names change between runs | Container named, schema missing | Step 2: name and type every field, add one example. |
| Right format on turn 1, prose by turn 7 | Instruction diluted by the conversation since | Restate a one-line reminder in any turn that needs structured output. |
| Still gets Markdown after "no markdown" | Negative-only instruction; a prompt written in Markdown | Say what to produce ("flowing prose paragraphs") and strip the Markdown from the prompt itself. |
| 400 error after a model upgrade | Prefilled assistant turn on Claude 4.6 or later | Move to output_config.format, or instruction plus XML tags. |
Temperature helps less than people expect. Lowering it makes a model more repeatable, including repeatably wrong when the spec is ambiguous. Fix the spec first, then tune temperature if you still see variance.
For a format that has to hold across edge-case inputs, test it on the ugly ones: an empty document, a listing in another language, a field that appears twice. The guide to testing and iterating prompts walks through building that small input set, and the PromptEval Playground (Basic and up, with your own API key) lets you run one prompt against Claude and GPT side by side to see which one drifts.
You've written the format line. Now see whether it moved the number: paste the prompt into PromptEval and read its specificity score next to clarity, structure and robustness. The free plan covers 3 evaluations a month. If you'd rather practice the habit than read about it, "Structured output format" is one of the named techniques in the Daily Training: one work scenario, one prompt from you, and an LLM judge scoring each criterion from 0 to 100. Today's drill needs no account.
Frequently Asked Questions
In the prompt: give the exact schema, show one example object, and say "return only the JSON" before and after the task. In code, when a parser depends on it, use native structured output: OpenAI Structured Outputs (json_schema with strict: true), Claude's output_config.format, or Gemini's response_format with mime_type: "application/json". Validate the values anyway and retry once with the error message.
Four causes cover most cases: the format line is far from where the answer starts; another instruction competes with it; it only says what not to do; or several turns have passed since you stated it. Give the format its own section, repeat it at the end, phrase it positively, and restate it in any turn that needs structured output.
JSON mode only guarantees syntactically valid JSON. Structured Outputs guarantees the JSON also matches your schema: right fields, right types, required keys present. OpenAI's documentation recommends Structured Outputs over JSON mode whenever the model supports it. Claude and Gemini offer the same schema-constrained behavior through their own parameters.
Not on current models. Anthropic's prompting guide says prefilled responses on the last assistant turn are no longer supported starting with the Claude 4.6 models, and those requests return a 400 error. Use Structured Outputs (output_config.format) instead, or a direct instruction plus XML tags around the part you want to extract.
In PromptEval's State of Prompt Quality 2026-Q3 report (1,018 prompts), prompts that declared an output format averaged 59.8 out of 100; prompts that didn't averaged 31.1. That 29-point gap was the largest of any single habit measured. It's a correlation across real submissions, not a controlled experiment, but the mechanism is simple: format is one decision the model no longer has to guess.