Monday, 17 August 2026

The Practical Guide to XML Prompt Engineering for Claude

If you've been working with Anthropic's Claude, you might have noticed a recurring recommendation in their prompt-engineering docs: using XML tags. But when should you actually use them, and when are they just getting in the way?


Claude XML isn't actual, validated XML. It’s a practical convention of wrapping parts of a prompt in named tags—like <instructions>, <context>, <example>, and <document>—so Claude can reliably distinguish the role of each section. Because Claude was trained on prompts formatted this way, it's highly effective for resolving structural ambiguity.

Here is a breakdown of when to use it, when to avoid it, and some practical patterns to get you started.

When XML Actually Helps (And When It Doesn't)

You don't need XML for everything. In fact, slapping tags on every prompt wastes tokens and adds visual noise. The golden rule: XML helps when your prompt mixes instructions, context, examples, and variable inputs.

Here are the key scenarios where XML pays for itself:

  • Repeatable work at scale: Running the same prompt against varying user inputs.

  • Structured output: When you need extraction or classification that downstream code will parse.

  • Long, mixed prompts: When system instructions, retrieved documents, few-shot examples, and a question all live in one massive message and need clear boundaries.

  • Untrusted-input boundaries: Wrapping user data so prompt injection attempts become more visible in your logs.

  • Multi-artifact outputs: Requesting a draft, a critique, and a final version in one API call. Separate output tags make each piece easily parseable.

When It's Just Noise

Skip the tags if you are engaging in casual conversational chat, single-shot creative writing, or simple one-line lookups. Furthermore, you should avoid tags if a current API feature does the job better. For example, use Claude's native tool use for structured output rather than a <format> tag, and use the API's extended thinking feature rather than manually writing <thinking> tags (using both can actually cause them to fight each other).

Working Examples: The 30-Second Starter

When you do need structure, the most useful pattern is separating your instructions, context, and the question.

Here is a basic, runnable example of classifying a support ticket:

XML
<instructions>
You are reviewing a customer support ticket. Classify the sentiment as
positive, neutral, or negative. Return only the label.
</instructions>

<ticket>
Hi — the new dashboard is so much faster. Thank you for shipping this.
</ticket>

Classify the sentiment of the ticket above.

Scaling Up: Advanced Prompt Patterns

As your tasks get more complex—such as incorporating Retrieval-Augmented Generation (RAG), multi-document analysis, or agentic tool use—you can scale this XML pattern up. Here is a one-shot pattern providing context and examples:

XML
<instructions>...</instructions>

<context>
The user is a senior engineer asking about distributed systems.
Prefer technical depth over surface explanation.
</context>

<examples>
  <example>
    <input>What is a quorum?</input>
    <output>A quorum is the minimum number of nodes that must agree...</output>
  </example>
</examples>

<question>Explain the CAP theorem in 100 words.</question>

Anti-Patterns: What to Avoid

Mistakes in XML prompting might look fine to the human eye but can quietly degrade Claude's reliability. Always avoid:

  • Over-tagging: Don't wrap every single sentence in a tag. If there is no structural ambiguity, drop the tags.

  • Fighting API Features: As mentioned above, don't use inline <role> tags if you are already using the API system parameter for a persona, and don't mix <thinking> tags with the native extended thinking feature.

Wednesday, 12 August 2026

Tmux Runbook

 Step 1: Install Tmux on the Server

SSH into your RunPod instance and run the following commands to update the package manager and install tmux: 
bash
# Update package lists
apt-get update

# Install tmux
apt-get install -y tmux
Step 2: Start a Persistent Session
Always launch a named session before starting any long-running command. Naming the session makes it easy to track and re-enter.
bash
# Syntax: tmux new -s <session_name>
tmux new -s training_session
Step 3: Execute and Detach
Run your script normally inside the tmux window.
  1. Start your process:
    bash
    python3 train.py --epochs 100
    

  2. Disconnect safely (Detach):
    To leave the script running in the background and return to your regular server terminal, press this exact key sequence:
    • Press and hold Ctrl + B at the same time.
    • Release both keys.
    • Press D on your keyboard. 
You will see a message like [detached (from session training_session)]. You can now safely close your terminal or close your laptop; the script will not stop. 

Step 4: Reconnect and Monitor
If your connection drops, or if you want to check your progress hours later:
  1. SSH back into your RunPod instance.
  2. List active sessions to verify it is still running:
    bash
    tmux ls
    

  3. Re-attach to your session:
    bash
    # Syntax: tmux attach -t <session_name>
    tmux attach -t training_session
    


Step 5: Clean Up
Once your script finishes running completely, you should close the session to free up server resources.
  • Option A (Inside the session): Type exit and press Enter.
  • Option B (Outside the session): Run tmux kill-session -t training_session.

Cheat Sheet Reference
GoalKey / Command
Install Tmuxapt-get install -y tmux
Start Named Sessiontmux new -s <name>
List All Sessionstmux ls
Detach from SessionCtrl + B then D
Re-attach to Sessiontmux attach -t <name>
Kill/Delete Sessiontmux kill-session -t <name>