Claude prompting techniques: XML tags, examples, and prefill
Claude interprets a prompt better when you separate content types: wrap instructions, data, and examples in their own XML tags, and in long documents, place the lengthy material at the top and the question last — order measurably affects response quality. For repetitive tasks, 3 to 5 well-chosen examples teach the output pattern better than repeating the instruction. Without extended thinking, ask for explicit reasoning with tags like `<thinking>`; to force a format, use prefill by starting the assistant's response.
A well-written prompt isn't about picking the magic words — it's about removing structural ambiguity. This page covers the documented techniques that fix the most common problems: Claude confusing data with instructions, inconsistent answers, and a lack of explicit reasoning.
Why XML tags fix more than a paragraph asking for care
When a prompt mixes instruction, data, and examples in the same plain-text block, Claude has to guess which is which — and sometimes gets it wrong, treating a piece of data, like a comment inside a code diff, as if it were an instruction aimed at it.
The documented fix isn't reinforcing with more adverbs ("pay attention", "don't confuse") — it's wrapping each type of content in its own tag, like `
Multishot: examples teach the pattern better than a repeated instruction
For repetitive tasks — classifying, extracting, formatting — three to five well-chosen examples teach the output pattern in a way that rewriting the instruction can't. Claude generalizes from the pattern the examples show, not just from what the instruction sentence describes.
Position matters too: in long documents, the lengthy material goes at the top of the prompt and the question goes last. That's the order Anthropic's guidance measures as most reliable — reversing it, question first and document after, tends to make the answer worse, not better.
How to ask for explicit reasoning without extended thinking
Without extended thinking mode turned on, the documented way to still get step-by-step reasoning before the final answer is to ask for it explicitly in the prompt — for example, with a tag like `
To force a specific output format there's a complementary technique: prefill, which starts the assistant's response for you — for example, opening with `{` to push toward JSON. It works well on its own, but doesn't combine with extended thinking in the same request: the two techniques compete for the same space at the start of the response.
tool_choice and the limit of what a well-written prompt solves
When you need a specific tool to be called, without relying on the model "deciding" that from the description, the API's `tool_choice` parameter solves it deterministically — forcing a named tool, or at least forcing that some tool gets called, instead of leaving the decision to the prompt text alone.
It's the same principle as CLAUDE.md versus hooks, applied to prompting: well-written text raises the odds that the right behavior happens; a structured API parameter guarantees it.
When prompt wording isn't enough: structured outputs
Prefill helps start the response in the right format, but doesn't guarantee the rest of the response keeps following the schema to the end — that still depends on the prompt being well written. To guarantee the response always matches a schema exactly, there's structured outputs, which validates the structure programmatically instead of relying only on how the instruction is worded.
Even with structured outputs enabled, some responsibilities remain yours: the schema guarantees the format is correct, not that the values inside it make business sense. Validating the content is still the application's job, not the API's.
Try it yourself
A code-review platform's prompt concatenates a PR diff, the repo's style guide, and four example review comments into one large block of plain text. Reviewers report that Claude sometimes treats a code comment inside the diff (e.g., "// TODO: ignore lint rule here") as an instruction directed at it.
Which change most directly fixes this ambiguity, using standard Claude prompting technique?
Read next
- How Claude Code's agentic loop worksClaude Code runs on cycles of gathering context, acting, and verifying — not a fixed list of steps. See when delegating to subagents actually pays off.
- CLAUDE.md, hooks, and permissions: how Claude Code decides what it can doCLAUDE.md shapes Claude Code's behavior; permissions and hooks decide what it can actually execute. Understand the difference before configuring a project.
- What MCP is and how to write tools Claude picks correctlyMCP standardizes how Claude connects to external data and actions. See how to name and describe tools so it picks the right one, even among dozens.
- How Claude's prompt caching works — and how not to overpayPrompt caching cuts real cost, but only if the prefix is byte-for-byte identical. See where to put the breakpoint and how to handle 429, 529, and 400 errors.
Study this for real
This is one concept out of the whole certification path. AgentPrep turns all of them into a daily quest, inside Claude Code.
Start free