Effective Prompt Design
Independent educational resource, not an official Anthropic course. Facts about the API, prices and limits were checked against Anthropic's documentation on 15 November 2026 and the code was run against a local mock of the API, not the live service. Check the linked official pages before relying on a number, and test with your own key.
Most weak prompts aren't weak because the model is limited. They're weak because the person who wrote them knew what they meant and forgot that the model didn't. This lesson is about closing that gap: writing a prompt the way you'd write a good ticket for a new colleague, and then checking the result in code instead of hoping.
What you'll be able to do
- Turn a vague request into a prompt with a clear task, audience, format and limits.
- Explain the "why" behind a rule so the model can apply it to cases you didn't list.
- Keep your rules in the system prompt and the data in the user message.
- Check the output against your rules in code, and retry with specific feedback.
Before you start
You should have read 1.7 Prompt Engineering Fundamentals and 1.6 System Prompts and User Messages. Python examples need the anthropic package and an API key, but most of the code here runs without one.
A prompt is a specification
Anthropic's own advice is to think of Claude as a brilliant new employee who has no idea how your company works. Give that person "Write a product description" and you'll get something reasonable and generic. Give them the audience, the length, the tone, the facts they may use and what to do when a fact is missing, and you'll get something you can actually publish.
The guide also offers a quick check worth stealing: show your prompt to a colleague who knows nothing about the task and ask them to follow it. If they'd come back with questions, so will the model, except it won't ask. It'll guess.
When you write a prompt, run through six questions:
- Task. What exactly should be produced?
- Audience. Who will read it, and what do they already know?
- Inputs. What material is the model allowed to use?
- Output. Format, length, tone. Be specific: "two short paragraphs, 60 to 90 words" beats "brief".
- Limits. What must it avoid, and what should it do instead?
- Gaps. What should happen when information is missing or the request doesn't fit?
The last one is the one people skip, and it's where most invented facts come from. If you don't say "leave it out if it isn't in the product details", the model will often fill the gap with something plausible.
Say what you want, and why
Compare these two ways of asking for the same thing.
Weak: Write a product description for this skillet.
Better: Write a description of this skillet for a shop selling kitchen equipment to home cooks.
Two short paragraphs, 60 to 90 words in total, plain prose. Use only the facts in
the product block. If something isn't there, leave it out rather than guessing.
Two habits from Anthropic's guidance make the second version work. First, ask for what you want. If you'd like more than the strict minimum ("include as many relevant details as you can"), say so, because the model won't assume it. Second, give the reason. Their example is telling the model a reply will be read aloud by a text-to-speech engine so it should avoid ellipses, instead of just writing "never use ellipses". With the reason, the model can handle the cases you didn't think of, like dashes or emoji.
Rules in system, facts in the user message
Standing rules don't change from request to request, so they belong in the system prompt. The product facts change every time, so they go in the user message, wrapped in a tag so there's no doubt where the data starts and ends. Here's a complete example. Read the SYSTEM string first, then the checks underneath it.
import re
from typing import Callable
import anthropic
# The rules you own live in `system`. The product facts are data and go in the user message.
SYSTEM = """You write product descriptions for a small online shop that sells kitchen equipment.
Readers are home cooks who skim. Write 2 short paragraphs of plain prose, 60 to 90 words in total.
Mention only facts that appear in the <product> block. If a fact is missing, leave it out; do not guess.
Do not use the words: revolutionary, game-changing, ultimate."""
BANNED = {"revolutionary", "game-changing", "ultimate"}
def problems(text: str) -> list[str]:
"""Check the rules in code. A prompt asks; code verifies."""
found = []
words = re.findall(r"[A-Za-z'-]+", text)
if not 60 <= len(words) <= 90:
found.append(f"Length is {len(words)} words; it must be 60 to 90.")
for bad in BANNED & {w.lower() for w in words}:
found.append(f"Remove the word '{bad}'.")
return found
def describe(product_facts: str, ask: Callable[[list[dict]], str], max_attempts: int = 2) -> str:
messages = [{"role": "user", "content": f"<product>\n{product_facts}\n</product>\n\nWrite the description."}]
text = ""
for _ in range(max_attempts):
text = ask(messages)
issues = problems(text)
if not issues:
return text
# Feed the specific problems back. Vague feedback ("try again") teaches nothing.
messages += [
{"role": "assistant", "content": text},
{"role": "user", "content": "Please rewrite it. Fix these problems:\n- " + "\n- ".join(issues)},
]
return text # best effort; a real app might flag this for a human
def live_ask(messages: list[dict]) -> str:
client = anthropic.Anthropic()
reply = client.messages.create(model="claude-sonnet-5-5", max_tokens=400, system=SYSTEM, messages=messages)
return "".join(b.text for b in reply.content if b.type == "text")
if __name__ == "__main__":
facts = "Name: Ridge 26cm cast iron skillet\nWeight: 2.1 kg\nPre-seasoned: yes\nOven safe to 260C: yes\nPrice: 54.00 USD"
print(describe(facts, live_ask))
Notice the two functions near the top, problems() and describe(). They do something prompts can't do: they check. A prompt asks for 60 to 90 words, but nothing guarantees it. So the code counts the words, looks for the banned ones, and if something's wrong it sends the model a specific correction. "Length is 2 words; it must be 60 to 90" teaches the model more than "try again" ever will.
We tested this loop with a stand-in model: a too-short first answer, a correct second answer, and a model that never improves. It passed the good text, rejected the short one with the exact reason, fed that reason back as a user turn, and stopped after two attempts instead of looping forever. Whether your real model behaves is something you find out by running it, which is what lesson 3.8 is about.
A small before-and-after workflow
- Write the shortest prompt that could work and run it on five real inputs.
- Read the outputs like a reviewer. Write down what's wrong in plain words ("too long", "invented a warranty").
- Turn each complaint into one specific instruction or one specific check.
- Run the same five inputs again. Keep the change if it helped and nothing else broke.
Real-world use case (illustrative scenario)
This scenario is an invented example to show how the ideas fit together. It is not a case study and its details are not measured results.
An online kitchen shop wants descriptions for 400 products and has the specs in a spreadsheet. Version one of the prompt was a single line. The descriptions read fine but kept mentioning "dishwasher safe" for pans where the spreadsheet said nothing about it. The fix was one sentence ("use only the facts in the product block") plus a check in code that flags any description containing a claim word that isn't in the source facts. A person reviews the flagged ones.
Mistakes I'd watch for
- Writing for yourself. Terms and abbreviations that only your team knows. Spell them out or explain them once in the system prompt.
- Rules with no output spec. "Be professional" says nothing about length or structure.
- Only saying what not to do. "Don't be wordy" is weaker than "two short paragraphs". Tell the model what you want and it has something to aim at.
- No plan for missing data. Decide what the model should do instead of guessing.
- Trusting the prompt to enforce a rule. Word limits, banned words and formats can be checked in code. Check them.
Security notes
Anything inside the <product> block was typed by someone else, perhaps a supplier pasting text from a website. It may contain sentences that read like instructions. Keep that text in the user message, say in the system prompt that it's data, and never paste it into the system prompt itself. Lesson 3.3 goes into how to build that boundary properly.
Cost and speed
Longer instructions cost input tokens on every request, and a retry costs a whole extra request. That's usually a good trade: one extra sentence of clear instruction costs a fraction of a cent, while a bad output that a person has to fix costs minutes. But measure it. Print usage for a batch (lesson 2.9) and see what your prompt really costs.
Key takeaways
- Write the prompt as a spec: task, audience, inputs, output, limits, and what to do when information is missing.
- Explain the reason behind a rule so the model can generalise it.
- Standing rules go in
system; changing data goes in a tagged block in the user message.
- Verify measurable rules in code and give the model precise feedback when they fail.
Lesson recap: a prompt is a specification, and code checks what the prompt can only ask for.
Quick quiz
- What is Anthropic's quick test for whether a prompt is clear enough?
- Why is it better to explain why you want a rule than to shout it in capitals?
- Name two rules from this lesson that you can check in code rather than trusting the model.
- Where should a changing product description go, and where should the rule "do not guess missing facts" go?
- Why is "Length is 2 words; it must be 60 to 90" better feedback than "try again"?
Answers and explanations
- Show it to a colleague with no context and ask them to follow it. If they'd be confused, the model will be too.
- The reason lets the model apply the rule sensibly to cases you didn't list, instead of applying it blindly or ignoring it.
- Word count and banned words, and also things like required keywords or a fixed set of allowed labels.
- The changing text goes in the user message, in a tag. The standing rule goes in the system prompt.
- It names the exact problem and the target, so the next attempt can fix it directly.
Official references and further reading
Related tutorials