Use Tags to Organize Your Input in Claude

Use Tags to Organize Your Input in Claude

When your message to Claude contains instructions, documents, and examples all at once, it can get messy. Simple labels called tags keep each part separate and clear. This guide shows how tags work, where to use them, and how to avoid common slips.

Imagine moving house and packing everything into the same big box: kitchen knives, bedsheets, a lamp, loose papers, and a bag of rice. Arriving at your new home, you would struggle to find anything, and something might get broken or spilled. Now imagine the same belongings packed into boxes with clear labels on the side: Kitchen, Bedroom, Papers, Food. Unpacking becomes calm and quick. A long message to an AI can be like that first jumbled box. When you put several kinds of information into one block of text, the AI has to work out where one part ends and the next begins. Tags are the labels on the boxes. They make it obvious what each piece is, so Claude can handle it correctly.

1What Does “Use Tags to Organize Input” Mean?

It means wrapping each part of your message in a simple named label, so Claude knows what each part is for.

A tag is a short word placed between angle brackets, like a label at the start of a section, with a matching label at the end to close it. Everything between the opening label and the closing label belongs to that section. For example, you might place a pasted email between a “email” label and its closing label, and your request between an “instructions” label and its closing label. Claude can then see at a glance which part is the email to be read and which part is the task to be done.

This style of labeling is called XML-style tagging, because it borrows its look from a long-standing format used to organize data. You do not need to know anything about that format to use the idea. All you need is to open a label, write your content, and close the label. There are no strict rules about which words you may use, and the labels do not have to come from an official list.

Simple Analogy

Think of a school bag with separate pockets. The front pocket holds your pencil case, the main compartment holds notebooks, and the side pocket holds your water bottle. You do not have to explain this to anyone who looks inside, because the pockets themselves show what goes where. Tags are pockets for the different parts of your prompt.

flowchart LR
    A["Messy block of text"] --> B["Add labels around each part"]
    B --> C["Instructions"]
    B --> D["Document"]
    B --> E["Examples"]
    B --> F["Output format"]
    C --> G["Claude sees clear sections"]
    D --> G
    E --> G
    F --> G
        
FIG 1 — Tags turn one tangled block into clearly labeled sections
i
Official Guidance

Anthropic’s prompt engineering documentation has a page called “Use XML tags to structure your prompts”. It explains that tags help Claude parse prompts that combine context, instructions, and examples, and it is the official place to read more.

2Key Terms You Need First

A few simple words appear again and again in this topic. Here they are in plain English.

Term 1

Prompt

The message you give to Claude, including any instructions, documents, and examples you place in it.

Term 2

Tag

A short named label written between angle brackets that marks the start or end of a section of your message.

Term 3

Opening and closing tag

The pair of labels around a section. The opening one begins it, and the closing one, which has a slash, ends it.

Term 4

Nesting

Placing one tagged section inside another, like a smaller box inside a bigger box.

Term 5

Context

Background information Claude needs to do the task well, such as who the audience is or what the project is about.

Term 6

Instructions

The part of your message that says what you want Claude to do.

Term 7

Delimiter

Anything that marks a boundary between parts of text. Tags are one kind of delimiter, and a very clear one.

Term 8

Parsing

Reading and picking apart text to find its pieces. Tags make this easier for both Claude and for any program reading Claude’s reply.

3The Problem: When Everything Is Mixed Together

Plain, unlabeled prompts work for small jobs but start to fail as they grow.

For a short, simple request such as “Explain how rainbows form”, no organization is needed. But real work is rarely that tidy. You might want Claude to read a long report, follow a set of rules, match the style of a sample, and then answer in a particular layout. Putting all of that into one stream of sentences creates several risks.

Risk 1: Instructions get mixed with content

If you paste a document that itself contains sentences like “Please reply by Friday”, Claude may be unsure whether that sentence is part of the document or an order for it. Without clear boundaries, the line between your instructions and the material blurs.

Risk 2: Examples get mistaken for the real task

When you include sample questions and answers, Claude may answer the samples again, or treat a sample as the actual request, unless it is plainly marked as an example.

Risk 3: Parts get missed in long prompts

