🗺 Prompting & Context
A strong prompt has a clear structure: a role, explicit instructions, relevant context, examples (few‑shot), and a specified output format. Use XML tags to separate sections so Claude parses them reliably. Put long, stable content (system prompt, documents) near the top and mark it for prompt caching to cut cost and latency. Give Claude room to think step by step on hard problems, but ask for structured output when you need machine‑readable results. Manage the context window deliberately: keep the system prompt and recent turns, summarise older history, and never let raw history grow unbounded.
Caching pays when the same prefix is sent repeatedly. Rules that matter: the cached block must be a stable, byte‑identical prefix — put the system prompt, reference documents, and tool definitions first, and the variable user input after them. Changing anything inside the cached prefix invalidates it. The win is large on chat apps and high‑volume extraction (cost and latency drop on every repeat call). Design prompts so the static 90% never changes and only the tail varies.
<context>, <example>, <format>) for reliable parsing.{) to anchor the format.null for unknown — “never guess” beats silent invention.“RICE‑F” for prompt structure — Role, Instructions, Context, Examples, Format. When a prompt underperforms, find the missing letter — it's usually E (examples) or F (an explicit output format).
“PRUNE” the context window — Preserve essentials (system + recent turns), Rank by relevance, Use summaries for older history, Never unbounded, Evict noise. A conversation that only ever grows will eventually degrade — prune deliberately.
Practise this domain with original, exam-style questions.
Start practising free