Claude 4 Sonnet prompting: a practical guide

Reliable use of Claude 4 Sonnet depends on a clearly built request structure — pin down the role, the task and the format to get stable behavior in both short and complex chains. Without that, even the most advanced model will return unmanageable or barely usable answers.

This guide covers Anthropic's practices for Claude 4 — from the basic principles to prompt templates, context management and advanced techniques (few-/multishot, chain-of-thought). You will learn how to apply XML tags, build templates, fix roles up front, create reference examples and use chains to critique or refine a result. Every approach here is backed by Claude 4: best practices and the Prompt engineering overview.

Key takeaways

  • Claude 4 Sonnet needs the goal, the input data and the format stated explicitly in every request — do not rely on defaults. 
  • For multi-part tasks, separate data, instructions, examples and the final answer using XML sections. 
  • As tasks get harder, bring in few-/multishot and prefill to control the output; use self-critique and refinement chains to guarantee the result. 
  • Leaning on the official practices prevents the usual mistakes even as you scale up and automate processes.

The basic Claude 4 prompting techniques rely on strict instructions for stable results and fast diagnosis. The goal, the input data, the acceptance criteria and the expected format must always be stated explicitly: do not count on the model "figuring it out from context" — any default you leave open costs you control over the result.

  • Follow the be clear & direct principle: state the role, tone, requirements and task clearly — and do not mix them.
  • For complex tasks use XML sections (for example, , , , ) to separate data, instructions and the result — XML tags in prompts.

Change technique as needed: from one-line instructions for simple tasks to few-/multishot, controlled "thinking" (CoT) and whole self-critique chains for complex scenarios — the ladder of techniques.

A user prompt template

A structured template with sections gives you a stable format and is easy to scale. Reuse this structure:

Return only the required format.

Example: Goal: 5 key points about…; Format: Markdown list; Constraints: ≤12 words per item, no lead-ins; Criteria: every point rests on a quote from .Section 3 of the report: "…" (pp. 12–14)A list with nothing extra.

Guidance on markup and examples is in the official guide and in the multishot section.

A minimal prompt (when the input is short)

For short tasks, do not overload the prompt — the principle is one task/one format/one output criterion. Simple instructions:

  • Summarize: Summarize the text in 4 points of 10–14 words. Format: Markdown list. Text: "…"
  • Strict schema: Return a JSON array of objects {"metric": str, "value": number}. Source: the excerpts below. Return JSON only. Excerpts: …
    For a rigid form, use prefill — see Prefill Claude's response.

This technique guarantees unambiguous markup and control over the result.

Examples (few/multishot) — when style and form matter

Claude 4 Sonnet prompting lets you lock in exactly the style and format you need with short input→output pairs.

For tasks where form matters as much as content (roles, structure, language), use 1–3 pairs drawn from the logic of the task:

Case A: …- Point 1 … - Point 2 …Case B: …- Point 1 … - Point 2 …Produce an answer in the same format for case C: …

More on this in multishot.

Controlled "thinking" without idle chatter

On complex assignments it helps to keep the step-by-step reasoning separate from the final answer. Use a section for that (put steps, reasoning and criteria there) and a separate for the result.

The instruction is "think step by step", but present the final answer as a result only — do not mix reasoning and output.

Example:

In , list 5 steps for selecting features; in , return the final list of 7 features with a justification of ≤10 words.Description of the dataset …

See CoT for an explanation.

Long context: extraction → normalization → conclusions

Claude 4 Sonnet prompting can handle substantial volumes of data, but it demands strict staging to manage the token limit and the structure.

  • Step 1 (extraction): "Write out up to 10 quotes on topics X/Y; give an anchor (section/page) for each. Draw no conclusions."
  • Step 2 (normalization): "Group the quotes by A/B/C; return a Markdown table: topic | quote | anchor."
  • Step 3 (conclusions): "Formulate 5 conclusions of ≤20 words; give the quote ID for each."

A workshop on long context is in tips, as well as a recent Anthropic experiment.

Prefilling the answer (hard control over form)

For full consistency, start the answer with the required structure directly. For example, if you require JSON, begin with { "title": "" , "risks": [ ] } and the model will complete the answer strictly in the given format.

See: prefill and consistency.

Prompt chains (self-critique, refinement)

For complex and automated scenarios, Claude 4 Sonnet prompting works best as chains of stages: first the solution, then the evaluation/critique, then the refinement.

  • Self-critique: first evaluate the result against a checklist, compare it with the criteria, then refine it.
  • A template for automation: "Score the result against criteria A/B/C; fix anything scored below B+."
  • Process: instructions for the output and the criteria come first; the result goes in .

See chain prompts for extended cases.

Diagnosing common failures

  • Answer too generic? — Ask: "Add the context of audience X and goal Y; compress to N points."
  • Format drifted? — "Return only JSON matching the schema …; drop the comments."
  • Speculation crept in? — "Use only [your requirement]; if there is no information, return an empty array."
  • Resistance to drift: use prefill and repeat the structure for consistency. More on this: consistency.

Ready-made prompt examples (copy and adapt)

  • Document summary: Summarize in 6 points of 12–16 words. Format: Markdown list. Criteria: every point rests on a quote (give the anchor).
  • Risk table: Return a Markdown table: risk | likelihood (low/medium/high) | impact (1–5) | quote (anchor). Source: .
  • Article outline: Build an outline: H2/H3 plus bullets of ≤15 words under each H3. Format: clean Markdown, no preamble. The topic and excerpts are in .
  • Term normalization: Map the terms from list A to glossary B; return JSON {"term": str, "match": str|null, "why": str ≤12 words}. Source: .

Extra: templates and variables (for scaling)

For durable Claude 4 Sonnet prompting, move variables, names, constraints and formats into separate sections/templates; version your prompts so they are easier to update. Use a checklist — role, goal, format, criteria, examples, prefill — so you can confirm before launch that nothing is missing. Most of these techniques are covered in detail in the Templates & variables section.

Try it in GPTunneL