Lesson 03 Prompt Engineering Fundamentals
Theme:

Lab Guide

Two hands-on exercises covering RTCF rewrites and output format control.

Setup: Open lab.pdf in Jupyter. Make sure your .env file contains ANTHROPIC_API_KEY. Run the setup cell before starting any exercise.

📥 Lab Notebooks

⬇ lab.pdf ⬇ lab_answer.pdf

Exercise 1 — RTCF Rewrites

EX 1Rewrite poor prompts using the RTCF framework

Below are 5 poor prompts. For each one, write an improved version that includes all four RTCF components (Role, Task, Context, Format). Then use the compare_prompts() helper in the notebook to call Claude with both the original and improved version and compare the outputs side by side.

The 5 poor prompts

Prompt 1

"write something about climate"

Problems: No audience, no angle, no length, no format. Claude must invent everything.

Your goal: Produce a specific prompt that reliably generates a focused, usable piece of text.

Prompt 2

"summarize this"

Problems: No document is provided. No target length. No audience.

Your goal: Add a sample document (paste any ~200-word article) and specify summary format.

Prompt 3

"be helpful"

Problems: Not a task — it's a vague disposition. Claude has no idea what to do.

Your goal: Turn this into a specific task (e.g., a customer support agent instruction).

Prompt 4

"fix my code"

Problems: No code is provided. No language specified. No description of what's broken.

Your goal: Write a proper prompt that includes a code snippet, the error, and the desired fix format.

Prompt 5

"what do you think about AI?"

Problems: Invites a long, unfocused opinion essay. No angle, no constraint.

Your goal: Rewrite as a specific analytical task with a defined output format.

What to submit

  1. Your 5 improved prompts (as strings in the notebook)
  2. Side-by-side outputs from compare_prompts()
  3. One-sentence note per prompt: what changed and why it matters
Self-check: Each improved prompt should have all 4 RTCF components. Read each one aloud — would a literal-minded human ask a clarifying question? If yes, add more specificity.

Exercise 2 — Format Control

EX 2Extract contact info in three different formats

Use the following block of text (provided in the notebook) as your input:

The project kickoff meeting was attended by Sarah Chen (sarah.chen@techcorp.io),
lead engineer Marcus Webb at m.webb@devstudio.com, and the client contact
Priya Nair — her email is priya.nair@clientco.org. Also cc'd were Jordan Ellis
(jellis@techcorp.io) and the PM, Dana Okafor, reachable at d.okafor@pm.io.

Write 3 separate prompts that extract the names and email addresses from this text and produce three different output formats:

Format A — JSON array

Expected output structure:

[
  {"name": "Sarah Chen", "email": "sarah.chen@techcorp.io"},
  ...
]

Your prompt must specify this exact JSON structure. The output should parse cleanly with json.loads().

Format B — Markdown table

Expected output structure:

| Name | Email |
|------|-------|
| Sarah Chen | sarah.chen@techcorp.io |
| ... | ... |

Your prompt must produce a clean markdown table with a header row.

Format C — Plain bullet list

Expected output structure:

- Sarah Chen: sarah.chen@techcorp.io
- Marcus Webb: m.webb@devstudio.com
...

Your prompt must produce a plain bullet list, no extra commentary.

What to compare

Self-check: For the JSON format, add assert len(result) == 5 to verify all contacts were found. For the table, count the rows. For the list, count the bullet points.