🎉🎉 Turn your prompts into realistic images with Realistic AI!Try for Free
Text AI

How to Prompt Claude: XML Tags, Examples and Long Documents

Structure prompts with XML tags, put long documents first, add examples and let Claude think step by step. Includes a reusable template.

By the AI Prompt Generator TeamUpdated September 27, 20263 min read

Claude handles long documents and careful instructions especially well, and Anthropic publishes clear guidance on how to prompt it. The single most useful habit is structuring your prompt with XML tags. This guide explains why, and how to combine tags with examples, step-by-step thinking and prefilled answers.

Be clear and direct

Anthropic's own advice is to write prompts the way you would brief a smart new colleague who knows nothing about your project:

  • What is the task for, and who will read the result?
  • What does a successful answer look like?
  • Which steps should be followed, in order?

If a colleague would need to ask you a follow-up question, Claude probably needs that information too.

Use XML tags to separate the parts of your prompt

Claude was trained to pay attention to XML-style tags. They are not a special syntax — any descriptive tag name works — but they make it unambiguous which text is an instruction, which is data and which is an example.

You are a contracts analyst.

<contract>
{{PASTE CONTRACT HERE}}
</contract>

<instructions>
1. List every clause that creates a payment obligation.
2. For each, quote the clause and explain it in one plain-English sentence.
3. Flag any clause that allows the other party to change prices.
</instructions>

<output_format>
Return a numbered list. Put flagged clauses in a separate section called
"Risks".
</output_format>

Tips for tags:

  • Name them after their content: <email>, <data>, <style_guide>.
  • Refer to them in your instructions: "Using the report in <report> tags…".
  • Nest them for hierarchy: <examples><example>…</example></examples>.
  • Ask for tagged output when you need to parse the answer: "Put the final answer in <answer> tags."

Put long documents first, questions last

For long inputs (reports, transcripts, codebases), place the documents at the top of the prompt and your question at the end. Anthropic notes this ordering can noticeably improve answer quality on long-context tasks.

For several documents, wrap each one with its metadata:

<documents>
  <document index="1">
    <source>q3-report.pdf</source>
    <document_content>{{REPORT}}</document_content>
  </document>
  <document index="2">
    <source>customer-survey.csv</source>
    <document_content>{{SURVEY}}</document_content>
  </document>
</documents>

Using only the documents above, explain why churn increased in Q3.
Quote the passages that support each reason.

Asking Claude to quote relevant passages before answering keeps it grounded in your material.

Give examples (multishot prompting)

Three to five diverse examples inside <example> tags are one of the most reliable ways to control tone and format:

<examples>
  <example>
    <input>Order arrived late</input>
    <output>Category: Shipping | Sentiment: Negative | Urgency: Medium</output>
  </example>
  <example>
    <input>Love the new colour options!</input>
    <output>Category: Product | Sentiment: Positive | Urgency: Low</output>
  </example>
</examples>

Classify this message in the same format: {{MESSAGE}}

Make examples varied so Claude learns the pattern rather than copying one case.

Let Claude think first

For analysis, maths, planning or writing that needs judgement, ask Claude to reason before it answers and to keep the reasoning separate:

Think through the problem in <thinking> tags. Then give your final
recommendation in <answer> tags.

This makes answers more accurate and lets you check the reasoning. Newer Claude models also offer a built-in extended thinking mode that does this automatically.

Assign a role with a system prompt

In the API, the system prompt is the right place for a role ("You are a senior data scientist at a fintech company"). In the Claude app, simply open your message with the role. A specific role changes vocabulary, depth and the kind of risks Claude points out.

Chain prompts for complex jobs

Break big tasks into a sequence where each prompt's output (inside tags) becomes the next prompt's input:

  1. Extract key facts from a document → <facts>
  2. Draft a summary from <facts> → <draft>
  3. Review <draft> against the original for errors → final version

Each step is simpler, easier to debug and more accurate than one giant prompt.

A reusable Claude prompt template

You are {{ROLE}}.

<context>
{{BACKGROUND, AUDIENCE, GOAL}}
</context>

<input>
{{DOCUMENT OR DATA}}
</input>

<instructions>
1. {{STEP 1}}
2. {{STEP 2}}
3. {{STEP 3}}
</instructions>

<constraints>
- Length: {{e.g. under 300 words}}
- Tone: {{e.g. neutral, plain English}}
- If information is missing, say so instead of guessing.
</constraints>

Think in <thinking> tags first, then give the final answer in <answer> tags.

Skip the boilerplate

The Claude Prompt Generator writes this structure for you: describe the task in one sentence and it returns a tagged, step-by-step prompt with placeholders where your own documents go.

Try the Claude Prompt Generator

XML-tagged, step-by-step prompts Claude follows well. Free, no sign-up.

Open generator

Keep Learning