# Prompt Engineering — Exercises

## Exercise 1: Improve a Vague Prompt

**Task:** Someone wrote: "Make this email sound professional." Rewrite it to be specific. Include: audience, tone, length, and one example of a phrase to avoid or use.

**Validation:**
- [ ] Specifies the audience (e.g., client, internal)
- [ ] Defines "professional" (formal? concise? friendly-but-polished?)
- [ ] Includes length or structure (short paragraph? bullet points?)
- [ ] Gives at least one example of desired or undesired phrasing

**Hints:**
1. "Professional" is vague — formal? concise? industry jargon?
2. "Sound professional for a CFO" narrows audience
3. "Use 'regarding' not 'about'; avoid exclamation points" — concrete style

---

## Exercise 2: Add Few-Shot Examples

**Task:** You need the AI to convert product names to URL slugs. Zero-shot: "Convert to URL slug." Add 2–3 few-shot examples. Example format: "Blue Widget Pro" → "blue-widget-pro".

**Validation:**
- [ ] At least 2 examples showing input → output
- [ ] Examples cover edge cases (capitals, spaces, special chars?)
- [ ] Output format is consistent (lowercase, hyphens)

**Hints:**
1. Show: "Hello World" → "hello-world"
2. Add: "Super Product 2024" → "super-product-2024" (numbers?)
3. Consider: "O'Reilly Book" → "oreilly-book" (apostrophes)

---

## Exercise 3: Request Structured Output

**Task:** Ask the AI to analyze a short product review and return: sentiment (positive/negative/neutral), main topic (1–3 words), and one suggested action for the business. Request JSON with keys `sentiment`, `topic`, `action`.

**Validation:**
- [ ] JSON structure is specified
- [ ] Keys are named exactly
- [ ] Value types are clear (string, etc.)
- [ ] Handles edge case: ambiguous or empty input

**Hints:**
1. "Return a JSON object with keys: sentiment, topic, action"
2. "No markdown, no explanation — JSON only"
3. "If unclear, use 'neutral' for sentiment"

---

## Exercise 4: Add Chain-of-Thought

**Task:** Give the AI a multi-step logic puzzle (e.g., "Three people: A, B, C. A is taller than B. B is taller than C. Who is shortest?"). First prompt: just ask for the answer. Second prompt: ask to "reason step by step, then give the answer." Compare outputs.

**Validation:**
- [ ] CoT prompt explicitly asks for reasoning first
- [ ] User observes CoT yields more reliable answer (or catches errors)
- [ ] User can state when CoT helps (logic, math, debugging)

**Hints:**
1. "Think through each step before answering"
2. "Show your reasoning, then state the final answer"
3. For complex tasks, CoT reduces confidently-wrong answers

---

## Exercise 5: Fix Common Mistakes

**Task:** This prompt has problems: "Be creative and write something good about our product. Make it long and detailed. Use lots of adjectives." Rewrite it to avoid: vagueness, conflicting constraints, no examples. Produce a better version.

**Validation:**
- [ ] Replaces "creative" and "good" with specifics (tone, audience, format)
- [ ] "Long" is quantified (e.g., 2 paragraphs, 150 words)
- [ ] Adds at least one example of desired style or output
- [ ] Removes or reconciles conflicting instructions

**Hints:**
1. "Creative" → "Convey enthusiasm without hype; avoid superlatives"
2. "Long" → "2 paragraphs, ~100 words"
3. Add example: "Like X, not like Y"
