Output format instruction

Also known as: format specification

On this page 7

An output format instruction, also called a format specification, is the part of a prompt that tells a language model how to structure its response: which format to use, which fields to include, in what order, at what length and with what delimiters. In prompting for artificial intelligence systems, it separates what the model should say from how the answer must look.

Format instructions matter most when a program, not a person, reads the output. A parser expecting JSON fails on a friendly preamble, and a dashboard expecting three bullet points breaks on five. A precise format specification turns free text into predictable, machine-readable output.

How an output format instruction shapes model responses

An output format instruction works by conditioning the next-token probabilities toward a recognizable structure. Language models have seen enormous amounts of JSON, Markdown, CSV and XML during training, so naming a format and showing its shape makes tokens that fit that structure far more likely than conversational prose.

Effective instructions usually combine several elements. The table below lists the components that practitioners specify and what each one controls.

ComponentWhat it controlsExample wording
Format typeOverall syntaxReturn valid JSON only
Schema or fieldsRequired keys and their typesKeys: title (string), score (integer 1-5)
OrderingSequence of partsAnswer first, then the reasoning
Length limitsSize of each partAt most three bullet points of 15 words
DelimitersBoundaries for extractionWrap the final answer in answer tags
ExclusionsWhat must not appearNo preamble, no closing remarks
Fallback valueBehavior when data is missingUse null when a field is unknown
Components of a complete format specification

Instructions placed near the end of the prompt, close to where generation begins, tend to be followed more reliably in long prompts, because recent tokens strongly influence what comes next. Many teams state the format once in the system message and repeat it briefly after the user content.

Common output formats and when to choose them

The right format depends on who or what consumes the output. Structured formats suit software pipelines, while lightly structured formats suit human readers who still benefit from consistency.

FormatBest consumerStrengthTypical failure
JSONApplication code and APIsDirect parsing into objectsTrailing commas, unescaped quotes
XML-style tagsExtraction scriptsClear section boundariesMissing closing tag
Markdown tableHuman readersEasy comparisonMisaligned column counts
CSVSpreadsheets and data toolsCompact rowsCommas inside values
Numbered listPeople following stepsClear sequenceMerged or skipped steps
Fixed templateReports and formsConsistent layoutPlaceholder text left in place
Typical formats requested in output format instructions

When the consumer is code, JSON with an explicit schema is the usual default. For long documents with several parts, XML-style delimiters are often more robust than JSON, because the model does not need to escape quotation marks or line breaks inside free text.

An output format instruction is one of several ways to control response structure, and it is often combined with neighboring techniques in the Prompting topic. The comparison below shows how they differ in mechanism and strength of guarantee.

TechniqueMechanismStrength of guarantee
Output format instructionNatural-language description of the formatProbabilistic, usually high
One-shot or few-shot exampleDemonstrates the exact shapeHigher, but examples may be copied too closely
Prompt templateReusable prompt with slotsDepends on the instruction inside it
Response prefillingStarts the answer with an opening brace or tagHigh for the first tokens
Structured outputs or JSON modeDecoder constrained to a schemaNear deterministic validity
Function or tool callingArguments generated against a declared schemaHigh, enforced by the API
Ways to control the structure of model output

The key distinction is between asking and enforcing. A format instruction asks the model to comply; constrained decoding makes invalid tokens impossible. Even with enforcement, the instruction still matters, because a schema guarantees valid syntax but not sensible field content.

Writing reliable format specifications

Reliable format instructions are specific, consistent and testable. Vague wording such as “keep it structured” leaves the model to guess, while an explicit schema with types and allowed values removes ambiguity.

  • Show the exact shape with a short skeleton or one complete example, using realistic values rather than placeholders.
  • Define every field with its type, unit and allowed range, for example a confidence score from 0 to 1.
  • State the edge cases: what to output when information is missing, ambiguous or out of scope.
  • Forbid surrounding prose explicitly when code will parse the response.
  • Keep instructions consistent: a prompt that says “use bullets” in one place and shows a table elsewhere invites mixed output.
  • Validate every response in code and retry or repair when parsing fails.

Reasoning and formatting can conflict. Forcing a model to emit only a short JSON object may suppress useful intermediate reasoning, so many designs include a dedicated reasoning field placed before the final answer field.

Failure modes of output format instructions

Format instructions fail in recognizable patterns, and most of them can be traced to ambiguity, competing instructions or excessive output length. The table pairs common symptoms with their usual causes and fixes.

SymptomLikely causeFix
Preamble before JSONConversational habit of chat modelsPrefill the opening brace or forbid preamble
Invented extra fieldsSchema not marked as closedState that no other keys are allowed
Truncated outputToken limit reached mid-structureRaise the limit or shorten fields
Format drift in long sessionsInstruction buried far back in contextRepeat the format near the end
Wrong value typesTypes not specifiedGive types and an example value
Symptoms, causes and fixes for format failures

A subtler risk is that strict formatting can reduce answer quality on complex tasks, because the model spends capacity on syntax. Measuring accuracy with and without the format constraint, as part of prompt evaluation, shows whether the trade-off is acceptable.

The idea in brief

Asking a model a question is like asking a colleague for information. An output format instruction is the part where you also say how you want the answer handed back: as a filled-in form, a short list or a table, rather than a loose paragraph.

This matters because answers are often read by software, and software needs everything in the same place every time. A clear format instruction is the difference between a reply someone must retype and one that drops straight into the next step.

A practical scenario

A customer support team uses a language model to sort about 3,000 incoming emails per day. The first prompt simply asked the model to classify each message, and the replies varied: some gave a category name, some wrote a paragraph, and the routing script failed on roughly 8 percent of messages.

The team rewrote the prompt with an explicit output format instruction: return a JSON object with the keys category (one of six listed values), urgency (an integer from 1 to 3) and summary (at most 25 words), with no other text. They added one worked example and a rule to use “other” when no category fits.

After the change, parsing failures dropped to well under 1 percent, and the remaining cases were caught by a validator that retried the request once. Agents now see a consistent summary and urgency level for every ticket.