8 ms·
Why XML tags are so fundamental to Claude
- TheJoeMan 7mo agoThat first image, “Structure Prompts with XML”, just screams AI-written. The bullet lists don’t line up, the numbering starts at (2), random bolding. Why would anyone trust hallucinated documentation for prompting? At least with AI-generated software documentation, the context is the code itself, being regurgitated into bulleted english. But for instructions on using the LLM itself, it seems pretty lazy to not hand-type the preferred usage and human-learned tips.
- Calavar 7mo agoIt looks like a screenshot from the Claude desktop app, so I don't think the author is trying to disguise the AI origin of the marerial
- TheJoeMan 7mo agoI'm sorry for not elaborating. My original complaint is with Anthropic! The article is about how Anthropic's published "tips" are incorrect, but I am saying of course it's flawed because there is no way for the AI to already have latent knowledge about how to use itself since that wouldn't have been part of the internet/books/github training material.
- rafram 7mo agoNo, it’s two screenshots from Anthropic documentation, stitched together: https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices https://platform.claude.com/docs/en/build-with-claude/prompt... The post even links to that page, although there’s a typo in the link.
- dmd 7mo agoThey're not even stitched together ; there's just no padding between the two images.
- glth 7mo agoAuthor here: I have just fixed the typo. Thank you. And yes, these are screenshots from Anthropic’s documentation.
- TheJoeMan 7mo agoI'm sorry for not elaborating. My original complaint is with Anthropic! The 7-figure Anthropic engineers couldn't be bothered to write down how to use their tool. And there is no way for the tool to already have latent knowledge about how to use itself since that wouldn't have been part of the internet/books/github training material.
- rafram 7mo agoThanks, that makes sense!
- croes 7mo agoYou just hallucinated the content is AI generated.
- michaelcampbell 7mo ago"This is AI" is the new "This is 'shopped, I can tell by the pixels."
- tingletech 7mo agoI can tell by the em dashes
- doctorpangloss 7mo agoThere must be an OpenClaw YouTube video helping people post to hacker news, or something, because the front page is overrun with AI slop like this article, that makes no sense anyway. The author literally has no idea what any of this stuff means.
- wolttam 7mo agoAnthropic’s tool calling was exposed as XML tags at the beginning, before they introduced the JSON API. I expect they’re still templating those tool calls into XML before passing to the model’s context
- pocketarc 7mo agoYeah like I remember prior to reasoning models, their guidance was to use <think> tags to give models space for reasoning prior to an answer (incidentally, also the reason I didn't quite understand the fuss with reasoning models at first). It's always been XML with Anthropic.
- wolttam 7mo agoExactly the same story here. I still use a tool that just asks them to use <think> instead of enabling native reasoning support, which has worked well back to Sonnet 3.0 (their first model with 'native' reasoning support was Sonnet 3.7)
- scotty79 7mo agoCan you sniff it out with Wireshark?
- wolttam 7mo agoThey don't expose the raw context over the wire, it's all pre/post processed at their API endpoints.
- imglorp 7mo agoA very minor porcelain on some of the agent input UX could present this structure for you. Instead of a single chat window, have four: task, context, constraints, output format. And while we're at it, instead of wall-of-text, I also feel like outputs could be structured at least into thinking and content, maybe other sections.
- deleted 7mo ago[deleted]
- kvirani 7mo agoYou're on to something here. Can we go more meta and define these dynamically such that users can customize multiple output streams?
- Zebfross 7mo agoI thought the goal was minimal instruction to let Claude determine the best way to solve the problem. Not adding this to my workflow anytime soon.
- TheLNL 7mo agoIt is not for the end user, it is more for things like wrappers and automation scripts. Nobody expects the end user to prompt the AI using a structured language like xml
- esafak 7mo agoThis sounds like something for harnesses, not end users. Are they really expecting us to format prompts as XML??
- nimbus-hn-test 7mo ago[dead]
- apwheele 7mo agoI think XML is good to know for prompting (similar to how <think></think> was popular for outputs, you can do that for other sections). But I have had much better experience just writing JSON and using line breaks, colons, etc. to demarcate sections. E.g. instead of <examples> <ex1> <input>....</input> <output>.....</output> </ex1> <ex2>....</ex2> ... </examples> <instructions>....</instructions> <input>{actual input}</input> Just doing something like: ...instructions... input: .... output: {..json here} ...maybe further instructions... input: {actual input} Use case document processing/extraction (both with Haiku and OpenAI models), the latter example works much better than the XML. N of 1 anecdote anyway for one use case.
- ekjhgkejhgk 7mo agoCould you clarify, do those tags need to be tags which exist and we need to lear about them and how to use them? Or we can put inside them whatever we want and just by virtue of being tags, Claude understands them in a special way?
- ezfe 7mo agoThey probably don’t need to be specific values. The model is fine tuned to see the tags as signals and then interprets them
- galaxyLogic 7mo agoIf it walks like a duck ... AI thinks it is something like a duck.
- apwheele 7mo agoAll the major foundation models will understand them implicitly, so it was popular to use <think>, but you could also use <reason> or <thinkhard> and the model would still go through the same process.
- cyanydeez 7mo ago
- michaelcampbell 7mo agoTotal tangent, but what vagary of HTML (or the Brave Browser, which I'm using here) causes words to be split in very odd places? The "inspect" devtools certainly didn't show anything unusual to me. (Edit: Chrome, MS Edge, and Firefox do the same thing. I also notice they're all links; wonder if that has something to do with it.) https://i.imgur.com/HGa0i3m.png https://i.imgur.com/HGa0i3m.png
- werdnapk 7mo agoCSS on the <a> tags: word-break: break-all;
- deleted 7mo ago[deleted]
- fancy_pantser 7mo agoCSS word-break property
- knallfrosch 7mo agoIt's an error in the site's CSS. CSS has way better methods, like splitting words correctly depending on the language and hyphenating it. Although I can never remember the correct incantation, should be easy for LLMs.
- rosstex 7mo agoAsk Claude?
- twoodfin 7mo agoThis isn’t surprising: XML’s core purpose was to simplify SGML for a wider breadth of applications on the web. HTML also descended from SGML, and it’s hard to imagine a more deeply grooved structure in these models, given their training data. So if you want to annotate text with semantics in a way models will understand…
- tingletech 7mo agoXML and HTML are SGMLs
- ChrisSD 7mo agoHTML diverged from SGML pretty early on. Various standards over the years have attempted to specify it as an application of SGML but in practice almost nobody properly conformed to those standards. HTML5 gave up the pretence entirely.
- alansaber 7mo agoSounds like as 1. XML is the cleanest/best quality training data (especially compared to PDF/HTML) 2. It follows that a user providing semantic tags in XML format can get best training alignment (hence best results). Shame they haven't quantified this assertion here.
- lsc4719 7mo agoMakes sense
- kid64 7mo agoThe thesis here seems to be that delimiters provide important context for Claude, and for that putpose we should use XML. The article even references English's built-in delimiter, the quotation mark, which is reprented as a token for Claude, part of its training data. So are we sure the lesson isn't simply to leverage delimiters, such as quotation marks, in prompts, period? The article doesn't identify any way in which XML is superior to quotation marks in scenarios requiring the type of disambiguation quotation marks provide. Rather, the example XML tags shown seem to be serving as a shorthand for notating sections of the prompt ("treat this part of the prompt in this particular way"). That's useful, but seems to be addressing concerns that are separate from those contemplated by the author.
- jinushaun 7mo agoExcept quotation marks look like regular text. I regularly use quotes in prompts for, ya know, quotes.
- wolttam 7mo agoThe GP isn't suggesting to literally use quotes as the delimiter when prompting LLMs. They're pointing out that we humans already use delimiters in our natural language (quotation marks to delimit quotes). They're suggesting that delimiters of any kind may be helpful in the context of LLM prompting, which to me makes intuitive sense. That Claude is using XML is merely a convention.
- deleted 7mo ago[deleted]
- sheept 7mo agoXML is a bit more special/first class to Claude because it uses XML for tool calling: <antml:invoke name="Read"> <antml:parameter name="file_path">/path/to/file</antml:parameter> <antml:parameter name="offset">100</antml:parameter> <antml:parameter name="limit">50</antml:parameter> </antml:invoke> I'm sure Claude can handle any delimiter and pseudo markup you throw at it, but one benefit of XML delimiters over quotation marks is that you repeat the delimiter name at the end, which I'd imagine might help if its contents are long (it certainly helps humans).
- Eric_WVGG 7mo agobemused by how competently designed this is, compared to enshittified blogs and whatnot To be realistic, this design needs more weirdly sexual etsy garbage, “one weird tip,” and “punch the monkey”
- CactusBlue 7mo agoI think the main advantage of the XML here is that the model is expected to have a matching end tag that is balanced, which reduces the likelihood of malformed outputs.
- RadiozRadioz 7mo ago> a contrast between Claude’s modern approach [...] XML, a technology dating back to 1998 Are we really at the point where some people see XML as a spooky old technology? The phrasing dotted around this article makes me feel that way. I find this quite strange.
- intrasight 7mo agoYup. Kids these days...
- coldtea 7mo agoXML has been "spooky old technology" for over a decade now. It's heyday was something like 2002. Nobody dares advertise the XML capabilities of their product (which back then everybody did), nobody considers it either hot new thing (like back then) or mature - just obsolete enterprise shit. It's about as popular now as J2EE, except to people that think "10 years ago" means 1999.
- cyanydeez 7mo ago20 years old means 1980!
- vlovich123 7mo agoFor me, even when it was first released, I considered obsolete enterprise shit. That view has not diminished as the sorry state of performance and security in that space has just reaffirmed that perception.
- himata4113 7mo agodidn't know html was spooky tech, TIL. /s
- coldtea 7mo agoHTML predates XML by 5 years. What's more, the web standards bodies even abandoned a short-lived XML-hype-era plan to make a new version of HTML based on XML in 2009. That from this touted to the heavens format a handful of uses remain (some companies still using SOAP, the MS Office monster schemas, RSS, EPUB, and so on) is the very opposite of the adoption it was supposed to have. For those that missed the 90s/early 00s, XML was a hugely hyped format, with enormous corporate adoption between 1999–2005, which deflated totally. Did you also learned those things too today?
- ixxie 7mo agoHow about other frontier models, and smaller models?
- TutleCpt 7mo agoI think this article is 100% relevant to you today. Anthropic put out a training video, a number of months ago saying that XML should be highly encouraged for prompts. See https://m.youtube.com/watch?v=ysPbXH0LpIE https://m.youtube.com/watch?v=ysPbXH0LpIE
- strongpigeon 7mo agoThis seems like an actual good use for XML. Using it as a serialization format always rubbed me the wrong way (it’s super verbose, the named closing tag are unnecessary grammar-wise, the attribute-or-child question etc.) But to markup and structure LLM prompts and response it feels better than markdown (which doesn’t stream that well)
- Lerc 7mo agoI am unconvinced. To me it seems like handling symbols that start and end sequences that could contain further start and end symbols is a difficult case. Humans can't do this very well either, we use visual aids such as indentation, synax hilighting or resort to just plain counting of levels. Obviously it's easy to throw parameters and training at the problem, you can easily synthetically generate all the XML training data you want. I can't help but think that training data should have a metadata token per content token. A way to encode the known information about each token that is not represented in the literal text. Especially tagging tokens explicitly as fiction, code, code from a known working project, something generated by itself, something provided by the user. While it might be fighting the bitter lesson, I think for explicitly structured data there should be benefits. I'd even go as far to suggest the metadata could handle nesting if it contained dimensions that performed rope operations to keep track of the depth. If you had such a metadata stream per token there's also the possibility of fine tuning instruction models to only follow instructions with a 'said by user' metadata, and then at inference time filter out that particular metadata signal from all other inputs. It seems like that would make prompt injection much harder.
- scotty79 7mo agoTransformers look like perfect tech for keeping track of how deep and inside of what we are at the moment.
- thesz 7mo agoTransformers are able to recognize balanced brackets grammar at 97% success rate: https://openreview.net/pdf?id=kaILSVAspn https://openreview.net/pdf?id=kaILSVAspn This is 3% or infinitely far away from the perfect tech. The perfect tech is the stack.
- krackers 7mo agoThis is very interesting since there is another notable paper which shows LLMs can recognize and generate CFGs https://arxiv.org/abs/2305.13673 https://arxiv.org/abs/2305.13673 and of course a^n b^n is also classic CFG, so it's not clear why one paper had positive results while the other hand negative.
- ryanschneider 7mo agoWait am I in the minority talking to Claude in markdown? I just assumed everyone does that, or at least all developers. It seems to work really well.
- cyanydeez 7mo agoI do that in openwebui for code indents like ```
- prima-facie 7mo agoAmazing how an entire profession that until yesterday would pride itself on precision, clarity (in thought and in writing), efficiency, and formality, has now descended into complete quackery.
- cyanydeez 7mo agoAre you talking about the office of the president of the united states? This vague posting is kind dumb.
- prima-facie 7mo agoIt's a simple observation. I'm not here to win internet points. I've never before seen so much cargo-culting and mystic belief among engineers.
- OutOfHere 7mo agoI can understand the benefit from XML if there is a at least a three-level variable structure to share with the LLM. If there is strong consistency in a repeated three or more level structure, then JSON ought to be sufficient. If there is just a one or two level structure, it feels like unnecessary quackery, possibly reflective of a poorly trained model if the structure is a genuine necessity.
- spacecadet 7mo agoThis has been the way for a long time, exploiting XML tags was a means of exfiltrating data or reversing a model for a while as well. Some platforms are still vulnerable to this.
- lmeyerov 7mo agoMy intuition is it comes down to error-correcting codes. We're dealing with lossy systems that get off track, so including parity bits helps. Ex: <message>...</message> helps keep track. Even better? <message78>...</message78>. That's ugly xml, but great for LLMs. Likewise, using standard ontologies for identifiers (ex: we'll do OCSF, AT&CK, & CIM for splunk/kusto in louie.ai), even if they're not formally XML. For all these things... these intuitions need backing by evals in practice, and part of why I begrudgingly flipped from JSON to XML
- Jcampuzano2 7mo agoBut should this extend to anything that could end up in Claudes context? Should we be using xml even in skills for instance, or commands, custom subagents etc. And then do we end up over indexing on Claude and maybe this ends up hurting other models for those using multiple tools. I just dislike how much of AI is people saying "do this thing for better results" with no definitive proof but alas it comes with the non determinism. At least this one has the stamp of approval by Claude codes team itself.
- hkbuilds 7mo agoThis matches my experience building AI-powered analysis tools. Structured output from LLMs is dramatically more reliable when you give the model clear delimiters to work with. One thing I've found: even with XML tags, you still need to validate and parse defensively. Models will occasionally nest tags wrong, omit closing tags, or hallucinate new tag names. Having a fallback parser that extracts content even from malformed XML has saved me more than once. The real win is that XML tags give you a natural way to do few-shot prompting with structure. You can show the model exactly what shape the output should take, and it follows remarkably well.
- docjay 7mo ago“It works great aside from the multiple failure modes.” ;) That’s the sign that your prompt isn’t aligned and you’ve introduced perplexity. If you look carefully at the responses you’ll usually be able to see the off-by-one errors before they’re apparent with full on hallucinations. It’ll be things like going from having quotes around filenames to not having them, or switching to single quote, or outputting literal “\n”, or “<br>”, etc. Those are your warning signs to stop before it runs a destructive command because of a “typo.” My system prompt is just a list of 10 functions with no usage explanations or examples, 304 tokens total, and it’ll go all the way to the 200k limit and never get them wrong. That took ~1,000 iterations of name, position, punctuation, etc., for Opus 4.6 (~200 for Opus 4.5 until they nerfed it February 12th). Once you get it right though it’s truly a different experience.
- kleyd 7mo agoThe main benefit of using XML here seems to be that it forces clearer thinking and formulation from the user.
- TacticalCoder 7mo agoIt'd be hilarious if XML schemas and validators were to make a comeback [1] to... interface with AI models. [1] well of course XML is still heavily used in stuff like interfacing with automated wire transfers with big banks (at least in Europe) and all the digital payments directives etc. But XML is not widely used by the "cool" stuff.
- muzani 7mo agoIn the spirit of Hacker News, a good way to learn about these tags is prompt injection and jailbreaking Claude. I'd post a link, but unfortunately many are highly NSFW. Just search for "Claude jailbreak" on reddit or something. You'll start to see how Claude really thinks. They'll put things in <ethic_reminders>, <cyber_warning> or <ip_reminder>. You could actually even snip these off in an API, overwrite them, or if your prompt-fu is good, convince Claude that these tags are prompt injections. It's also interesting noting how jailbreaking is easier on thinking mode because the jailbreaking prompts will gaslight Claude into thinking that these tags are attacks. There's a lot of speculation in this thread, but go and have a spar with Claude instead.
- krackers 7mo agoAll system prompts are already wrapped in specific role markers (each LLM has its own unique format), so I'm sure every lab is familiar with the concept of delimters, in-band vs out-of-band signalling and such. It'd not clear why within any section XML markers would do better than something like markdown, other than claude being explicitly post-trained with XML prompts as opposed to markdown. One hypothesis could be that since a large portion of the training corpus is websites, XML is more natural to use since it's "learned" the structure of XML better than markdown. Another could be that explicit start/end tags make identifying matching delimiters easier than JSON (which requires counting matching brackets) or markdown (where the end of a section is implicitly defined by the presence of a new header element).
- thethimble 7mo agoPerhaps named closing tags like `</section>` are a factor?
- ashirviskas 7mo agoAuthor does not know what they're talking about. > In other words, XML tags have not only a special place at inference level but also during training Their cited source has 0 proof of that. It's just like python/C/html in training. Doesn't mean it's special. And no, you don't need to format your prompts as python code just because of that. > In truth, it does not matter that these tags are XML. Other models use ad hoc delimiters (as explained in a previous article; example: <|begin_of_text|> and <|end_of_text|>) and Claude could have done the same. What matters is what these tags represent. Those strings are just representations of special tokens in models for EOS. What does it have to do with anything this article pretends to know about? Please don't post such intellectual trash on here :') Claude analysis of the article: The author is making an interesting philosophical argument — that XML tags in Claude function as metalinguistic delimiters analogous to quotation marks in natural language, formulaic speech markers in Homer, or recognition sequences in DNA. The core thesis is about first-order vs. second-order expression boundaries, which is a legitimate linguistic/information-theory concept. But to your actual question — do they understand what tokens are? No, not in the technical sense you're pointing at. The article conflates two very different things: 1. Tokenizer-level special tokens — things like <|begin_of_text|>, <|end_of_text|>, <|start_header_id|> etc. These are literal entries in the vocabulary with dedicated token IDs. They're not "learned" through training in the same way — they're hardcoded into the tokenizer and have special roles in the attention mechanism during training. They exist at a fundamentally different layer than XML tags in prompt text. 2. XML tags as structured text within the input — these are just regular tokens (<, instructions, >) that Claude learned to attend to during RLHF/training because Anthropic's training data and system prompts heavily use them. They're effective because of training distribution, not because they occupy some special place in the tokenizer. The author notices that other models use <|begin_of_text|> style delimiters and says Claude "could have done the same" but chose XML instead. That's a category error. Claude also has special tokens at the tokenizer level — XML tags in prompts are a completely separate mechanism operating at a different abstraction layer. The philosophical observation about delimiter necessity in communication systems is fine on its own. But grafting it onto a misunderstanding of how tokenization and model architecture actually work weakens the argument. They're essentially pattern-matching on surface-level similarities (both use angle brackets!) without understanding the underlying mechanics.
- arbirk 7mo agoIf this is true, the why does Claude Code's own system prompt not use this style? https://github.com/Piebald-AI/claude-code-system-prompts/tree/main https://github.com/Piebald-AI/claude-code-system-prompts/tre...
- its-summertime 7mo agohttps://github.com/Piebald-AI/claude-code-system-prompts/blob/ac9c00804a9625b34234e9fb910b2bc7290804c2/system-prompts/agent-prompt-agent-creation-architect.md?plain=1#L42-L59 https://github.com/Piebald-AI/claude-code-system-prompts/blo... They seem to use XML-esque tags here in the first prompt I looked at
- arbirk 7mo agoYes, but that is for a specific JSON format. The instructions are in md