The Practical Guide to XML Prompt Engineering for Claude
If you've been working with Anthropic's Claude, you might have noticed a recurring recommendation in their prompt-engineering docs: using XML tags. But when should you actually use them, and when are they just getting in the way? Claude XML isn't actual, validated XML. It’s a practical convention of wrapping parts of a prompt in named tags—like <instructions> , <context> , <example> , and <document> —so Claude can reliably distinguish the role of each section. Because Claude was trained on prompts formatted this way, it's highly effective for resolving structural ambiguity. Here is a breakdown of when to use it, when to avoid it, and some practical patterns to get you started. When XML Actually Helps (And When It Doesn't) You don't need XML for everything. In fact, slapping tags on every prompt wastes tokens and adds visual noise. The golden rule: XML helps when your prompt mixes instructions, context, examples, and variable inputs. Her...