Prompt engineering advice tends to drift into vague heuristics ("be clear," "give context"), which isn't wrong but also isn't actionable. Anthropic's own documentation is more specific than that, and it's worth building habits directly from it rather than folklore that's accumulated around it. Four techniques do most of the work: role prompting via the system parameter, multishot examples, XML-tag structuring, and extended thinking for hard problems.
Four techniques, in the order to reach for them
1. Set the role in the system prompt. Telling Claude who it is ("You are a senior security auditor reviewing this code for vulnerabilities") shapes tone and focus more reliably than folding the same instruction into the user turn.
2. Add multishot examples for any task with a specific output format. Three to five examples covering edge cases (not just the easy case) does more to lock in consistent formatting than a longer written description of the format would.
3. Wrap distinct prompt sections in XML tags. When a prompt mixes reference documents, instructions, and examples, tags like <document>...</document> and <instructions>...</instructions> prevent Claude from treating document content as an instruction or vice versa.
4. Turn on extended thinking for genuinely hard reasoning. For multi-step math, complex analysis, or tasks requiring the model to weigh several constraints, letting Claude work through its reasoning before answering measurably improves output quality — at the cost of extra tokens.
# pip install anthropic
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
system="You are a meticulous contract reviewer. Flag ambiguous clauses only.",
messages=[{
"role": "user",
"content": """<document>
{contract_text}
</document>
<instructions>
List every clause that could be interpreted more than one way.
</instructions>"""
}]
)
print(response.content[0].text)
| Technique | Best For | Trade-off |
|---|---|---|
| Multishot examples | Tasks needing a precise, consistent output format | Uses more input tokens per request |
| Extended thinking | Genuinely hard multi-step reasoning | Higher latency and output token cost |
Note the currency issue this article itself had to fix: prompt-engineering guides age quickly as new models ship. This piece originally referenced "Claude 3.5 Sonnet," a model Anthropic has since retired in favor of newer releases like Claude Sonnet 5 — the techniques above are stable across model generations, but always check the current model catalog before hardcoding a model string in production code.
Practical Challenge
Take a prompt you currently use with a single vague instruction, add 3 multishot examples covering different edge cases, and compare the consistency of the outputs across five runs.
Concept Check
Sources & Further Reading
- Anthropic: Prompt Engineering Overview — the official documentation covering the techniques in this article.
- Anthropic: Multishot Prompting — guidance on how many and what kind of examples improve consistency.
- Anthropic: Extended Thinking — documentation on when and how to enable step-by-step reasoning.
AI