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:
| Technique | From the docs | For chapter work |
|---|---|---|
| Positive instruction | Instead 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 indicators | Write the prose sections inside named tags | Ask for the draft inside body tags |
| Style matching | The formatting style of your prompt influences the response; removing markdown from the prompt can reduce markdown in output | Write your own prompt in the style you want back |
| Examples | Examples are "one of the most reliable ways" to steer format, tone and structure; include 3-5 | One 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.
| Sample | Result 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 element | Ease of enforcing | How to check |
|---|---|---|
| Named tags in a fixed order | High | Search for each tag |
| Field labels ("Title:", "Summary:") | High | Search for each label |
| Numbered list of N items | Medium-high | Count the items |
| Word or sentence limits | Medium | Word counter; models often miss exact counts |
| Tone ("warm but crisp") | Low | Read 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
- Is the format written as parts, limits and order, with one filled-in example?
- Does the prompt say to start with the first tag and add nothing else?
- Is your prompt itself written in the style you want back?
- Did you separate "think and write" from "fit into the template" for important text?
- Do you have a checklist or script to validate each output?
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.