Magic Tools
AI TutorialsBy CooconMarch 29, 20266858 views2 min read

Claude XML Tags Guide: Structure Prompts for Better Output

XML tags are one of the most useful structure tools in Anthropic's prompt engineering guidance. They help Claude separate instructions, examples, context, and output constraints so the model does not mix them together.

The main advantage is not flashy. It is reliability. When your prompt has several moving parts, a clear structure makes it much easier for Claude to interpret the request correctly.

Why XML tags help

Use XML tags when a prompt has multiple sections or when you want predictable parsing:

  • Separate instructions from source material
  • Mark examples clearly
  • Isolate output format requirements
  • Make complex prompts easier to edit later

You do not need exotic tag names. Use names that match the content and stay consistent across prompts.

A simple pattern

<instructions>
Rewrite the note for a leadership audience.
</instructions>

<context>
This is a weekly project update for executives.
</context>

<output_format>
Use 3 bullets: status, risk, next step.
</output_format>

That structure gives Claude a clean map of the task. It also helps you read the prompt later and see what each part does.

Best practices

Anthropic's docs emphasize a few practical habits:

  1. Keep tag names consistent.
  2. Use tags to separate different kinds of content.
  3. Nest tags when the structure is hierarchical.

For example:

<contract>
  <section>...</section>
  <section>...</section>
</contract>

This is especially helpful when you are feeding Claude long source material and want the output to stay aligned with the input.

When to combine XML with other techniques

XML tags work well with both examples and reasoning prompts. Anthropic specifically recommends combining tags with multishot prompting or chain-of-thought style prompts when that structure makes the task clearer.

A good pattern is:

  • Use <examples> for sample outputs
  • Use <thinking> for intermediate reasoning
  • Use <answer> for the final result

That separation is useful when you want to inspect or post-process only part of the output.

Practical example

<instructions>
Summarize the following customer feedback for the product team.
</instructions>

<feedback>
[paste the raw feedback here]
</feedback>

<output_format>
Return:
1. Overall sentiment
2. Main complaint
3. One suggested action
</output_format>

This prompt is easier for Claude to follow than a paragraph of mixed instructions because the structure does the organizing for you.

Common mistakes

  • Using tag names that are too vague
  • Putting everything into one tag and losing the benefit
  • Mixing instructions and data without boundaries
  • Assuming tags are magic on their own

XML tags improve clarity, but they do not replace good prompt design. You still need specificity, context, and a clear final goal.

Bottom line

If your Claude prompts are getting longer or more complicated, XML tags are one of the cleanest ways to keep them organized. They reduce ambiguity, make prompts easier to maintain, and pair well with examples and reasoning prompts.

Official References

Sources reviewed on March 29, 2026. Prompting behavior and best practices may evolve, so confirm the latest details in the linked Anthropic pages.

Related Articles

Claude's Aug 24 Outage: Elevated Errors Hit Opus 5, Fable 5, Mythos 5 for 2h46m

Full recap of the Aug 24 Claude API outage: elevated errors from 04:50–07:36 UTC across Claude Mythos 5, Fable 5, Opus 5 and Opus 4.8, hitting claude.ai, the API, Claude Code and Cowork. Includes the verbatim status-page timeline and tips for developers.

claudeapi+3
ai-tutorialsAug 25, 20263 min
265

OpenAI Didn't Cut the Price: GPT-5.6 Sol's 50% Off Expires September 18 and Excludes BYOK

GPT-5.6 Sol dropped from $5/$30 to $2.50/$15 on OpenRouter. The 50% is real, but three qualifiers went missing in transit: this is a platform-side promotion from OpenRouter and Vercel AI Gateway, with OpenAI's own pricing page still showing $5/$30; it expires September 18; and BYOK requests don't get it. SemiAnalysis raised a sharper question — these two platforms are a negligible share of OpenAI's volume but happen to be the main public data source for estimating model market share. Here's a same-source price table for 17 models, the 272K long-context pricing cliff, and a checklist for deciding whether to switch.

claudeopenai+6
ai-tutorialsAug 19, 20269 min
321

Claude Designed Proteins From Scratch — And the Prompt Is Public

Anthropic handed Claude a 30,000-token prompt, a GPU budget, and 15 protein targets, then walked away. It hit 14 of them at more than double the field's typical success rate, verified in two independent wet labs. The prompt and every data point are now on HuggingFace.

claudeanthropic+5
ai-tutorialsAug 19, 202612 min
351

Dario Amodei on the AI Backlash: 'Fundamentally a Crisis of Trust'

Told by an investor to be a more positive advocate for his own industry, Anthropic's CEO broke his usual social media silence with a long rebuttal. His core claim: the public's hostility toward AI wasn't manufactured by risk warnings — it's decades of accumulated distrust finally arriving at AI's door.

anthropicopen-source+4
ai-tutorialsAug 18, 202611 min
203

Published by Magic Tools