Bible Network Crypto DeFi Onchain RWA AI Agent Stablecoin Chain SAFU CryptoTax DeFAI AGI Claude Me Claude Skill Claude Design Claude Cowork
Independent Media
Not affiliated with any project
Learn Claude Skills. Do Everything Better.
claudeskill-me.com
LATEST
Subagents Aren't Smarter Mini-Claudes — They Solve Isolation, Not Capability  ·  How Long Should SKILL.md Actually Be? The Logic Behind the Official 500-Line Guideline  ·  How to Actually Use XML Tags in Prompts: 3 Before/After Examples vs. Plain Text  ·  What Is MCP? Understanding "USB-C for AI" and Connecting Claude to Your First External Tool  ·  Claude API Bill Suddenly Higher? Check Whether You're Using Prompt Caching — and That Quietly Changed TTL  ·  How to Set Claude's Temperature Parameter: 0 to 1, and the Hidden Constraint That Keeps Breaking Developer Tools
prompt-examples

How to Actually Use XML Tags in Prompts: 3 Before/After Examples vs. Plain Text

30-Second Version · For the impatient
XML tags aren't decoration — they convert a semantic boundary Claude had to guess at into an explicit declaration.

Full Explanation +
01 · Why did this happen?

Do XML tags really make that much difference compared to plain-text paragraph breaks or headers?

The difference comes down to how explicit the signal is. Paragraph breaks and text labels (like writing "Example:" or "Input:") do provide some separation that a human reader can follow, but these markers are still part of natural language — Claude still has to interpret them as content rather than recognize them as a structural boundary.

XML tags work at the format level instead: Claude doesn't need to "understand" what a label means semantically, it directly recognizes a container boundary. This is also why the official documentation emphasizes tags being most effective when multiple content types are mixed together — the more types of content and the higher the risk of confusion, the more a format-level signal outperforms a semantic-level label.

02 · What is the mechanism?

Is there a standard vocabulary for tag names? Does picking names carelessly hurt the results?

The official documentation is explicit that Claude wasn't trained to recognize only one "canonical" set of XML tags — any descriptive tag name works, including situation-specific ones like <customer_data> or <financial_report>.

But "any name works" isn't the same as "naming carelessly." Two principles matter: first, the name should make the contents obvious at a glance, which also helps when you come back to edit the prompt later; second, stay consistent within a single prompt — don't use <input> in one section and switch to <user_input> for similar content elsewhere, since that inconsistency creates new confusion on its own.

03 · How does it affect me?

Can XML tags be combined with Few-Shot Prompting or Chain-of-Thought Prompting?

Not only can they, the official documentation explicitly recommends this combination as a "power user" technique. A common pattern is wrapping multiple examples in <examples>, with each individual input-output pair separated by its own <example> tag — this lets Claude clearly recognize "there are several examples here, each an independent input-output pairing," rather than blending different examples' content together.

For chain-of-thought, a common pairing is <thinking> and <answer> tags, letting Claude output its reasoning process separately from the final answer, which makes it easier to programmatically extract just one part later. One caveat: if your use case is already using the API's Extended Thinking feature, layering on a <thinking> tag asking Claude for additional reasoning output isn't recommended — the two reasoning mechanisms can interfere with each other and actually reduce quality.

04 · What should I do?

I mostly chat with Claude through claude.ai in the browser rather than building on the API — is this technique still useful for me?

Completely, and the barrier to entry is lower than it sounds. You don't need to understand XML syntax rules or write any code — just wrap different types of content in angle brackets like <example>...</example> or <instructions>...</instructions> directly in the chat box, and Claude will recognize the structure the same way.

The most practical scenario is when you need to paste several different kinds of content into one message at once — say, a writing style example to follow, some background material, and today's actual topic. Without any markers, these three blocks are easy for Claude to misjudge as the same kind of thing. Spending ten seconds adding tags buys you noticeably more accurate replies with less back-and-forth clarification — a pretty good trade for everyday chat use.

Full Content +

If you've ever written a prompt longer than three paragraphs, you've probably run into this: Claude treats your "example" as part of the actual instruction, or mistakes "background context" for the problem it's supposed to solve. This isn't a sign Claude isn't smart enough — it's that plain-text prompts simply lack clear boundaries once content starts piling up. Even a carefully worded system prompt gets misread if its internal structure is a mess.

