← ContentsPrompting · intermediate

XML tags

XML tags are a prompting technique where you wrap different sections of your prompt in descriptive markup elements—such as <instructions>, <context>, <document>, or <input>—to help Claude clearly distinguish between instructions, reference data, examples, and user content. By giving each type of content its own named container, you eliminate ambiguity about what Claude should treat as a command versus background information, reducing misinterpretation especially in long or complex prompts. This is not a special model feature or API setting you toggle on—it is simply standard XML syntax written directly into your system prompt or user messages. Claude has been trained to recognize and weigh these structural cues natively, so no additional configuration is required. The technique works across all Claude models and all subscription plans. The value of XML tags scales with prompt complexity. A short, simple prompt rarely needs them. But once your prompt combines instructions, multiple documents, few-shot examples, and variable user input, XML tags prevent 'context bleeding'—the failure mode where Claude cannot tell where one section ends and another begins—and make responses more consistent and easier to parse downstream.

When you’d use it

  • Separating instructions from variable user inputA developer builds a customer-support bot where the system instructions must not be confused with whatever the end user types. Wrapping the system rules in <instructions> and the user message in <user_query> ensures Claude never treats the customer's text as a command.
  • Multi-document legal or research analysisA legal team needs Claude to compare liability clauses across three contracts. Each contract is wrapped in a <document index='n'> tag with a <source> child tag, so Claude can cite which document each finding came from without mixing up the texts.
  • Structured output for downstream parsingAn engineering pipeline needs to extract specific fields from Claude's response programmatically. The prompt asks Claude to place each field inside a named tag (<total_revenue>, <net_income>), so the application can parse the response with a simple string or XML extractor rather than natural-language post-processing.
  • Few-shot prompting with consistent example formattingA content moderation system needs Claude to learn a labeling pattern from examples before classifying new inputs. Each example is wrapped in <example> tags containing <input> and <output> children, making the pattern visually and structurally unambiguous before the live <input> appears.
  • Agentic and multi-step reasoning workflowsA complex pipeline passes intermediate outputs from one prompt to the next. XML tags like <analysis>, <synthesis>, and <recommendations> separate each reasoning stage, making it easy to extract and inject specific sections between pipeline steps without re-parsing free text.

What changed recently

  • 2025-10The Prompt Improver tool launched in the Claude Console (console.anthropic.com). It automatically restructures prompts into XML-tagged sections as part of its drafting step. Anthropic's internal testing showed the tool increased classification accuracy by approximately 30% and brought word-count adherence to 100% on a summarization benchmark for prompts it restructured.
  • 2025Anthropic documentation consolidated XML tagging guidance into a dedicated 'Use XML tags to structure your prompts' page in the prompt engineering section, confirming the technique as a core best practice across the Claude 3.x and 4.x model families.
  • 2026-05Claude Opus 4.8 and Sonnet 4.6 released with extended context windows (up to 1,000,000 tokens for Opus 4.8). Anthropic documentation explicitly notes that XML tagging becomes especially important for maintaining coherence and preventing context confusion as prompts approach 100K+ tokens.
  • 2026-05Anthropic engineering blog published guidance on effective context engineering for AI agents, recommending XML tags as the primary structure for separating tool outputs, memory sections, and instructions in agentic prompts.
This is the short version

The full chapter has three worked examples, the common pitfalls, and the workflow that makes it pay — plus the other 84 features, kept current.

Get Claude Master — $97
CLAUDEMASTER
An independent publication.
Independent product. Not affiliated with or endorsed by Anthropic. “Claude” is a trademark of Anthropic, used here only to describe the subject of this manual.
© 2026 Claude Master — All rights reserved.