Learning Goals
3 min- Use the
systemparameter to set role, tone, rules. - Write clear, specific user prompts (and why specificity wins).
- Constrain output format (JSON, bullet list, word count).
- Control creativity with
temperature.
Warm-Up · Same Question, Different Roles
5 minQuestion: "What is gravity?" system = "You are a pirate." → "Arr, gravity be the force that..."" system = "You are a physics prof." → formal, precise definition system = "Explain to a 6-year-old." → "It's what makes things fall down!"
The system prompt is the model's standing instructions — its persona and rules. The user prompt is the specific request. Separating them keeps behaviour consistent across many user messages. Most prompt "magic" is just being clear and specific.
New Concept · system, specificity, format, temperature
14 minThe system parameter
import anthropic client = anthropic.Anthropic() msg = client.messages.create( model="claude-haiku-4-5", max_tokens=300, system="You are a friendly Malaysian science tutor. " "Always use simple words and a local example.", messages=[{"role": "user", "content": "What is evaporation?"}], ) print(msg.content[0].text)
The system prompt is a separate top-level parameter, not a message. It applies to the whole conversation.
Be specific — vague in, vague out
✗ "Write about dogs." ✓ "Write a 3-sentence fun fact about why dogs wag their tails, for a 9-year-old, ending with a question."
Constrain the format
system="Reply ONLY with valid JSON, no prose." user="List 3 planets with their order from the sun as " '{"planet": ..., "order": ...} objects in an array.'
Telling the model the exact output shape makes the result programmable — you can json.loads the reply. (For guaranteed structure, tool use in Lesson 42 is even more reliable.)
temperature — creativity dial
# 0 = focused/deterministic; 1 = creative/varied client.messages.create(model="claude-haiku-4-5", max_tokens=200, temperature=0, # facts, code, classification messages=[...]) client.messages.create(model="claude-haiku-4-5", max_tokens=200, temperature=1.0, # brainstorming, stories, names messages=[...])
Give an example or two
Showing the model the style you want (a sample input→output) steers it strongly. That's "few-shot prompting" — the whole of the next lesson.
Worked Example · A Consistent Tutor Bot
12 min# tutor.py — system prompt locks the behaviour import anthropic client = anthropic.Anthropic() SYSTEM = ( "You are 'CikguBot', a patient tutor for Malaysian students aged 10-14. " "Rules: use simple English; give one local everyday example; " "end with a short question to check understanding; " "never give the full answer to homework — guide instead." ) def ask_tutor(question): msg = client.messages.create( model="claude-haiku-4-5", max_tokens=300, temperature=0.3, system=SYSTEM, messages=[{"role": "user", "content": question}], ) return msg.content[0].text print(ask_tutor("Why does ice float on water?"))
Sample output
Ice floats because it is lighter than the water around it — when water freezes it spreads out a little and takes up more space, like how a packed bus feels fuller than an empty one. That's why ais kacang ice cubes bob at the top of your bowl! Can you think of another thing that floats because it's light for its size?
Read the diff
The system prompt enforces the persona and rules for every question — simple words, a local example (ais kacang!), a check-question, and the "guide, don't solve" rule. The user only sends the topic. temperature=0.3 keeps it warm but consistent. This is how real LLM products behave reliably.
Try It Yourself
13 minAsk "what is the moon?" with three different system prompts (pirate, scientist, toddler-explainer). Compare.
Get the model to return 3 book recommendations as a JSON array of {title, author, why}. json.loads the reply and print it as a table.
Ask "invent a name for a robot pet" five times at temperature 0, then five times at 1.0. Compare variety. Explain when you'd want each.
Mini-Challenge · A Strict Grader
8 minBuild a system prompt that makes the model grade a short answer out of 5 and return strict JSON: {"score": int, "feedback": str}. Parse it. Test on a good and a weak answer.
Show one possible solution
import anthropic, json client = anthropic.Anthropic() SYSTEM = ('You are a strict but fair grader. Given a question and a student ' 'answer, reply ONLY with JSON: {"score": <0-5 int>, "feedback": ' '"<one sentence>"}. No other text.') def grade(question, answer): msg = client.messages.create( model="claude-haiku-4-5", max_tokens=150, temperature=0, system=SYSTEM, messages=[{"role": "user", "content": f"Q: {question}\nAnswer: {answer}"}]) return json.loads(msg.content[0].text) print(grade("Name a planet with rings.", "Saturn has rings.")) print(grade("Name a planet with rings.", "I don't know."))
Non-negotiables: system prompt forces JSON, temperature 0 for consistency, parse with json.loads. (Tool use in L5-42 makes this even more reliable.)
Recap
3 minSystem prompt = role + rules (whole conversation); user prompt = the request. Be specific; constrain the format to make output programmable; use temperature 0 for facts/code and higher for creativity. Most "prompt engineering" is just clear instructions. Next: teach by example with few-shot prompting.
Vocabulary Card
- system prompt
- Standing instructions setting the model's role, tone, and rules.
- user prompt
- The specific request/question for this turn.
- temperature
- Randomness dial: 0 = focused/repeatable, 1 = creative/varied.
- output format constraint
- Telling the model the exact shape (JSON, list) so code can parse it.
Homework
4 minDesign a persona bot (a coach, a poet, a recipe helper). Write a strong system prompt with at least 3 rules. Test 5 different user questions and confirm the behaviour stays consistent. Then deliberately try to make it break its rules — does the system prompt hold?
Adapt tutor.py's SYSTEM to your persona. Strong system prompts hold up well, but note any edge cases where the model drifts — that's a real lesson about reliability.