damngoodprompts

XML tags in prompts

When XML-style tags help a model parse context, and when they are just decoration.

Last reviewed: August 10, 2026

The concept

XML tags are plain text delimiters. They help when the model needs to distinguish instructions, documents, examples, and user inputs inside one long prompt. They do not make the prompt more powerful by themselves.

Claude’s docs specifically call out XML tags for structuring complex prompts. Other models can also follow clear delimiters, but the benefit comes from separation, not the angle brackets.

The current approach

Use tags when parts of the prompt have different jobs:

<instructions>
Review the contract for operational risk. Do not give legal advice.
</instructions>

<contract source="vendor-a.md">
{{contract_text}}
</contract>

<output>
Return blocking risks, non-blocking concerns, and missing facts.
</output>

The tags make maintenance easier because each section has one purpose. They also make it harder for pasted documents to blur into instructions.

When they help

Tags are most useful with long documents, multiple examples, retrieval packs, tool outputs, and prompts that mix stable instructions with variable data.

They are less useful for a two-sentence chat request. If the prompt naturally reads well without tags, keep it plain.

For a provider comparison where this matters, see Claude vs ChatGPT.

What to avoid

  • Wrapping every sentence in tags because a template said XML is “advanced.”
  • Using vague tag names like <stuff> or <context> when the section has a more specific job.
  • Forgetting to close tags in long generated prompts.
  • Letting tags hide a messy prompt. If the instructions conflict, XML will not fix them.

Source set