# Prompt Engineering Quick Reference

## Prompt Anatomy

| Component | Purpose | Example |
|-----------|---------|---------|
| **Role** | AI persona | "You are an expert Python developer." |
| **Context** | Background | "Codebase uses FastAPI and Pydantic." |
| **Task** | The request | "Add validation for the email field." |
| **Format** | Output structure | "Return JSON with keys: valid, errors." |
| **Constraints** | Limits | "Under 100 words. No external APIs." |

## Zero-Shot vs Few-Shot

| Type | When to Use |
|------|-------------|
| **Zero-shot** | Simple, well-defined tasks |
| **Few-shot** | Structured output, style-sensitive, edge cases |

## Chain-of-Thought

- Ask: "Think step by step" / "Show your reasoning"
- Improves: logic, math, multi-step tasks
- Reduces: confidently-wrong answers

## Temperature

| Range | Use Case |
|-------|----------|
| 0–0.3 | Factual, code, extraction, classification |
| 0.5–0.7 | Balanced |
| 0.7–1.0 | Creative, varied, brainstorming |

## Structured Output

- **JSON** — `Return a JSON object with: name, email, score`
- **XML** — `Wrap the summary in <summary> tags`
- **Markdown** — `Format as a markdown table with columns A, B, C`

## Iteration Order

1. Start simple — one clear task
2. Add context — if output is generic
3. Add examples — if format/style drifts
4. Add constraints — if too long or off-topic
5. Test edge cases — ambiguous, empty input

## Common Mistakes

| Mistake | Fix |
|---------|-----|
| Vague instructions | Be explicit: "List 3 pros and 3 cons" |
| No examples | Add 1–2 few-shot examples |
| Too many constraints | Add incrementally |
| Assuming model knows context | Provide relevant background |
| One giant prompt | Break into steps or sub-tasks |

## By Task Type

| Task | Strategy |
|------|----------|
| Summarization | Specify length, key points, audience |
| Analysis | Define criteria, structure (pros/cons) |
| Code | Language, framework, patterns, I/O format |
| Creative | Tone, length, style, examples |
