Claude Prompt Templates — 10 XML Structures That Work
Claude responds best to structure. It was trained on a large amount of XML-tagged content, so it reads tagged sections as labeled containers instead of one undifferentiated block of prose. That is why a tagged prompt produces more consistent output than the same instructions written as a paragraph.
Below are 10 copy-paste templates in Anthropic’s XML format. Each uses the common four-section pattern — <role>, <context>, <task>, <output_format> — plus extra tags (<input>, <examples>, <constraints>) where they earn their place. Replace the {{placeholders}}, paste into Claude, and adjust.
There are no “correct” tag names. Anthropic’s documentation is explicit: use names that describe what a section contains, and keep them consistent. The templates here pick clear, conventional names so you can swap one in immediately. For the reasoning behind the format, see the companion guide on how to structure Claude prompts with XML.
1. Code Review
When to use: you want a thorough, prioritized review of a diff or file — not a vague “looks good”.
<role>
You are a senior software engineer doing a careful code review.
</role>
<context>
Language/framework: {{e.g. TypeScript, Node.js, Express}}.
This code {{what it does and where it runs}}.
Priorities, in order: correctness, security, then readability.
</context>
<input>
{{paste the diff or file here}}
</input>
<task>
Review the code above. Find bugs, security issues, edge cases, and unclear
logic. Report problems you are uncertain about as well — flag them as low
confidence rather than dropping them.
</task>
<output_format>
A numbered list, ordered by severity (critical, high, medium, low).
For each item: severity, file and line reference, what is wrong, and a
concrete suggested fix. End with one "Overall" sentence.
</output_format>
2. Summarize a Long Document
When to use: you have a long text and need a tight, structured summary at a fixed length.
<role>
You are a precise analyst who summarizes without losing key facts.
</role>
<document>
{{paste the article, transcript, or report here}}
</document>
<task>
Summarize the document above for a {{audience, e.g. busy executive}}.
Keep only what changes a decision; drop background and filler.
</task>
<output_format>
- A one-sentence TL;DR (under 25 words).
- 3 to 5 bullet points, each under 20 words, covering the main takeaways.
- One "Open questions" line if anything material is unresolved; otherwise omit it.
Do not add information that is not in the document.
</output_format>
3. Rewrite / Edit Text
When to use: you want existing text rewritten to a specific tone and length without changing the meaning.
<role>
You are an editor who tightens prose without changing the author's meaning.
</role>
<context>
Target tone: {{e.g. direct and professional}}.
Target length: {{e.g. under 80 words}}.
Audience: {{e.g. prospective customers}}.
</context>
<input>
{{paste the text to rewrite here}}
</input>
<task>
Rewrite the text above to match the tone and length above. Preserve all facts
and the original intent. Remove hedging, filler, and repetition.
</task>
<output_format>
Return only the rewritten text — no preamble, no commentary, no alternatives.
</output_format>
4. Extract Structured Data
When to use: you need clean structured data (JSON) pulled out of messy or unstructured text.
<role>
You are a data extraction engine. You output only valid data, never prose.
</role>
<input>
{{paste the unstructured text — email, invoice, notes, transcript}}
</input>
<task>
Extract the requested fields from the input above. If a field is not present,
use null. Do not guess or infer values that are not stated.
</task>
<output_format>
Return a single JSON object with exactly these keys:
{
"name": string | null,
"email": string | null,
"company": string | null,
"amount": number | null,
"date": string | null // ISO 8601, or null
}
Output the JSON only — no markdown fences, no explanation.
</output_format>
5. Classify / Route
When to use: you want each item sorted into one of a fixed set of categories, with a reason.
<role>
You are a classification system that assigns one label from a fixed set.
</role>
<context>
Allowed categories (choose exactly one): {{e.g. billing, bug, feature_request, other}}.
Definitions:
- billing: payments, refunds, invoices, pricing.
- bug: something is broken or behaves incorrectly.
- feature_request: a request for new functionality.
- other: anything that fits none of the above.
</context>
<input>
{{paste the message to classify here}}
</input>
<task>
Assign exactly one category from the allowed set. If it is genuinely ambiguous,
pick the closest fit and lower your confidence.
</task>
<output_format>
Return JSON: { "category": string, "confidence": "high" | "medium" | "low",
"reason": string (one sentence) }. Output JSON only.
</output_format>
6. Brainstorm Ideas
When to use: you want a spread of distinct, usable ideas rather than three obvious ones.
<role>
You are a creative strategist who values range and specificity over volume.
</role>
<context>
Goal: {{what you are trying to achieve}}.
Constraints: {{budget, audience, channel, tone, anything off-limits}}.
</context>
<task>
Generate {{e.g. 8}} distinct ideas for the goal above. Make them genuinely
different from each other — not variations of one theme. Include at least two
that are unconventional.
</task>
<output_format>
A numbered list. For each idea: a 3-to-6-word title, then one sentence on the
idea, then one sentence on why it could work. No intro, no conclusion.
</output_format>
7. Draft an Email
When to use: you need a complete, send-ready email in a specific tone with a clear ask.
<role>
You are a clear, courteous business writer.
</role>
<context>
From: {{your name and role}}.
To: {{recipient and their relationship to you}}.
Purpose: {{the single goal of this email}}.
Tone: {{e.g. warm but concise}}.
Key facts to include: {{bullet the must-mention points}}.
</context>
<task>
Write the email. Lead with the ask or the point — do not bury it. Keep it under
{{e.g. 150}} words. Include a subject line.
</task>
<output_format>
Subject: {{one line}}
{{email body, with a greeting and sign-off}}
No commentary before or after the email.
</output_format>
8. Write a SQL Query
When to use: you want a correct SQL query against a known schema, with the logic explained.
<role>
You are a SQL expert. You write correct, readable queries for the given dialect.
</role>
<context>
Dialect: {{e.g. PostgreSQL 16}}.
Schema:
- users(id, name, email, created_at)
- orders(id, user_id, amount_cents, status, created_at)
{{add or replace tables and columns with your real schema}}
</context>
<task>
Write a query that answers this question: {{plain-English question, e.g. "total
revenue per user for paid orders in the last 30 days, highest first"}}.
Use only the columns defined above. Do not invent tables or columns.
</task>
<output_format>
1. The SQL query in a single code block.
2. Two or three bullet points explaining the key joins and filters.
3. One note on any assumption you made about the data.
</output_format>
9. Compare Options (Decision Table)
When to use: you are weighing options and want a like-for-like comparison plus a recommendation.
<role>
You are an impartial analyst who compares options on stated criteria only.
</role>
<context>
Decision: {{what you are choosing between, e.g. three project management tools}}.
Options: {{Option A, Option B, Option C}}.
Criteria that matter to me, in order: {{e.g. price, learning curve, integrations}}.
</context>
<task>
Compare the options above against the criteria above. Be specific and note where
you are uncertain. Then give a single recommendation for my stated priorities.
</task>
<output_format>
A markdown table: one row per option, one column per criterion, plus a final
"Best for" column. Below the table, a 2-to-3-sentence recommendation that names
the winner and the main trade-off. State if any cell is an assumption.
</output_format>
10. Explain a Concept (Teach Me)
When to use: you want a concept explained at a chosen level, with an analogy and a check.
<role>
You are a patient teacher who explains clearly and checks understanding.
</role>
<context>
Topic: {{the concept you want explained}}.
My current level: {{e.g. beginner / knows the basics / intermediate}}.
Why I am learning it: {{the practical reason, so the explanation stays relevant}}.
</context>
<task>
Explain the topic at my level. Use one concrete analogy. Avoid jargon, or define
it the first time it appears. Do not oversimplify to the point of being wrong.
</task>
<output_format>
1. A 2-to-3-sentence plain-language explanation.
2. One analogy.
3. A short worked example.
4. One "check yourself" question (with the answer hidden one line below it).
</output_format>
How to Adapt These Templates
A few rules that apply to all 10:
- Skip tags you do not need. A quick rewrite needs only
<task>and<input>. Over-tagging a single sentence adds nothing. - Keep
<output_format>specific. “Give me a summary” tells Claude nothing. “Three bullets, each under 20 words” does. This is the section most people drop and the one that saves the most cleanup later. - Put constraints in context, not in the task. “Do not include PII” or “avoid jargon” belong in
<context>or a dedicated<constraints>tag — not jammed into<task>. - Stay consistent with tag names. If you call the input
<input>in one prompt, do not call it<text>in the next. Consistency is what makes a template reusable.
For nesting multiple documents and the full rationale, read how to structure Claude prompts with XML.
Skip the Snippet Library — Apply These From a Hotkey
Keeping templates in a notes app and filling in placeholders by hand works, but it adds friction every time — especially when you are writing prompts inside Claude.ai, ChatGPT, VS Code, Slack, or anywhere else.
Prompt Enhancer is a native macOS and Windows desktop app that applies these XML structures automatically. Select any draft in any app, press a global hotkey, and it rewrites your text into a structured <role>/<context>/<task>/<output_format> prompt in place, in under four seconds — so you get the structure of every template above without keeping a snippet library.
Free and trial enhancements run through our managed proxy, which never logs prompt content. On Pro you can enable BYOK — your own Anthropic API key, so prompts go directly to api.anthropic.com with no proxy in between. Try it with 3 free enhancements (no signup), then a 7-day free trial. Pro Lifetime is a one-time $29, with no subscription.
Summary
| Template | Best for | Key tags |
|---|---|---|
| Code review | Prioritized bug/security review | role, context, input, task, output_format |
| Summarize | Fixed-length structured summary | role, document, task, output_format |
| Rewrite | Tone/length change, same meaning | role, context, input, task, output_format |
| Extract | Clean JSON from messy text | role, input, task, output_format |
| Classify | One label from a fixed set | role, context, input, task, output_format |
| Brainstorm | A range of distinct ideas | role, context, task, output_format |
| Send-ready email with an ask | role, context, task, output_format | |
| SQL | Correct query for a known schema | role, context, task, output_format |
| Compare | Like-for-like decision table | role, context, task, output_format |
| Explain | Concept at your level | role, context, task, output_format |
Sources: Use XML tags to structure your prompts — Claude Docs · Prompting best practices — Claude Docs