XML Prompting
XML prompting uses XML-style tags to structure prompts.
Introduction
XML prompting uses XML-style tags to structure prompts. Anthropic's Claude is trained to strongly respect XML tags — making it the most reliable delimiter style on Claude.
Beginner analogy: XML tags are bright neon highlighters around each section. Models can't miss what's where.
Learning objective: Apply XML Prompting in a TechLearningPRO AI product — with measurable output quality, token awareness, and failure modes you can explain in review.
Treat every prompt like production code: versioned, evaluated on a golden set, and shipped with guardrails. Prefer explicit roles, schemas, and stop conditions over vague adjectives.
Purpose of this lesson
Apply XML Prompting in a TechLearningPRO AI product — with measurable output quality, token awareness, and failure modes you can explain in review.
Understanding the topic
Core concepts to understand:
- Use semantic tags: <role>, <context>, <examples>, <format>.
- Tags can nest: <examples><example>...</example></examples>.
- Particularly powerful on Claude (per Anthropic docs).
- Combine with instruction: 'process content inside <input> tags'.
Step-by-step explanation
- State the user job XML Prompting must accomplish and the failure cost if the LLM drifts.
- Read the workflow diagram and map each box to system message, user turn, tools, or eval.
- Write the smallest correct prompt (or template) for a TechLearningPRO Orders / support scenario.
- Run a 10-case smoke eval: note hallucination, format break, and refusal edge cases.
Syntax reference
Visual workflow / architecture:
<task>Summarise the support ticket below.</task><rules><rule>Max 50 words.</rule><rule>Include urgency level.</rule></rules><input>{ticket_text}</input>
Informative example
Worked prompt sketch:
# TechLearningPRO prompt sketch — XML PromptingSystem: You are a careful assistant for a learning platform.User: Given order {{order_id}} with status {{status}}, explain the next safe action in ≤3 bullets.Constraints: no PII invention; cite only provided fields; JSON keys: summary, next_steps.
Real-world use
Anthropic's own prompting cookbook recommends XML for Claude. Most enterprise prompts on Claude use it.
Security implications
Prompts are a trust boundary. Untrusted input must never silently override system policy.
- Separate system instructions from user content; never concatenate raw tickets into system roles.
- Redact secrets and PII before they enter the prompt or logs.
- Add output validators / allowlists for actions that can mutate state or spend money.
Best practices
- Tag everything: input, examples, output, rules.
- Use lowercase tag names; close every tag.
- Combine XML with instructions referencing the tags.
Common mistakes
- Shipping a prompt with zero golden-set evals and hoping production traffic is kind.
- Stuffing the context window with unused docs instead of retrieving the right slice.
- Letting untrusted user text redefine system instructions (prompt injection).
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionQ1. Why is XML the preferred delimiter for Claude?+
Answer
2IntermediateQuestionQ2. Can you mix XML with JSON output?+
Answer
3IntermediateQuestionQ3. Risks of malformed XML in user input?+
Answer
4AdvancedQuestionQ4. How does XML differ from markdown sections?+
Answer
Hands-on exercise
Hands-on + interview drill:
- Ship a minimal evaluated prompt for XML Prompting with a JSON schema and 5 failing cases.
- Q1. Why is XML the preferred delimiter for Claude?
- Q2. Can you mix XML with JSON output?
- Q3. Risks of malformed XML in user input?
- Q4. How does XML differ from markdown sections?
Summary
XML Prompting is a production prompt skill: specify the job, constrain the output, and prove quality with evals — not with a single lucky chat.