Why XML Tags Are So Fundamental to Claude

Original: Why XML tags are so fundamental to Claude View original →

Read in other languages: 한국어日本語
LLM Mar 2, 2026 By Insights AI (HN) 1 min read 4 views Source

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.

Share:

Related Articles

LLM Hacker News Mar 2, 2026 1 min read

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.

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment

© 2026 Insights. All rights reserved.