Lesson 04 Advanced Prompting Techniques
Theme:
Lesson 04 · Slide 1

Advanced Prompting Techniques

Beyond basic instructions: reasoning elicitation, few-shot calibration, system prompt architecture, and pipeline decomposition.

Learning Objectives

Lesson 04 · Slide 2

Chain-of-Thought Prompting

Chain-of-thought (CoT) prompting asks the model to reason step by step before giving its final answer. Research consistently shows this improves accuracy on arithmetic, logic, and multi-step problems.

The simplest trigger phrase: "Let's think step by step." — but explicit step structures work even better.

prompt = """Solve the following problem step by step, showing your reasoning.
After reasoning, state your final answer on a new line starting with "Answer:".

Problem: A store has 240 apples. They sell 3/8 of them in the morning and
1/4 of the remainder in the afternoon. How many apples are left?

Let's think step by step:"""

Why it works: generating intermediate tokens forces the model to allocate computation to the problem rather than jumping to a plausible-sounding answer. The reasoning trace acts as scratchpad space.

Lesson 04 · Slide 3

Few-Shot Prompting

Providing example input → output pairs inside the prompt calibrates the model's response format, tone, and reasoning style without any fine-tuning.

Example Structure

Classify the sentiment of customer reviews as POSITIVE, NEUTRAL, or NEGATIVE.

Review: "Delivery was lightning fast and the product exceeded expectations!"
Sentiment: POSITIVE

Review: "It works fine. Nothing special."
Sentiment: NEUTRAL

Review: "Arrived broken and customer service was unhelpful."
Sentiment: NEGATIVE

Review: "{{USER_REVIEW}}"
Sentiment:

Selection Criteria

Lesson 04 · Slide 4

System Prompts

The system prompt is your persistent configuration layer. It scopes every turn of the conversation and is prepended before the user's first message.

What to Put in System Prompts

Example System Prompt

You are a senior code reviewer specialising in Python and security.
Your job is to review code snippets for bugs, security vulnerabilities, and style issues.

Rules:
- Always list issues by severity: Critical → High → Medium → Low
- Suggest a concrete fix for every issue you raise
- Do not comment on correct code; only flag problems
- If the code is safe and idiomatic, respond only: "LGTM — no issues found."
Lesson 04 · Slide 5

XML Tags in Claude

Claude is trained to pay special attention to XML-like tags. Using them creates unambiguous structure that separates instructions, data, and expected outputs.

Why XML Works Well

prompt = """<instructions>
Extract all action items from the meeting notes below.
Return them as a JSON array of objects with fields: owner, action, due_date.
If a field is not mentioned, use null.
</instructions>

<document>
{meeting_notes}
</document>

<output>
"""
# Claude will fill in and close the output tag

Pro tip: asking Claude to begin its response with an opening tag (like <output>) ensures it follows the structure rather than adding preamble text.

Lesson 04 · Slide 6

Prompt Chaining

Complex tasks rarely fit in one prompt. Prompt chaining breaks them into sequential steps where each output feeds the next — improving reliability and making each step independently testable.

Prompt 1
Extract key facts
→
facts JSON
→
Prompt 2
Draft from facts
→
draft text
→
Prompt 3
Edit & polish
def chain_summarise_then_classify(document: str) -> dict:
    # Step 1: summarise
    summary = client.messages.create(
        model="claude-haiku-4-5", max_tokens=300,
        messages=[{"role": "user", "content":
            f"Summarise in 3 sentences:\n\n{document}"}]
    ).content[0].text

    # Step 2: classify the summary
    label = client.messages.create(
        model="claude-haiku-4-5", max_tokens=20,
        messages=[{"role": "user", "content":
            f"Classify as SPORTS/POLITICS/TECH/OTHER:\n\n{summary}"}]
    ).content[0].text.strip()

    return {"summary": summary, "label": label}
Lesson 04 · Slide 7

Demo

Live examples showing CoT reasoning and XML extraction.

Demo Steps

  1. CoT on a word problem: run the same maths problem with and without "Let's think step by step" — show accuracy difference
  2. XML extraction: paste a messy email and use the XML-tagged prompt to extract structured action items as JSON
  3. Few-shot calibration: show how 0-shot sentiment returns verbose answers; 3-shot returns just the label
  4. System prompt scope: demonstrate that a constraint in the system prompt holds even when the user explicitly tries to override it
Notes: Show CoT on word problem, then XML extraction. Have the failure case (no CoT, wrong answer) ready to contrast with CoT success.
Lesson 04 · Slide 8

Lab & Homework

Lab Exercises

  1. CoT vs Direct: choose a 3-step logic puzzle; run it with and without chain-of-thought; record accuracy across 5 runs each
  2. Few-Shot Builder: build a few-shot prompt that classifies customer support tickets into categories; achieve consistent output with no extra text
  3. XML Pipeline: use XML-tagged prompts to extract structured data (title, author, date, summary) from 3 different article formats

Homework Tasks

  1. Implement a two-step chain: first extract all named entities from a news article, then for each entity call Claude to write a one-sentence biographical note. Return as JSON.
  2. Design a system prompt for a domain you know well (medical, legal, finance, gaming). Include: persona, 3 hard constraints, output format rule, and one example of correct behaviour.
  3. Experiment with meta-prompting — have Claude write a few-shot prompt for a task you specify. Evaluate the generated prompt on 5 real inputs.
1 / ?