Blog
Wild & Free Tools

XML Tags in System Prompts (the Claude Pattern)

Last updated: April 2026 6 min read

Table of Contents

  1. Why XML works for Claude
  2. Common tag conventions
  3. A working example
  4. Nesting and hierarchy
  5. GPT and Gemini
  6. When XML does not help

Anthropic's official documentation tells you to use XML tags to structure your Claude system prompts. Most developers see this and ignore it because XML feels old. They are leaving free quality on the table. Claude is trained to respect XML tag boundaries, and using them produces measurably better adherence to your instructions. This guide is the why and the how.

The free system prompt generator structures output in a way that converts cleanly to XML for Claude.

Why XML Works for Claude Specifically

Anthropic trained Claude on a corpus that included a lot of XML-tagged content (technical documentation, structured datasets, instruction-tuning examples with explicit tags). As a result, Claude treats XML tags as strong section boundaries — it knows that content inside <rules> is rules, content inside <persona> is persona description, and so on.

The same content presented as plain English headings produces noticeably worse adherence. The model has to guess where each section ends. With XML tags, it does not have to guess.

Common Tag Conventions

There is no official Anthropic-mandated tag list. The community has converged on these:

You can invent your own tags too. Claude will respect any sensible tag name as long as you use it consistently.

A Working XML Example

<persona>

You are Ada, a customer support assistant for Acme Corp. Acme sells project management software for small teams.

</persona>

<capabilities>

You answer questions about Acme features, pricing, billing, and account settings. You troubleshoot common issues using the knowledge base.

</capabilities>

<rules>

- Stay on topic. Politely redirect off-topic questions.

- Admit when you don't know something. Never invent features.

- Use a friendly, professional tone.

- Keep responses under 100 words unless the user asks for detail.

</rules>

Same content as a plain-text prompt, but with XML structure. Claude treats this as much more authoritative.

Sell Custom Apparel — We Handle Printing & Free Shipping

Nesting Tags for Hierarchy

You can nest XML tags to express hierarchy: <rules><tone>Friendly</tone><length>Under 100 words</length></rules>

Use sparingly. Two levels deep is the practical limit before the prompt becomes hard to read. If you find yourself nesting four levels, your prompt is probably overcomplicated.

Does This Work for GPT and Gemini Too?

Yes, partially. GPT-4o and Gemini both respect XML tags reasonably well even though they were not explicitly trained on the same XML-heavy corpus as Claude. The improvement is smaller than for Claude but still positive. If you write your prompt with XML tags and need to deploy to multiple providers, you do not need to rewrite for each one — the same XML-structured prompt works on all three.

The reverse is not as true. JSON-structured or markdown-headed prompts work fine for GPT and Gemini but may underperform on Claude.

When XML Does NOT Help

For very short system prompts (under 100 tokens), XML tags add overhead without much benefit. The model can hold a 50-token prompt in attention easily — structure does not matter. Reserve XML structure for prompts over 200 tokens where the model benefits from clear section boundaries.

Generate an XML-Structured Prompt

Output organized into clear sections, ready to wrap with XML tags.

Open System Prompt Generator
Launch Your Own Clothing Brand — No Inventory, No Risk