XML Tagging in Prompts: The Secret to Getting Better Output from Claude and GPT A developer shares a simple prompt-engineering trick: wrapping prompt sections in XML tags like and measurably improves output consistency from large language models such as Claude and GPT. The technique leverages models' familiarity with markup from training data, reducing ambiguity in multi-part prompts and simplifying programmatic parsing of responses. A simple structuring trick that turns messy, unpredictable LLM outputs into clean, reliable ones. If you've spent any time writing prompts for Claude, GPT, or any other large language model, you've probably hit this wall: your prompt works fine for a simple ask, but the moment you pack in multiple instructions — some context, a few examples, formatting rules, and the actual task — the model starts mixing things up. It answers the wrong part of the question. It ignores your formatting instructions. It treats your example output as part of the actual task. The fix is almost embarrassingly simple: wrap your prompt sections in XML tags. LLMs are trained on enormous amounts of code, documentation, and markup. XML and HTML syntax is deeply embedded in that training data, which means models are very good at recognizing where one tagged section ends and another begins. Unlike plain paragraphs — where the boundary between "here's my context" and "here's my instruction" is fuzzy — a tag creates an unambiguous boundary. Anthropic actually recommends this explicitly for Claude: wrapping distinct parts of a prompt instructions, context, examples, output format in tags like