<claudexml/>

Claude XML FAQ

Quick answers to the questions developers ask first.

What is Claude XML?

Claude XML is the convention of structuring prompts to Anthropic's Claude using XML-style tags (like <instructions>, <context>, <example>) to separate the parts of a prompt. Claude was trained with these patterns and follows them reliably.

Are XML tags required to prompt Claude?

No. Claude works without them. Anthropic's docs recommend them "especially when your prompt mixes instructions, context, examples, and variable inputs" — i.e., they meaningfully improve consistency on non-trivial prompts, but a one-line question doesn't need scaffolding.

Is XML still relevant in 2026?

Yes, but with caveats. Anthropic's prompt-engineering docs (verified May 2026) still recommend XML tags for structured prompts. What's changed since the early Claude era: some uses are now better served by API features. Tool use is stronger than <format> for JSON output; the API system parameter is stronger than inline <role>; extended thinking on Claude 3.7+ replaces manual <thinking> tags. XML is still the right tool for splitting documents/examples/instructions in a single prompt and for multi-artifact outputs.

Do I need XML for a chat conversation?

No. Conversational chat (claude.ai, multi-turn dialogue) already establishes roles. Wrapping your message in <question> adds tokens and visual noise without helping the model. Save tags for repeatable programmatic prompts where structure is load-bearing.

Is this real XML?

No. There's no schema, no validation, no parser. Tags are a convention Claude treats as structure. Closing tags are still important — mismatched tags confuse the model.

Which XML tags does Claude officially support?

There is no official allowlist. Anthropic's docs use <instructions>, <context>, <example>/<examples>, <document>/<documents>, <source>, <thinking>, <answer>, <format> consistently. Custom tags work fine if their names are clear.

Should I use XML tags or the API's system parameter?

Both, for different jobs. Put the persona and stable directives in the system parameter — that's stronger than an inline <role>. Use XML inside the user message to structure dynamic content: documents, examples, the question.

Should I use XML tags or tool use for structured output?

Tool use is stronger in 2026. If you can define a tool, prefer it. XML coercion (<format> + "return only this inside <result>") is the right fallback when you can't or don't want to set up tool use — and on Bedrock/Vertex with older API surfaces.

Should I use <thinking> tags with Claude's extended thinking enabled?

Pick one. Extended thinking (Claude 3.7+ via the API's thinking parameter) is the model's native reasoning channel. Adding a <thinking> tag on top creates a second scratchpad that can fight the internal one — sometimes silently degrading output. If extended thinking is on, drop the manual tag. If it's off and you want reasoning, use the tag.

Where should I put long documents — before or after the instructions?

Before. Anthropic's guidance: large reference material first, then instructions, then the question. Claude attends more strongly to instructions placed closer to the query.

Can Claude be tricked by XML in user input?

Yes. If you splice user input into a prompt without escaping, the user can inject closing tags like </instructions> and break your scaffolding. Sanitize: escape angle brackets or strip XML-like sequences from untrusted input.

Do XML tags increase token cost?

Slightly. A few tags add tens of tokens, not hundreds. The quality gain almost always justifies the cost on real tasks.

Can I nest XML tags?

Yes, when the semantics imply containment: <source> inside <document>, <example> inside <examples>. Don't nest things that are logically peers — keep major sections as siblings.

How many few-shot examples should I include?

2–5 in almost all cases. One example often doesn't carry the pattern; more than five rarely helps and burns context.

Why does Claude wrap my JSON in markdown fences?

Default behavior on prose-style prompts. Fix: explicitly say "return only the JSON object, no prose, no markdown fences" or wrap the output in <result> tags and extract from there.

Does this site work with Claude on Bedrock / Vertex AI?

Yes. The prompting conventions are identical regardless of where you call Claude — Anthropic API, AWS Bedrock, Google Vertex AI, or partner platforms. Only the surrounding API differs.

Can I cite this site?

Yes — every page includes a citation block. Stable URLs, content under the page byline (claudexml.com), last updated date is in the page metadata.

Cite this page
Claude XML FAQ. claudexml.com. https://claudexml.com/faq/