CURRENT TREND INSIGHT
In-depth guide to prompt engineering and orchestration with Claude Sonnet 5 Illustration

In-depth guide to prompt engineering and orchestration with Claude Sonnet 5

Direct Summary:

Effective prompt engineering for Claude models centers on a handful of documented techniques: giving Claude a clear role via the system prompt, providing several concrete input/output examples (multishot prompting) rather than describing the task abstractly, wrapping distinct pieces of a prompt in XML tags so Claude doesn't confuse instructions with content, and — for genuinely hard reasoning tasks — enabling extended thinking so the model reasons step by step before answering. These aren't folklore; they're the specific practices Anthropic documents in its own prompt engineering guide.

"The only source of knowledge is experience."

— Albert Einstein

Key Insights

  • Multishot beats zero-shot for consistency: giving Claude 3-5 diverse, well-chosen examples of the exact input/output format you want typically produces more consistent results than a purely descriptive instruction.
  • XML tags reduce ambiguity, not just formatting: wrapping context, instructions, and examples in distinct tags (like <document>, <instructions>) helps Claude parse which part of the prompt is which, especially in long, multi-part prompts.
  • Extended thinking is a deliberate trade-off: it improves performance on genuinely hard multi-step problems, but it costs more tokens and latency — reserve it for tasks that actually need step-by-step reasoning, not routine calls.

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.

claude_prompt.py
# 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

Why does Anthropic recommend wrapping distinct prompt sections (documents, instructions, examples) in XML tags?
Correct! Structuring a prompt with tags reduces ambiguity about which text is data to analyze versus an instruction to act on — especially important in long, multi-section prompts.
Incorrect. Try again! XML tags aren't a technical requirement — they're a clarity technique that helps the model parse mixed content correctly.

Sources & Further Reading

Previous Guide Dashboard Next Guide