In a very long message, a rule placed in the middle can be overlooked. Structure helps every part stand out as its own item.

Risk 4: Hard to edit later

A single wall of text is difficult to update. If you want to swap the document or tweak one rule, you must hunt through the whole message.

Simple Analogy

Imagine a teacher reading an exam paper where the questions, the answers, and the rules were all printed in one long paragraph with no line breaks or headings. Even a clever student would feel uncertain about where to start. Structure is not decoration. It is how we make meaning clear.

4Why Tags Help Claude

Tags give Claude clear signals about what each part of your message is.

Anthropic’s guidance says that when a prompt has several components, such as context, instructions, and examples, tags help Claude read it more accurately and tend to improve the quality of the answer. A tip in the official documentation suggests using labels such as instructions, example, and formatting to separate the different parts, which prevents Claude from mixing up instructions with examples or context.

The official page highlights a few benefits. It points to clarity, because each part is clearly separated. It points to accuracy, because there is less chance of parts being misread. It points to flexibility, because you can find, add, remove, or change one part without rewriting everything. And it points to parseability, because if Claude uses tags in its reply, a program or a person can pull out exactly the piece needed.

Benefit 1

Clarity

Each part of the prompt is clearly separated, so Claude knows what is a rule, what is material, and what is a sample.

Benefit 2

Accuracy

Fewer misunderstandings caused by parts running into each other.

Benefit 3

Flexibility

Swap a document or change one instruction without touching the rest of the prompt.

Benefit 4

Easy extraction

Ask Claude to put its answer inside tags, and anyone can pick out that part easily.

Benefit 5

Reusability

A well-labeled prompt works like a template that you can reuse with new content each time.

Benefit 6

Team-friendly

Others can read your prompt and understand its structure quickly, which helps when sharing work.

“Tags are labels on the boxes, so Claude never has to guess what is inside.”

5How a Tag Is Written

The basic pattern is the same every time: open, fill, close.

1

Choose a clear name

Pick a short word that describes the content, such as document, instructions, example, or notes. The name is for meaning, so choose one a stranger would understand.

2

Write the opening tag

Put the name between a less-than sign and a greater-than sign. This marks where the section begins.

3

Place your content inside

Write or paste the material for that section. It can be a single line or many paragraphs.

4

Write the closing tag

Repeat the same name, but add a forward slash before it, inside the brackets. This marks where the section ends.

5

Refer to it by name

In your instructions, mention the section by its label, such as “Summarize the text in the document tags.” This links your request to the labeled content.

i
No Special Tag Names Required

There is no official list of tag names that Claude insists on. Any sensible, descriptive name works, as long as you use it consistently and the name matches what is inside.

!
Always Close What You Open

If you open a tag and forget to close it, the boundary becomes unclear again. A matching closing label for every opening label keeps the structure clean.

6Handy Tag Names to Start With

You can invent your own, but these common labels cover most everyday needs.

Common

instructions

The task you want done and any rules to follow. Keeping this apart stops it from blending with the material.

Common

context

Background information, such as who the audience is, what the goal is, or what has already happened.

Common

document

A text you pasted for Claude to read, such as an article, a report, or an email thread.

Common

example

A sample of an input and the output you want. Use several example sections, or group them inside an examples section.

Common

formatting

How you want the answer laid out, such as a short list, a table, or three labeled parts.

Common

input

The specific item you want Claude to work on right now, kept apart from fixed instructions.

Common

constraints

Limits and rules, such as word count, topics to avoid, or a required tone.

Common

answer

Where you ask Claude to place its final response, which helps when you want to extract only that part.

i
Make Up Your Own

If your prompt includes a customer complaint, a style guide, or a price list, label them exactly that. Names that match your content are better than generic ones.

7Worked Example 1: Summarizing a Pasted Email

Let us start with the most common use: separating your request from the material you want Claude to read.

Suppose a customer sent a long, rambling email and you want a short summary plus a suggested reply. Without labels, you might paste the email and write your request right under it, and the two could run together. With labels, the structure is crisp.

Step 1: Label the material

Place the customer’s email between an opening “email” label and a closing “email” label. Everything inside is clearly the thing to be read, not an order to be followed.

Step 2: Label your request

