Why XML Tags Are So Fundamental to Claude
Original: Why XML tags are so fundamental to Claude View original →
The Curious Case of XML and Claude
Developers who work extensively with Claude have noticed something: XML tags work noticeably better than other delimiters like quotes, backticks, or markdown. This Hacker News post (154 points) digs into why — and the answer is rooted in how Claude was trained.
XML in Claude's Training
Anthropic used XML-structured data extensively throughout Claude's training pipeline. System prompts, tool use, and internal reasoning are all structured with XML tags. Claude's tool use feature relies on XML structures, and Anthropic's official prompt engineering guidelines actively recommend tags like <context>, <document>, and <thinking>.
Three Reasons XML Tags Excel
- Unambiguous boundaries: Unlike quotes or backticks, XML tags carry semantic meaning in their names. <examples> tells the model what kind of content it contains, not just that it's a delimited block.
- Natural nesting: XML nests cleanly, allowing complex prompts to be structured hierarchically. This pattern appears abundantly in Claude's training data.
- Prompt injection defense: Clearly wrapping user input in <user_input> tags creates a reliable semantic boundary that makes it harder for malicious content to blend with system instructions.
Practical Implications
Anthropic's official prompt engineering guide explicitly recommends XML tags when handling long documents, multiple examples, or complex instruction sets. This is not a stylistic preference — it reflects an architectural reality about how Claude processes structured text. When in doubt, wrapping distinct sections of your prompt in semantically meaningful XML tags will almost always improve Claude's comprehension of the intended structure.
Related Articles
A deep-dive into why XML tags work better than other delimiters with Claude — rooted in how Anthropic structured Claude's training data and the model's extensive exposure to XML-structured prompts throughout fine-tuning.
Hacker News focused on the ambiguity around Claude CLI reuse: even if OpenClaw now treats the path as allowed, developers still want a clearer boundary between subscription, CLI, and API usage.
Anthropic put hard numbers behind Claude’s election safeguards. Opus 4.7 and Sonnet 4.6 responded appropriately 100% and 99.8% of the time in a 600-prompt election-policy test, and triggered web search 92% and 95% of the time on U.S. midterm-related queries.
Comments (0)
No comments yet. Be the first to comment!