Lesson 04 Advanced Prompting
Theme:

Advanced Prompting

Chain-of-thought, few-shot examples, system prompts, XML structure, and prompt chaining.

Introduction

Lesson 03 established the RTCF framework — the foundation for clear, specific prompts. This lesson builds on that foundation with five advanced techniques that unlock Claude's more sophisticated capabilities: chain-of-thought reasoning, few-shot learning, system prompt design, XML-structured prompts, and prompt chaining.

Each technique addresses a different class of problem. Understanding when to reach for each one — and how to combine them — is the mark of a production-grade prompt engineer.

Chain-of-Thought Prompting

Chain-of-thought (CoT) prompting instructs the model to produce explicit intermediate reasoning steps before arriving at a final answer. The canonical trigger phrase is "Let's think step by step.", though many variations work.

Why it improves reasoning

LLMs generate text token by token. When forced to write out intermediate steps, each token in the reasoning chain becomes evidence the model can condition on for subsequent tokens. This is functionally similar to a human using scratch paper — it reduces the cognitive load on any single "decision" in the reasoning chain.

Wei et al. (2022) demonstrated that CoT prompting on the GSM8K benchmark (elementary math word problems) improved accuracy from roughly 18% (direct answer) to 57% with standard CoT. The gains are largest for models at or above 100B parameters.

When to use CoT

CoT is generally not needed for simple factual recall, clear-cut classification, or latency-sensitive tasks — CoT produces more tokens, increasing cost and response time.

Zero-shot vs few-shot CoT

Zero-shot CoT: Append "Let's think step by step." to the prompt. Requires no examples.

Few-shot CoT: Provide 2–4 examples where the full reasoning chain is written out. More reliable for specialized domains where step format matters.

Few-Shot Prompting

Few-shot prompting provides worked examples in the prompt itself, allowing the model to infer the task pattern without fine-tuning. The model generalizes from examples in-context.

Example selection criteria

  1. Representativeness: Cover the output space. For a 4-class classifier, include at least one example per class.
  2. Diversity: Avoid near-duplicate examples. If all your POSITIVE examples are about food, the model may over-fit to food sentiment.
  3. Correctness: Wrong labels produce wrong outputs. Verify every example.
  4. Format consistency: Every example must use exactly the same input-output format. One deviation confuses the pattern.
  5. Difficulty calibration: Include easy, medium, and hard examples.

How many examples?

The 3–8 rule of thumb is a reasonable starting point, but the optimal number depends on task complexity. Simple binary classification may work with 2 examples; a 10-class taxonomy may need 3 examples per class (30 total). Beyond 8–10 examples, context window cost increases while marginal accuracy gains diminish rapidly.

System Prompts

The system prompt is a special message sent before the conversation begins. It establishes the model's persona, defines hard behavioral constraints, and sets persistent formatting rules that apply to every turn in the conversation.

Structure of a good system prompt

  1. Persona: Who Claude is. "You are an expert Python developer working on a financial data platform."
  2. Behavioral constraints: What Claude must always or never do.
  3. Response format: How every answer should be structured. "Answer in markdown. Keep responses under 400 words unless the user explicitly asks for more."
  4. Scope limits: What topics are in and out of bounds.
System prompt vs user prompt: System prompts set the stage; user prompts ask specific questions. If they conflict, the system prompt usually wins — but not always. Always test combined behavior.

XML Tags (Claude-Specific)

Claude handles XML tags exceptionally well for separating different parts of a complex prompt, because it was pre-trained on large volumes of XML-formatted technical documentation.

When to use XML tags

Recommended tag vocabulary

TagPurpose
<document>Input text to be processed (not instructions)
<instructions>Task instructions
<examples> / <example>Few-shot examples
<output_format>Schema or format specification
<context>Background information

Prompt Chaining

Prompt chaining decomposes a complex task into sequential sub-tasks, where the output of each step becomes the input to the next.

When to chain

# Extract → Verify → Format chain
facts = call_claude(f"Extract all action items from: {meeting_notes}")
checked = call_claude(f"Remove duplicates and sort by priority: {facts}")
formatted = call_claude(f"Format as a JIRA-compatible task list: {checked}")

Meta-Prompting

Meta-prompting means asking Claude to help write a better prompt. This is underused and genuinely effective. Claude can identify missing RTCF components, suggest few-shot examples, and generate XML-structured templates.

"I need a prompt that extracts structured data from legal contracts.
The output should be JSON. What information should I provide to get
reliable results? Draft a production-ready prompt."

Treat meta-prompting output as a starting point — always test and iterate on the generated prompt.

Further Reading