Place your task between “instructions” labels, for instance: “Summarize the email in the email tags in three short bullet points, then suggest a polite two-sentence reply.”

Step 3: Add the limits

If you care about tone or length, add a “constraints” section saying, for example, “Keep the tone warm and professional. Do not promise a refund.”

What Claude sees

Three neat boxes: the email, the task, and the rules. Claude reads the email as material, follows the task, and respects the rules, without confusing a sentence inside the email for one of your commands.

i
Refer to the Label

Notice that the instruction mentions the email tags by name. Referring to a section by its label connects your request to exactly the right content, even if there are other documents in the message.

8Worked Example 2: Comparing Several Documents

When you share more than one document, tags keep them from blurring into one.

Imagine you are comparing two job offers. You paste the text of both and ask Claude which has the better terms. If the texts are simply pasted one after another, Claude may struggle to tell where the first offer ends and the second begins, particularly if they use similar wording.

Give each document its own label

Wrap the first offer in a “document” section and the second offer in another “document” section. Better still, give each a clear name, such as offer_a and offer_b, so you can refer to them directly.

Nest the details when helpful

Inside each document section, you can add a “source” label for where it came from and a “content” label for the text itself. This tidy nesting mirrors how a filing cabinet works: a drawer, then a folder, then the paper.

Write instructions that name the labels

“Compare offer_a and offer_b on salary, notice period, and benefits. Present the result as a table, and say which offer looks stronger and why.”

flowchart TD
    A["Whole prompt"] --> B["documents"]
    A --> C["instructions"]
    B --> D["offer_a"]
    B --> E["offer_b"]
    D --> F["source"]
    D --> G["content"]
    E --> H["source"]
    E --> I["content"]
        
FIG 2 — Nested tags work like drawers, folders, and papers in a filing cabinet
Simple Analogy

A filing cabinet with a drawer marked “Job Offers”, inside it two folders marked “Offer A” and “Offer B”, and inside each folder the actual letter. You can always find the paper you want because each level is named.

9Worked Example 3: Keeping Examples Separate

Tags are especially useful when your prompt includes sample answers.

Samples are a powerful way to show Claude the style you want, but they must be clearly marked so they are not mistaken for the real task. Tags solve this neatly. Place the samples inside an “examples” section, with each sample wrapped in its own “example” label, and keep your real input in a separate “input” section.

The examples section

Inside it, one “example” for a product named Cardamom Buns with a warm one-line caption, and another “example” for Chocolate Brownies with a similar caption. Each shows an item and its ideal caption.

The input section

Separately, an “input” section containing only the new item: Lemon Tart.

The instruction

“Write a caption for the item in the input tags. Match the tone and length of the examples, but do not reuse their exact words.”

i
The Safety of Separation

Because the samples live in their own labeled section, Claude does not wonder whether the cardamom buns need a second caption. It uses them as a guide and does the real work on the input.

If you would like to learn more about how samples help, the idea of showing an example in your prompt is a technique on its own. Tags and examples work wonderfully together, because tags keep the samples tidy and clearly separate from the real job.

10Worked Example 4: Asking Claude to Reply with Tags

Tags can organize Claude’s answer too, not only your input.

You are not limited to labeling what you send. You can also ask Claude to label parts of what it sends back. This is helpful when your answer has several pieces, such as a short summary and a longer explanation, and you want to find one quickly or pass it into another tool.

1

Decide the parts of the answer

For example, a one-line verdict, the reasoning behind it, and a list of next steps.

2

Name the labels in your instruction

“Put your reasoning in thinking tags, then give your final verdict in answer tags.”

3

Claude replies in labeled parts

The reply arrives with the reasoning in one labeled section and the verdict in another.

4

Pick out what you need

You can copy just the verdict, or a program can extract the answer section automatically and ignore the rest.

sequenceDiagram
    participant You
    participant Claude
    You->>Claude: Task, material in labeled sections, and the output labels you want
    Claude-->>You: Reply with reasoning and answer in separate labeled sections
    You->>You: Copy only the answer section you need
        
FIG 3 — Using tags on both sides: labeled input going in and labeled output coming back
i
Great for Automation

