Claude 101 · lesson 5 of 6
Prompt Engineering Basics
The 5 lever model (Anthropic's canonical order)
When a prompt isn't working, walk this list top to bottom before reaching for fine-tuning or a bigger model:
- Be clear and direct. State the task, the constraints, the expected format. Don't make Claude guess.
- Use examples (few-shot). Show 2–5 input/output pairs. Examples beat description for tone, format, edge cases.
- Let Claude think (chain-of-thought). For multi-step reasoning, ask Claude to think before answering, or use extended thinking.
- Use XML tags. Wrap inputs, examples, and instructions in named tags (
<context>,<example>,<task>). Disambiguates roles in the prompt. - Assign a role. A system prompt that says "You are an expert tax preparer" frames the response.
Two more levers, applied tactically:
- Prefill Claude's response. Start the
assistantturn with{or<output>to force structure. - Chain prompts. Break a complex task into sequential prompts; each prompt's output feeds the next.
Anatomy of a strong prompt
<role>You are a senior accountant reviewing year-end statements.</role>
<context>
{customer_document}
</context>
<task>
1. Identify any line items that look anomalous compared to industry norms.
2. For each, output: line_item, why_anomalous, suggested_followup.
</task>
<format>
Return strict JSON: {"findings": [{"line_item": "...", "why_anomalous": "...", "suggested_followup": "..."}]}
</format>
Then prefill the assistant turn with { to force JSON.
Common failure modes
| Symptom | Likely cause | Fix |
|---|---|---|
| Wandering / chatty answers | No format constraint | Add <format> + prefill |
| Wrong format intermittently | Format described in prose | Use JSON schema or strict examples |
| Hallucinated facts | Asked to recall, not retrieve | Provide source in <context>, instruct "only answer from context" |
| Misses edge cases | No examples | Add 2–3 few-shot examples covering the edges |
| Won't follow a rule | Buried in long instructions ("dilution") | Move rule to top, repeat at end, or restructure system prompt |
See also
- system-prompts
- few-shot-prompting
- structured-output
- cca-domain-4-prompting — the 301-level cert domain