Anthropic's own Prompt Engineering documentation states that when a prompt mixes instructions, context, examples, and variable input, XML tags meaningfully reduce the chance Claude misjudges what each section is for. Rather than repeating syntax rules the official docs already cover, this piece walks through three real before/after cases so you can see exactly what the difference looks like in practice.

Case One: Customer Service Replies — The Example Gets Mistaken for the Input

An untagged prompt typically looks like this: an instruction to "reply to this complaint in a friendly tone," followed by a past reply used as an example, followed by the actual complaint that needs a response. The three sections look clearly separated to a human reader, but to Claude, they're all just text — there's no structural signal telling it "the second Block is a reference example, don't respond to it" or "the third block is the actual thing to handle." A common failure mode here is Claude replying to the example itself, or applying the example's tone to the wrong target.

Wrapping the example in <example> and the actual complaint in <input>, while keeping the instruction in <instructions>, makes the role of each block unambiguous. This isn't decorative punctuation — it converts a semantic boundary Claude previously had to guess at into an explicit declaration.

Case Two: Multi-Document Comparison — Claude Cites the Wrong Source

When you hand Claude two or more documents and ask it to compare them, plain-text pasting is where things go wrong most often — without a clear separator between documents, Claude can sometimes attribute content from Document A to Document B, especially when the documents share similar formatting and lack distinct headers.

The documented approach is to wrap each document in a <document> tag with an index attribute for numbering, nesting <source> and <document_content> subtags inside. This nested structure lets Claude explicitly mark which document a given claim came from when generating its response — it's the same pattern this site actually uses when handling multi-source search results: each source gets wrapped independently before asking for sentence-level attribution.

Case Three: The Role Setup Gets Diluted by Later Instructions

Another common pattern: a prompt opens by setting a role ("you are a senior backend engineer"), then follows with a long list of formatting requirements, output rules, and caveats. The role setup's influence gradually dilutes, and Claude's tone drifts toward something more generic, losing the specific professional lens it was supposed to apply.

Keeping the role setup separate from formatting rules — for example, keeping the role in the System Prompt and wrapping format requirements in <formatting> — helps Claude distinguish "this is who I am" from "these are my output rules," so a longer rules section doesn't dilute the weight of the role setup.

When You Don't Need XML Tags

The official documentation's phrasing is specific: use XML tags "when your prompt mixes instructions, context, examples, and variable inputs." The inverse holds too — if your prompt is a single, simple question without multiple content types mixed together, adding tags just introduces noise without meaningful improvement. The deciding factor isn't prompt length; it's how many distinct content types need to be kept apart from each other.

What This Means for Your Prompt Design

Next time you write a prompt, ask yourself one question first: how many different roles of content does this text contain — instructions, examples, background, input to process? If the answer is two or more, wrapping each in its own tag is more reliable than continuing to let Claude guess at the boundaries. There's no mandated tag vocabulary; what matters is staying consistent within a single prompt and choosing names that make the contents obvious at a glance.

Sources: Use XML tags to structure your prompts - Claude Docs, Prompting best practices - Claude Platform Docs
Diagram
純文字 Prompt 與 XML 標籤 Prompt 對比純文字 Prompt 缺乏結構邊界,容易讓 Claude 混淆各段落角色;XML 標籤把角色邊界明確宣告出來Plain Text vs XML-Tagged PromptPlain Text PromptInstruction text...Example text...Input text...No structural boundary→ Claude may confuse rolesXML-Tagged Prompt<instructions>...</instructions><example>...</example><input>...</input>Explicit role boundary→ Claude parses each block correctlyClaude Skill Me · claudeskill-me.com
Feel free to share. Please credit the source.
Ask a Question
Please enter at least 10 characters
Related Articles
System Prompt vs. User Prompt: The Structural Difference That Decides Whether Claude Actually Listens
beginners · Aug 27
Writing Your First System Prompt: From "You Are an Assistant" to a Role Setup That Actually Works
prompt-examples · Aug 14
Subagents Aren't Smarter Mini-Claudes — They Solve Isolation, Not Capability
advanced · Aug 31
How Long Should SKILL.md Actually Be? The Logic Behind the Official 500-Line Guideline
skill-library · Aug 31
More Related Topics