Developers building tools with Claude love this habit, because a program can reliably find the answer section in every reply. For everyday users it simply makes long answers easier to scan.

11Nesting Tags: Boxes Inside Boxes

When content has natural layers, place tags inside other tags.

Some information is layered. A list of customer reviews contains many separate reviews. A collection of documents contains several documents, each with a source and a body. Nesting means placing smaller labeled sections inside a larger labeled section, which reflects that structure.

Anthropic’s guidance mentions nesting as a good practice. The key rule is to close the inner tags before closing the outer one, just like boxes that must be closed in the right order. An outer “reviews” label might hold several inner “review” labels, and the outer closing label comes only after all the inner ones are closed.

LayerExample labelWhat it holds
OuterreviewsThe whole collection of customer reviews
MiddlereviewOne single review
Innerrating and commentThe star rating and the written comment of that review
Simple Analogy

Russian nesting dolls: a large doll contains a medium one, which contains a small one. You must open and close them in order. Nested tags follow the same rule of order.

!
Do Not Over-nest

Use only as many layers as your content naturally has. Too many levels make a prompt harder for people to read and add little value for Claude.

12Placing Things in a Smart Order

Where you put each labeled section can also affect the quality of the result.

Guidance for working with long material suggests putting long documents near the top of your prompt, and placing your question or instructions after them, near the end. Many people find this order works well, especially with large amounts of text, because Claude reads the material first and then sees exactly what you want done with it.

1

Long documents first

Place big pasted materials in labeled sections at the top.

2

Context and examples next

Add background and any labeled samples after the documents.

3

Instructions and the question last

End with the clear task, so it is fresh and unmistakable when Claude begins to answer.

flowchart TD
    A["1. Documents"] --> B["2. Context and examples"]
    B --> C["3. Instructions and question"]
    C --> D["Claude answers"]
        
FIG 4 — A friendly order for long prompts: material first, task last
i
A Guideline, Not a Law

This ordering is a helpful rule of thumb. If a different arrangement makes your prompt clearer, try it, and compare the results.

13Tags Compared with Other Ways of Organizing

Tags are not the only tool. Here is how they compare with other common methods.

MethodHow it worksStrengthWeakness
TagsNamed labels with clear start and endVery clear boundaries and easy to refer to by nameSlightly more to type
HeadingsTitles above each sectionEasy to read for peopleNo clear end of section, so material can bleed together
Divider linesLines of dashes between partsQuick to addDoes not say what each part is
Quotation marksQuotes around pasted textFine for a short snippetBreaks down when the text itself contains quotes
Numbered stepsOrdered list of instructionsGreat for sequences of actionsNot designed for separating documents or examples

These methods can be used together. You might use numbered steps inside your instructions section, while using tags to separate the instructions from the document. Think of tags as the outer structure and the other methods as tidying inside each section.

i
Why Tags Often Win for Complex Prompts

Because a tag has both a name and a clear end, it answers two questions at once: what is this, and where does it stop? Other methods usually answer only one.

14When You Do Not Need Tags

Tags are helpful, but a short simple message does not need them.

Short, single-purpose requests

“Give me five healthy breakfast ideas” has one part only. Adding labels would be extra work with no benefit.

Casual conversation

When you are chatting back and forth, natural sentences are perfectly fine. Save the structure for tasks with several moving parts.

When your prompt has few parts

A simple rule of thumb is to use tags when your message has more than two or three distinct pieces, such as instructions plus a document plus examples plus an output format.

When clear writing already does the job

If a short instruction and a short pasted text are obviously separate, a simple line break may be enough. Use tags when there is any real risk of confusion.

flowchart TD
    A["How many parts does your message have?"] --> B{"More than two or three kinds of content?"}
    B -- "Yes" --> C["Use tags"]
    B -- "No" --> D{"Could one part be confused with another?"}
    D -- "Yes" --> C
    D -- "No" --> E["Plain writing is fine"]
        
FIG 5 — A quick test for deciding whether tags are worth using

15Using Tags in the Claude App, Projects, and System Prompts

The same idea works wherever you write to Claude.

In the regular Claude chat, you simply type or paste labeled sections into your message. There is nothing to switch on. Tags are only text, and Claude reads them like any other part of your message.

