Claude Academy
Sign in

Vault / wiki/101/prompt-engineering-basics.md

updated 2026-05-28

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:

  1. Be clear and direct. State the task, the constraints, the expected format. Don't make Claude guess.
  2. Use examples (few-shot). Show 2–5 input/output pairs. Examples beat description for tone, format, edge cases.
  3. Let Claude think (chain-of-thought). For multi-step reasoning, ask Claude to think before answering, or use extended thinking.
  4. Use XML tags. Wrap inputs, examples, and instructions in named tags (<context>, <example>, <task>). Disambiguates roles in the prompt.
  5. Assign a role. A system prompt that says "You are an expert tax preparer" frames the response.

Two more levers, applied tactically:

  1. Prefill Claude's response. Start the assistant turn with { or <output> to force structure.
  2. 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

SymptomLikely causeFix
Wandering / chatty answersNo format constraintAdd <format> + prefill
Wrong format intermittentlyFormat described in proseUse JSON schema or strict examples
Hallucinated factsAsked to recall, not retrieveProvide source in <context>, instruct "only answer from context"
Misses edge casesNo examplesAdd 2–3 few-shot examples covering the edges
Won't follow a ruleBuried in long instructions ("dilution")Move rule to top, repeat at end, or restructure system prompt

See also