Promptyard
Format

Anthropic XML Prompt Builder

Compose a Claude prompt as ordered XML-tagged sections — instructions, context, examples.

  1. Section 1
  2. Section 2
  3. Section 3
Output
<instructions>
You are a senior code reviewer. Be concise and specific.
</instructions>

<guidelines>
- Flag security and correctness issues first.
- Skip style nits unless they hide bugs.
- Quote the file:line you're referring to.
</guidelines>

<context>
<source-file path="src/auth.ts">
... full file pasted here ...
</source-file>
</context>

The Claude prompt convention

Claude is trained to recognize XML-tagged sections as structured prompt blocks. Instead of writing

You are a code reviewer.

Your guidelines:
1. Flag security issues
2. Skip style nits
3. Quote file:line

Now review this code:
[code paste]

Claude does measurably better with

<instructions>
You are a code reviewer.
</instructions>

<guidelines>
- Flag security issues
- Skip style nits
- Quote file:line
</guidelines>

<code-to-review>
... paste here ...
</code-to-review>

The tags give Claude unambiguous structure cues that survive long-context distractions and prompt-injection attempts in user content.

FAQ

Why does Claude prefer XML tags?
Anthropic's training data heavily uses XML for structured prompts. Tags like <instructions>, <context>, <example> are reliable signals to Claude about prompt sections — more reliable than markdown headings or numbered lists.
Are there reserved tag names?
There's no formal reserved list, but avoid system (it conflicts with Claude's system role), thinking (used by extended-thinking output), and tag names with whitespace. Use kebab-case or single words.
What if my content contains XML?
If the body contains </section> for some section, Claude may close the tag early. Either rename the wrapping tag, escape the inner content as a CDATA-like block, or use distinct tag names that won't collide.
Does GPT / Gemini benefit from XML tags?
Less than Claude does. GPT prefers markdown headings; Gemini is more flexible. For cross-provider prompts, markdown is safer.

Common pitfalls

  • Using markdown headings (##) instead of XML — works fine for GPT, less reliable for Claude.
  • Including content that contains the closing tag of its wrapping tag.
  • Reusing tag names where one block contains another (e.g., a section inside a section) — use distinct names.
  • Treating XML structure as a security boundary. It isn\'t — it\'s a hint to the model. Adversarial input still needs validation.

Related tools