In ongoing work such as Projects, where you save instructions and background for repeated use, tags help you keep those saved instructions neat: one section for the role and tone, another for the rules, another for background facts. Because they are labeled, you can update one section later without rewriting the others.

Developers who build their own tools with the Claude API often write a system prompt, which is a standing set of instructions given to Claude before the conversation begins. Tags are very popular there, because the same structure can be filled with new content each time while the labels stay constant.

Place 1

Everyday chat

Add labels to messages that combine several kinds of content, such as a task plus a pasted document.

Place 2

Saved project instructions

Organize standing guidance into labeled sections that are easy to review and update.

Place 3

System prompts for developers

Build reusable templates where the labels stay fixed and the content changes with each request.

Place 4

Shared team prompts

Labeled prompts are easier for colleagues to read, trust, and improve together.

16A Safety Note: Tags Do Not Make Content Trustworthy

Labels organize content. They do not make it safe.

It is tempting to think that wrapping a pasted web page or email in a “document” label makes anything inside it harmless. That is not quite true. Tags tell Claude what the content is, but a pasted text can still contain sentences written to push an AI into doing something. These are sometimes called prompt injection attempts, where hidden or sneaky instructions are placed inside material the AI reads.

Labeling the material as a document helps Claude treat it as something to read, not as orders from you. But you should still be careful with text from unknown sources, especially if Claude can take actions for you, such as sending messages or using connected apps. Review what Claude proposes to do before anything important or irreversible happens.

!
Good Habits

Treat pasted content from unknown sources as information only. Keep your real instructions in your own labeled section, and check any action before approving it.

i
Privacy Too

Do not paste passwords, financial account numbers, or confidential material into any prompt without proper approval, however neatly it is labeled.

17Mistakes to Avoid

A handful of habits cause most problems with tagged prompts.

ANTI-PATTERN-01 Avoid
Problem

Using different names for the same thing, such as “doc” in one place and “text” in another.

Why It’s Harmful

Claude and any person reading may wonder whether these are two different things, which weakens the clarity tags are meant to give.

Correct Approach

Choose one name per kind of content and use it everywhere, including when you refer to it in instructions.

ANTI-PATTERN-02 Avoid
Problem

Forgetting to close a tag, or closing tags in the wrong order.

Why It’s Harmful

The boundaries become blurry again, and one section may seem to swallow the next.

Correct Approach

Match every opening label with a closing label, and close inner sections before outer ones.

ANTI-PATTERN-03 Avoid
Problem

Choosing vague or misleading names, like “stuff” or “part1”.

Why It’s Harmful

The label no longer tells Claude, or you, what the content is for.

Correct Approach

Use descriptive names that match the content, such as contract, style_guide, or customer_email.

ANTI-PATTERN-04 Avoid
Problem

Wrapping every single sentence in tags, even in a short, simple prompt.

Why It’s Harmful

It adds clutter, makes the message tiring to read, and gives no real benefit.

Correct Approach

Use tags for genuine sections only, and leave simple parts as plain writing.

ANTI-PATTERN-05 Avoid
Problem

Putting instructions inside the document section.

Why It’s Harmful

Claude may treat your instruction as part of the material instead of a command, defeating the point of separating them.

Correct Approach

Keep the document section for the material only, and put every instruction in its own instructions section.

ANTI-PATTERN-06 Avoid
Problem

Assuming tags guarantee a perfect answer.

Why It’s Harmful

Tags improve clarity, but Claude can still make mistakes or misread unclear instructions.

Correct Approach

Write clear instructions too, test your prompt on real inputs, and check important facts yourself.

18Advantages and Trade-offs

Tags bring real benefits at a small cost in effort.

Advantages

  • Clear separation of instructions, material, and examples
  • Fewer misunderstandings in long or complex prompts
  • Easy to edit, reuse, and share as a template
  • Replies can be labeled too, making answers easy to extract
  • Prompts become easier for teammates to read and review

Disadvantages / Trade-offs

  • A little extra typing and planning
  • Overkill for very short or casual requests
  • Inconsistent names or missing closing tags can cause confusion
  • Tags do not by themselves protect against misleading pasted content

