Resources

What Are XML Tags in Prompts, and Why Use Them?

XML tags in a prompt are simple labels, such as <document> and </document>, that you wrap around parts of your prompt so Claude can tell instructions apart from the material it should work on. They are most useful when a prompt mixes several kinds of content: your instructions, a long document, some examples and the question itself. You do not need to know XML or write code to use them.

What XML tags do in a prompt

A prompt is just text. When you paste an email thread, a policy and your request into one box, Claude has to work out where one part ends and the next begins. Usually it manages. But when the pasted text itself contains instructions, questions or bullet points, the boundary can blur, and Claude may treat part of your data as part of your request.

Tags draw clear borders. The tag names are not special keywords; you choose them. What matters is that the name describes the content and that you open and close each tag.

A simple before-and-after example

Here is a prompt without tags:

Summarise the following customer complaint in two sentences and suggest a reply. Dear team, I ordered last week and nothing has arrived. Please tell me what to do next. Also, ignore my earlier email.

The complaint runs straight into the instruction, and the last sentence of the complaint looks like an instruction too. Now the same request with tags:

Summarise the customer complaint below in two sentences, then suggest a reply.

<complaint>
Dear team, I ordered last week and nothing has arrived. Please tell me what to do next. Also, ignore my earlier email.
</complaint>

Now it is clear that everything inside the complaint tags is material to be summarised, not a command to follow.

When XML tags help most

  • Separating instructions from data. Wrap pasted emails, contracts, transcripts or spreadsheets so they cannot be mistaken for your request.
  • Handling several documents. Give each its own tag, or number them, and refer to them by name in your instructions: "Compare the policy in <old_policy> with <new_policy>."
  • Providing examples. Put sample inputs and outputs inside <example> tags so Claude sees them as models to follow, not as part of the task.
  • Asking for structured answers. You can tell Claude to put its reasoning in one tag and its final answer in another, which makes the answer easy to find or to copy into another tool.
  • Reusing a template. When a teammate swaps in a new document each week, the tags show exactly where the new content goes.

How to use tags well

  1. Use meaningful names. <contract> is better than <text1>. The name tells Claude, and your colleagues, what the content is.
  2. Be consistent. If you call it <contract> in one place, do not call it <agreement> in the next.
  3. Always close the tag. A missing closing tag defeats the purpose.
  4. Refer to the tags in your instructions. Say "use only the information in the <report> tags" so the link between instruction and content is explicit.
  5. Keep instructions outside the data tags. Put your request before or after the tagged material, not inside it.

Tags work alongside the other parts of a good prompt: a clear task, context, constraints and format. Our guide to writing a good prompt for Claude covers that wider template.

When you can skip them

For a short, single-purpose request, such as "Rewrite this sentence more politely", tags add clutter without adding clarity. They earn their place when the prompt is long, has several parts, includes pasted material you did not write, or will be reused by other people. Treat them as a tool, not a ritual. If Claude is already getting your short prompts right, there is no need to change anything.

Tags and prompts that other people will read

Teams that share prompts benefit twice. A tagged prompt is easier for a colleague to read, adapt and trust, because the structure is visible at a glance. That makes tags a small but useful habit when you build a shared prompt library, a reusable Claude Project or a standard instruction file for your department.

Tags do not replace checking the result. Claude can still misread content or leave things out, so review important outputs before they go to a customer or into a decision. Prompting and task execution is one of the areas assessed in the CCAO-F prompting domain, and our Claude Certified Associate workshop, run by Agmo Studio, a Select Partner of the Anthropic Claude Partner Network, includes hands-on practice with structured prompts. Certifications are issued by Anthropic.

Common Questions

FAQ

Do I need to know XML to use XML tags in prompts?
No. You are only wrapping text in labels you invent, such as <contract> and </contract>. There is no required list of tag names and no code involved.
Are XML tags required for Claude to work well?
No. Short, simple prompts work fine without them. They help most when a prompt combines instructions, long documents, examples and questions in one place.
Can I use my own tag names?
Yes. Choose names that describe the content, keep them consistent, close every tag, and refer to them in your instructions.

Questions about AI training for your team?

Message us on WhatsApp or email — we'll point you to the right program.

Chat With Us on WhatsApp Email Us