Prompt techniques that matter

In one sentence

Treat the model like a brilliant new hire with zero context: say exactly what you want and why, separate data from instructions, show an example, and specify the output format.

Analogy: Briefing a contractor: "fix the bathroom" gets you something; "replace the leaking tap, keep the tiles, finish by Friday because guests arrive Saturday" gets you what you wanted.

A prompt is assembled from separable parts, and every change is validated against an eval set before it ships.

How it works

  • Current models follow instructions literally: be explicit, and say what to do rather than what to avoid.
  • Give the reason behind a rule; the model generalizes from the why, not from the bare command.
  • A role in the system prompt sets tone, vocabulary and audience; it doesn't add knowledge.
  • Anti-patterns: ALL-CAPS threats cause over-applied rules, contradictions force guessing, and kitchen-sink prompts bury what matters.
  • Every edit is a hypothesis: test it on an eval set, one change at a time.

Check yourself

Answer to mark it learned; your answers aren't scored.

Error analysis on an invoice extractor shows dates read as MM/DD when the invoices use DD/MM. Which line do you add to the prompt?

Go deeper

Full explanation

Most prompt quality comes from a handful of habits, not magic phrases:

  • Be explicit and specific. Current models follow instructions literally; if you want "thorough, with edge cases", say so.
  • Give the why. "Never use ellipses" works worse than "a text-to-speech engine reads this aloud and can't pronounce ellipses": the model generalizes from the reason.
  • Separate data from instructions with XML tags or delimiters (<contract>…</contract>) and refer to them by name. Put long documents first and the question last.
  • A role in the system prompt sets tone, vocabulary and audience; it doesn't add knowledge.
  • Say what to do, not what to avoid: "write flowing prose paragraphs" beats "no markdown".
  • Show examples: 3–5 diverse ones beat a page of rules (Zero-shot vs few-shot prompting).
  • Specify the output format, ideally enforced with Structured outputs & JSON mode; prefilling the assistant turn (e.g. with {) works only where still allowed (not OpenAI or Claude 4.6+).
  • Split complex tasks into a chain of focused calls (Pattern: prompt chaining).

Anti-patterns: ALL-CAPS threats ("CRITICAL: you MUST") make current models over-apply the rule; contradictory rules make the model guess which one wins; 5,000-word kitchen-sink prompts bury the instruction that matters. Every edit is a hypothesis: test it on an eval set.

Code Role, reasons, tagged data and an output contract
pythonRole, reasons, tagged data and an output contract
import anthropic

client = anthropic.Anthropic()
MODEL = "claude-sonnet-5-5"  # any chat model

# Role + audience + the WHY behind each constraint
SYSTEM = (
    "You are a tier-2 support engineer for a B2B SaaS product. "
    "Your reply is pasted into a plain-text ticket widget, so write short "
    "sentences and numbered steps. Customers are often mid-incident: "
    "lead with the fix, then the explanation."
)

# Long data first, inside named tags; instructions and format last
PROMPT = """<runbook>
{runbook}
</runbook>

<ticket>
{ticket}
</ticket>

<example_reply>
1. Clear the IdP session cookie. 2. Retry login. Why: the cookie pins a stale SAML assertion.
</example_reply>

Answer the ticket using only the runbook. If the runbook does not cover it,
say so and set escalate to true.
Return JSON: {{"reply": str, "runbook_section": str | null, "escalate": bool}}"""

# For a guaranteed shape, prefer structured outputs over a JSON instruction
resp = client.messages.create(
    model=MODEL, max_tokens=800, system=SYSTEM,
    messages=[{"role": "user", "content": PROMPT.format(runbook=runbook, ticket=ticket)}],
)
Real example

An invoice extractor scored 81% field accuracy. Error analysis on 60 failures found three causes: dates read as MM/DD instead of DD/MM, totals taken from the subtotal line, and invented PO numbers. Fixes, one at a time against a 300-invoice eval set: state the date format and why ("the ERP rejects ambiguous dates"), wrap the invoice in <invoice> tags and add two examples contrasting subtotal and total, and say "return null when no PO number appears". The line "BE EXTREMELY ACCURATE!!!" was deleted. Accuracy rose to ~94%, with no model change.

Trade-offs +3 · −3

+ You gain

  • The cheapest, fastest lever: a prompt change ships in minutes, with no training or infrastructure.
  • Fixes most "the model is dumb" complaints, which are usually missing context.
  • The habits transfer across providers and model generations.

− You pay

  • Gains are model-specific: a prompt tuned for one model can regress on the next.
  • Prompts that grow by accretion become untestable folklore without versioning and evals.
  • Can't add knowledge or skills the model lacks; that needs RAG, a bigger model or fine-tuning.

Use it when

Always, and first. Before RAG, fine-tuning or a bigger model, make sure the prompt states the task, context, constraints and output format explicitly.

Avoid it when

Stop polishing wording when evals plateau: the gap is then missing knowledge (RAG), missing capability (bigger model, fine-tuning) or a task that should be split.

Numbers to know 3
  • Anthropic reports that putting the question after long documents improves response quality by up to ~30% on complex multi-document inputs.
  • Anthropic recommends 3–5 diverse, relevant examples for few-shot prompting.
  • OpenAI's GPT-4.1 guide: in long contexts, repeat key instructions at both the start and the end; XML delimited documents well, JSON poorly.
Common pitfalls 4
  • Adding a rule after every incident until the prompt contradicts itself; prune and dedupe regularly.
  • Treating delimiters as security: <user_input> tags reduce confusion but do not stop prompt injection.
  • Judging a prompt change on 3 hand-picked inputs instead of an eval set.
  • Reusing a prompt tuned for one model on another without re-testing; newer models follow instructions more literally.
Interview questions 3

Answer out loud first, then reveal.

Your prompt works in the demo but fails on ~10% of production traffic. What do you do?Show answer

I don't start by rewording. I pull 50–100 failures and label why each failed, because failures cluster: missing context, an ambiguous instruction, format drift or a real capability gap. I fix the biggest cluster with one targeted change, usually the missing context plus the reason behind a rule, or an example of that edge case, and re-run the full eval set to catch regressions. If a cluster survives two honest attempts, it isn't a prompt problem: I add retrieval, split the task or move up a model.

Do ALL-CAPS and "you MUST" instructions help?Show answer

With older models they sometimes compensated for weak instruction-following. With current models they mostly cause over-application: the model starts using that tool or rule where it shouldn't, and Anthropic's guidance for recent Claude models is to dial that language back. A calm, specific instruction plus the reason works better, because the model can then judge edge cases. If a rule truly must never break, I enforce it in code or a validator, not with capital letters.

How do you keep user-provided text from being treated as instructions?Show answer

I put it inside clearly named tags, tell the model that tagged content is data to analyze, and keep my instructions outside it. That reduces accidental confusion, but it is not a security boundary: a determined prompt injection can still work. So the real controls live outside the prompt: least-privilege tools, output validation, and human approval for consequential actions.