Interactive eBook BuilderInteractive eBook Builder
$59 · unlimited access, unlimited eBooksGet it for $59

· Updated · By · 6 min read

How to Make Claude Follow a Strict Output Format

aipromptsclaudeworkflow

To make Claude follow a strict output format, define the format with labeled tags, show one filled-in example, state the format as something to do (not only something to avoid), forbid preamble, and then validate the result with a checklist or a small script. Formatting rules are the easiest to test, so treat them as testable.

This guide is written for authors working in Claude chat or with a project, with notes for developers using the API. It's based on Anthropic's prompting documentation as of November 2026; model behavior and features change, so check the current docs.

What does Anthropic recommend for formatting control?

Three techniques: say what to do, use XML-style indicators, and match your prompt's style to the desired output. The documentation lists them as particularly effective ways to steer formatting:

TechniqueFrom the docsFor chapter work
Positive instructionInstead of "Do not use markdown", say "Your response should be composed of smoothly flowing prose paragraphs.""Output plain paragraphs under the heading tags I give"
XML indicatorsWrite the prose sections inside named tagsAsk for the draft inside body tags
Style matchingThe formatting style of your prompt influences the response; removing markdown from the prompt can reduce markdown in outputWrite your own prompt in the style you want back
ExamplesExamples are "one of the most reliable ways" to steer format, tone and structure; include 3-5One or two filled-in chapters

For general advice on rules that get ignored, see why AI ignores instructions. This post focuses on the output shape.

How do I define the format?

Spell out each part, its limits and the order, then show it once. Vague formats ("give me a nice chapter layout") can't be validated. Specific ones can:

Return the chapter in exactly this structure and nothing else:

<title>[chapter title, max 8 words]</title>
<summary>[one paragraph, 30-40 words]</summary>
<body>
[550-650 words of plain paragraphs with H2 lines marked as "## Heading"]
</body>
<action>[one 5-minute exercise, one sentence]</action>

Start your response with <title>. Do not write anything before or after the tags.

Notice the last line states the rule positively (start with the title tag) and adds the "no preamble" rule. If your own instructions are written in clean prose, Claude tends to answer in clean prose too, which is the style-matching effect. For the full picture of how examples and tags work together, see reusing a prompt across ChatGPT, Claude and Gemini, where the tag approach is also the part most likely to transfer.

How do I stop preambles like "Here is your chapter"?

Tell the model to start with the first tag and add no commentary. Developers used to solve this by prefilling the start of the response. Anthropic's documentation says that starting with the Claude 4.6 models, prefilled responses on the last assistant turn are no longer supported and return a 400 error. Its suggested migration for preamble is a direct instruction (for example, "Respond directly without preamble"), output within XML tags, structured outputs or tool calling, and, if the odd preamble still slips through, stripping it in post-processing. Authors in chat have a simpler version: add the line, and delete the stray sentence if it appears.

For API users who need exact data shapes, the docs point to a structured outputs feature that constrains responses to a given schema, and note that newer models can often match complex schemas when asked, especially with retries.

Will strict formats make the writing worse?

They can, if you constrain the thinking and the writing at once. A study titled "Let Me Speak Freely?" (Tam et al., 2024) found that format restrictions such as JSON or XML caused a significant decline in LLMs' reasoning, with stricter constraints causing bigger drops. That research concerned reasoning tasks, not chapter drafting, but the lesson transfers in spirit: don't ask for creative or analytical work and a rigid format in one step if quality matters. A safe pattern (my suggestion): let the model write the section in free prose, then ask a second step to place it into the template. This is the chain pattern from prompting Gemini vs Claude for long-form writing.

How do I check the output automatically?

Write the format as rules you can test, then test them. Here's a tiny checker I wrote for the chapter format above, run on two made-up outputs. The script checks that each tag appears exactly once, the summary is at most 40 words, the body is 550-650 words, and nothing precedes the title.

SampleResult from the script
"good" (30-word summary, 600-word body, all four tags)OK
"bad" (preamble line, 55-word summary, 480-word body, no action tag)expected exactly one <action> block; summary over 40 words; body is 480 words, want 550-650; text before <title>

The point isn't the script; it's that vague formatting wishes become four pass/fail checks. When a check fails, paste the error list back to Claude: "Fix only these problems." The same idea works as a manual checklist when you don't code. Wherever the check lives, keep it separate from the writing step. In Interactive eBook Builder, for example, the Packs Database holds QA/Gate items and Agent C Polisher runs a final QA pass, so a format check is a recurring gate rather than a thing you remember at 11 pm.

Which formats are easiest to keep strict?

The simpler and more mechanical the structure, the easier it is to enforce. This ranking is my own judgment, based on how easily each can be verified:

Format elementEase of enforcingHow to check
Named tags in a fixed orderHighSearch for each tag
Field labels ("Title:", "Summary:")HighSearch for each label
Numbered list of N itemsMedium-highCount the items
Word or sentence limitsMediumWord counter; models often miss exact counts
Tone ("warm but crisp")LowRead it; use samples

Choose the checkable elements for hard requirements, and use samples rather than strict wording for soft ones like tone. Word limits deserve a range ("550-650 words") instead of a single number, since an exact figure is a coin flip. If you publish a series, freeze the format as a template you reuse, the same way the Configuration Hub in Interactive eBook Builder keeps a book's settings together, so Chapter 12 is built from the same spec as Chapter 1.

Before you hit send

The takeaway: strict formatting is a spec plus a test. Describe the structure with tags and one example, say what to do, and check every output before you trust it.

FAQ

Does Claude support a strict JSON or schema output?

Anthropic's API offers a structured outputs feature designed to constrain responses to a schema. In ordinary chat, you rely on clear instructions, tags and examples, and you validate the result.

How do I stop Claude from adding "Here is your chapter"?

Tell it directly: respond without preamble, start with the first tag, and don't add commentary. Anthropic's docs suggest a direct system-prompt instruction, output within XML tags, or structured outputs, plus trimming leftover preamble in post-processing.

What are XML tags for?

They label parts of the prompt or output, such as title and body, so the model and you can tell them apart. Use consistent names and mention them in your instructions.

Do I need to code to validate the format?

No. A manual checklist works for a few chapters. A tiny script saves time when you check many, as shown in the example below.

Ship niche eBooks with agents already built.

Get the Interactive eBook Builder for $59