19Best Practices at a Glance

Keep these habits in mind whenever you organize input with tags.

Habit 1

Be consistent

Use the same tag name for the same kind of content throughout your prompt.

Habit 2

Name things clearly

Choose descriptive labels that match the content.

Habit 3

Refer to labels in instructions

Say things like “use the text in the document tags” so the link is explicit.

Habit 4

Close every tag

Match each opening label with a closing label, in the right order.

Habit 5

Nest only when natural

Add layers where the content really has layers, and no further.

Habit 6

Put long material first

Place big documents at the top and your question or task at the end.

Habit 7

Ask for labeled output when useful

Request answers inside named tags when you want to extract a particular part.

Habit 8

Stay careful with unknown content

Treat pasted text from unknown sources as information only, and review actions before approving them.

20Frequently Asked Questions

Quick answers to the questions beginners ask most often.

Q1What are tags in a prompt?

They are short named labels placed around parts of your message, with an opening and a closing label, so Claude can tell what each part is, such as instructions, a document, or an example.

Q2Do I need to know XML or coding to use them?

No. You only need to open a label, write your content, and close the label. The style looks like XML, but you do not need any technical knowledge.

Q3Are there official tag names I must use?

No. Any sensible, descriptive name works. What matters is that the name fits the content and that you use it consistently.

Q4When should I use tags?

Whenever your message mixes several kinds of content, such as instructions, a pasted document, examples, and a requested format. For short, simple requests they are not needed.

Q5Can I ask Claude to use tags in its reply?

Yes. Name the labels in your instruction, such as asking for reasoning in one labeled section and the final answer in another. This makes it easy to pick out the part you need.

Q6Is it necessary to close every tag?

It is a good habit. A closing label clearly marks the end of a section and keeps the structure clean, especially when tags are nested.

Q7Can I put tags inside other tags?

Yes. This is called nesting and is useful when content has layers, such as a list of documents that each have a source and a body. Close the inner tags before the outer one.

Q8Where should the instructions go?

Many people place long documents first and the instructions or question last, so the task is clear and fresh at the end. Try the order that makes your prompt clearest.

Q9Do tags work in the normal Claude chat?

Yes. They are simply text in your message, so there is nothing to turn on. They also work in saved project instructions and in system prompts for developers.

Q10Do tags make pasted content safe?

No. Tags organize content, but text from unknown sources can still contain misleading instructions. Treat such material as information only and review any action before approving it.

Q11Are tags better than headings or bullet points?

They solve a different problem. Tags give each section a name and a clear end, which is especially useful for separating documents, examples, and instructions. You can combine them with headings and lists inside each section.

Q12Where can I read the official advice?

Anthropic’s prompt engineering documentation has a page on using XML tags to structure prompts, which explains the benefits and best practices in more depth.

21Summary and Key Takeaways

Tags are simple named labels that you place around parts of your message to Claude, so it can tell instructions from documents, examples, and formatting requests. They work like labels on moving boxes: they make everything easy to find and prevent parts from being mixed up. Anthropic’s own guidance recommends them for prompts that combine context, instructions, and examples, and highlights clarity, accuracy, flexibility, and easy extraction as the main benefits. You choose descriptive names, open and close each tag, refer to the labels in your instructions, nest them only when content truly has layers, and put long material first with the task at the end. You can also ask Claude to label its reply. Tags are unnecessary for short, simple messages, and they do not make untrusted content safe, so keep reviewing important actions and checking important facts.

Key Takeaways

  • Tags are labels for the parts of your prompt — an opening and closing label around instructions, documents, examples, or formats keeps each part clearly separate.
  • They prevent mix-ups — Claude can tell the difference between your instructions, the material to read, and samples to follow.
  • Any clear name works — there is no required list, but use one consistent, descriptive name per kind of content.
  • Refer to labels by name — say “use the text in the document tags” so your request links directly to the right section.
  • Use them when prompts have several parts — skip them for short, simple, casual requests where plain writing is enough.
  • Tags can organize the reply too — ask Claude to put its answer in a named section so you can extract exactly what you need.
  • Labels organize, they do not protect — treat pasted text from unknown sources as information only, review actions before approving them, and verify important facts.