Prompt Engineering with Claude
25% of the examSystem prompts, XML tags, few-shot, explicit reasoning and prompt caching.
Structuring the prompt
- System prompt for role/tone/persistent rules; user messages for the task.
- Claude responds very well to XML tags (<document>, <instructions>, <example>) — a key Anthropic recommendation.
- Be explicit: describe the desired result, output format and constraints.
Techniques that work
- Few-shot: 2-5 representative examples strongly shape behavior.
- Chain-of-thought: 'think step by step' (or <thinking> tags) improves reasoning.
- Prefill the assistant turn to force a format (e.g. start with '{' for JSON).
- Give an out ('if you don't know, say so') to reduce hallucinations.
Prompt caching
- Caches a stable prefix (long instructions, documents) → lower cost/latency on repeated calls.
- Put stable content first, variable content last.
Practice — 10 questions
- 1. Anthropic-recommended practice to delimit a document to analyze in a prompt?
- 2. To make multi-step reasoning reliable, which technique?
- 3. Force strictly JSON output — most robust approach?
- 4. Reduce hallucinations on questions outside the provided context?
- 5. An assistant reuses 30K tokens of instructions/docs each call. Which lever cuts cost/latency?
- 6. For deterministic, reproducible extraction, which temperature?
- 7. Which instruction phrasing is most effective?
- 8. How many few-shot examples are usually useful to frame a task?
- 9. How to separate reasoning from the final answer?
- 10. For prompt caching, what content order?