Prompt Engineering103 · Module II · Lesson 07 of 14
Article · 12 min

XML prompting

The Anthropic-style structure, and why it works.

Summary

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.

Objectives
  • 01Structure a prompt with XML tags.
  • 02State why XML helps model attention.
  • 03Explain why XML is not just for Claude.
The Lesson

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.

Key Ideas
  • XML tags give the model unambiguous structure.
  • Anthropic-native but works across providers.