XML prompting: use XML-like tags to delineate sections of a prompt (<document>, <instructions>, <example>). Popularized by Anthropic; well-supported by Claude in particular. Reduces prompt-injection risk and improves adherence to structure.
- 01Structure a prompt with XML tags.
- 02State why XML helps model attention.
- 03Explain why XML is not just for Claude.
The pattern
Wrap content in tags: <document>...</document>, <instructions>...</instructions>. Reference tags in instructions ('summarize the content in <document>'). The tags act as anchors that make the prompt structure legible to the model.
Why it helps
Frontier models are trained on structured web data with XML/HTML markup. Structured tags map to patterns the model has seen millions of times. Adherence improves; injection resistance improves; extraction of specific sections improves.
- XML tags give the model unambiguous structure.
- Anthropic-native but works across providers.