Lección 2 · Módulo 1: System Prompts That Control Agents and Cut Cost
Anatomy of a system prompt: role, goal, rules, output format
- Name the four parts of a system prompt
- Write each part for a real business
- Spot the gaps that cause drift
Why this matters
A customer asks a candle shop, "Do you ship to Alexandria?" and gets four paragraphs about the history of wax. Nothing is broken. The From the lesson: How an AI agent works: model, instructions, tools and memoryAn agent is an AI model that works toward a job, using instructions, tools and memory.Review that lesson was never told its job, its limits or the shape of a reply. Businesses that let an assistant answer customers need that briefing written down carefully, because the same text is sent with every message, and each gap becomes a costly, unpredictable reply.
Key ideas
- A system prompt has four parts. The system prompt is a standing briefing that the model reads before every message, and the customer never sees it. Its four parts are the role (who the assistant is), the goal (the one job), the rules (the limits) and the output format (the shape of each reply).
- A goal is an outcome. "Be a good assistant" never finishes, so nobody can say when it has worked. "Answer the customer's question" can be checked, because the answer either arrived or it did not. Name what is out of scope too.
- A rule must be testable. A rule works only if a checker can test it. "Only quote prices from the price list" can be compared with the list. "Be friendly" cannot be checked, so it controls nothing. For example,
len(reply.split()) < 60returns True for a 10-word reply, so it passes an "under 60 words" rule. Turn each wish into a test, or delete it. - Keep it short. The prompt travels with every message, and you pay per a small piece of text, often a word or part of one, that a model reads and is billed by. Every extra line is charged on every reply.
Try it before you watch
A bakery assistant must never give a delivery date that is not in its list. Is that a rule a checker can test: yes or no, and why?
Show answerHide answer
Yes. A checker can compare each date in a reply with the list and flag any date that is not there. A rule is testable when a program or a person can check the reply against something fixed.
Words to know
- system prompt: the standing briefing the model reads before every message; the customer never sees it.
- drift: when an assistant slowly starts doing things it was never asked to do.
- checker: a test, often a short program, that reads a reply and reports any broken rule.
- out of scope: work the agent is told to leave alone, because another agent or a person handles it.
- output format: the agreed shape of a reply, such as its length, its language or its fields.
What to watch for
- How the failed reply splits into three gaps: no job, no limits, no required shape.
- Which of the four parts each line of Nour's prompt belongs to.
- Why "be friendly" gets dropped while the price rule stays, and how the checker treats each reply.
Apréndelo con tu tutor en la pizarra en vivo
Puntos clave del video
A reply nobody wanted
- Customer asks: "Do you ship to Alexandria?"
- Reply: four paragraphs about wax
- No job, no limits, no shape
layout: full
parts:
bot: {chip: "Chat assistant", sub: "No system prompt", icon: message-circle}
ask: {chat: "Do you ship to Alexandria?", reply: "Candles have a long and fascinating history."}
steps:
- at: "a wall of text back"
note: "A simple question, a long reply"
- at: "Nour sells handmade candles"
highlight: bot
note: "Nour's candle shop"
- at: "Do you ship to Alexandria"
send: ask
- at: "four paragraphs about the history of wax"
note: "No yes, no answer"
- at: "Nothing was wrong with the model"
note: "The model is fine"
- at: "no clear job, no limits"
spokes: {of: bot, items: ["No clear job", "No limits", "No required shape"]}
- at: "Those three gaps are what a system prompt fills"
note: "Fill the three gaps" What you will learn
- Name the four parts of a system prompt
- Write each part for a real business
- Spot the gaps that cause drift
layout: full
parts:
goal: {chip: "This lesson", sub: "Three things to do"}
steps:
- at: "three things"
spokes: {of: goal, items: ["Name the four parts", "Write each part", "Spot the gaps"]}
- at: "name the four parts"
note: "1 of 3: name the parts"
- at: "write each part"
note: "2 of 3: write each part"
- at: "spot the gaps"
note: "3 of 3: spot the gaps"
- at: "Nour's candle shop"
note: "Our example: Nour's candles" The system prompt: a briefing
- A briefing read before every message
- The customer never sees it
- Sent again with every message
layout: full
parts:
model: {chip: "AI model", sub: "Reads every message"}
brief: {box: BRIEFING, holds: [model], icon: file-text}
ask: {chat: "Do you ship to Alexandria?", reply: "Yes, we ship to Alexandria."}
steps:
- at: "standing briefing"
spokes: {of: brief, items: ["Read first", "Never shown"]}
- at: "job sheet"
note: "A job sheet for the assistant"
- at: "The customer never sees it"
note: "Hidden from the customer"
- at: "every single message"
send: ask
- at: "Everything in this lesson"
highlight: brief Part 1: the role
- Who the assistant is
- Name the business
- Name the audience
- Two or three sentences
layout: full
parts:
role: {chip: ROLE, sub: "Who it is"}
steps:
- at: "answers one question"
spokes: {of: role, items: ["Business: Nour Candles", "Audience: customers", "Tone: warm and brief"]}
- at: "a small online shop in Cairo"
note: "Nour Candles, Cairo"
- at: "names the business"
note: "Which shop?"
- at: "names the audience"
note: "Who it talks to"
- at: "sets the tone"
note: "How it sounds"
- at: "two or three sentences at most"
note: "Two or three sentences" Part 2: the goal
- One job, as an outcome
- Nobody can tell when it is done
- Say what is out of scope
layout: full
parts:
goal: {chip: GOAL, sub: "One job, done"}
steps:
- at: "the one job this agent must finish"
spokes: {of: goal, items: ["Answer order questions", "Book workshop seats", "Pass leads to Nour"]}
- at: "Be a good assistant"
note: "Activity: no finish line"
- at: "Answer the customer's question"
note: "Outcome: you can see it"
- at: "answer order questions"
note: "Task 1: answer order questions"
- at: "book seats in the candle workshops"
note: "Task 2: book workshop seats"
- at: "pass serious buyers to Nour"
note: "Task 3: pass leads to Nour"
- at: "Invoices and sales reports"
note: "Out of scope: other agents" Part 3: the rules
- A rule a checker can test
- Only use listed prices
- Never promise a refund
- Hand complaints to a person
cells:
A1: Rule
B1: "Can a checker test it?"
steps:
- at: "where most prompts go wrong"
note: "Most prompts fail here"
- at: "A good rule is one that a checker can test"
note: "Testable, not just nice"
- at: "Only use the prices in the list"
type: {A2: "Only use listed prices", B2: "Yes"}
- at: "Never promise a refund is also testable"
type: {A3: "Never promise a refund", B3: "Yes"}
- at: "Be friendly and kind sounds sensible"
type: {A4: "Be friendly and kind", B4: "No"}
- at: "Hand complaints to a person is a rule too"
type: {A5: "Hand complaints to a person", B5: "Yes"}
- at: "turn every wish into a test"
highlight: B4 Part 4: the output format
- The shape of every reply
- The language the customer wrote in
- Fields when a tool reads it
tree:
Reply:
Intent: [Order, Booking, Lead, Other]
Message: [Under 60 words, Customer language]
Ends with: [Question, Next step]
Handoff: ["Yes", "No"]
direction: down
steps:
- at: "the output format"
note: "Output format"
- at: "reply in under sixty words"
grow: Reply
- at: "the language the customer wrote in"
grow: Message
- at: "one question or one next step"
grow: Ends with
- at: "the intent"
grow: Intent
- at: "step in"
grow: Handoff
- at: "four parts in total"
note: "Role, goal, rules, output format" Putting the four parts together
- Role and goal on one line each
- Rules as a list
- Joined into one text
role = "You are the assistant for Nour Candles, a small online shop in Cairo."
goal = "Answer customer messages, book workshop seats and pass leads to Nour."
rules = [
"Use only the prices in the price list.",
"Never promise a refund. Send refund requests to Nour.",
"Never give a delivery date you were not given.",
]
output = "Reply in under 60 words, in the language the customer wrote in."
parts = [role, "GOAL: " + goal, "RULES:"] + ["- " + r for r in rules] + ["OUTPUT: " + output]
prompt = "\n".join(parts)
print(prompt)
print("Words:", len(prompt.split())) Checking a reply against the rules
- A checker turns a rule into a test
- Flags any reply of sixty words or more
- Flags a promise, using the word guarantee
def check(reply):
problems = []
if len(reply.split()) >= 60:
problems.append("too long")
if "guarantee" in reply.lower():
problems.append("promised something")
return problems or ["PASS"]
good = "Hi! Yes, we ship to Alexandria. Which candle would you like?"
bad = "Sure! A full refund is guaranteed for you, so order now."
print("Reply 1:", check(good))
print("Reply 2:", check(bad)) Common mistake: wishes are not rules
- Wishes that sound right
- Rules you can count or search
- Rewrite each wish as a test
title: Wishes are not rules
underline: red
rows:
- id: wish
text: "Be friendly and helpful"
- id: test1
text: "Reply in under sixty words"
- id: test2
text: "Never promise a refund"
- id: fix
text: "Test it, or delete it"
color: green
steps:
- at: "writing wishes instead of rules"
show: wish
- at: "Be friendly and helpful sounds right"
mark: {target: wish, kind: cross, color: red}
- at: "Compare it with reply in under sixty words"
show: test1
- at: "You can count that"
mark: {target: test1, kind: box, color: green}
- at: "Never promise a refund works the same way"
show: test2
- at: "search the reply for a promise"
mark: {target: test2, kind: box, color: green}
- at: "rewrite it as something you can test"
show: fix Recap: three takeaways
- Four parts: role, goal, rules, output format
- Rules a checker can test
- Keep it short and clear
layout: full
parts:
core: {chip: "System prompt", sub: "Four parts"}
steps:
- at: "First, a system prompt has four parts"
spokes: {of: core, items: [Role, Goal, Rules, Output format]}
- at: "write every rule so that a checker can test it"
note: "Takeaway 2: testable rules"
- at: "Third, keep it short and clear"
note: "Takeaway 3: keep it short"
- at: "that length is what you pay for"
note: "Every token costs money"
- at: "Next, we add guardrails"
highlight: core Exercise: write your own prompt
- Write the role in two sentences
- Write one goal, with three tasks
- Write three rules a checker can test
- Write the output format
- Test on three customer messages
title: "Your exercise: pick one business"
rows:
- id: t1
text: "1. Write the role in two sentences"
- id: t2
text: "2. Write one goal with three tasks"
- id: t3
text: "3. Write three rules a checker can test"
- id: t4
text: "4. Write the output format"
- id: t5
text: "5. Test it on three customer messages"
steps:
- at: "Write the role in two sentences"
show: t1
- at: "Write one goal"
show: t2
- at: "Write three rules that a checker could test"
show: t3
- at: "Write the output format"
show: t4
- at: "three customer messages"
show: t5
- at: "Bring your list to the next lesson"
mark: {target: t5, kind: underline, color: green} Transcripción
A reply nobody wanted. Have you ever asked a chatbot a simple question and got a wall of text back? Nour sells handmade candles online, and her chat assistant did exactly that last month. A customer typed, Do you ship to Alexandria? The assistant replied with four paragraphs about the history of wax, and never gave a yes or no. Nothing was wrong with the model itself. The assistant had no clear job, no limits and no required shape for its answer. Those three gaps are what a system prompt fills, and this lesson shows you how to fill each one.
What you will learn. By the end of this lesson you will be able to do three things. First, name the four parts of a system prompt. Second, write each part for a real small business, such as an online shop that answers customers. Third, spot the gaps that make an agent, an assistant that acts for you, drift off course, which means doing things it was never asked to do. We will use one example all the way through, Nour's candle shop, so you can follow every line.
The system prompt: a briefing. Let us start with the basics. A system prompt is a standing briefing that the model reads before every customer message. Think of it as the job sheet you hand a new shop assistant on their first morning. The customer never sees it. It is sent again with every single message, so the assistant always starts from the same instructions. Everything in this lesson is about what goes into that sheet, and how to write each line so that it can be checked.
Part 1: the role. The first part is the role. The role answers one question: who is the assistant? For Nour, the role line reads, you are the assistant for Nour Candles, a small online shop in Cairo. Notice what it does. It names the business, so the model knows which products exist. It names the audience, which is customers who buy candles and book workshops. It also sets the tone: warm and brief. A role should be short, two or three sentences at most, because every extra word adds tokens, the pieces the model is billed by, on every message.
Part 2: the goal. The second part is the goal. The goal is the one job this agent must finish, and it should be stated as an outcome, not as an activity. Compare two lines. Be a good assistant is an activity, and nobody can tell when it is done. Answer the customer's question is an outcome, because you can see whether it happened. Nour's assistant has one goal: help customers with orders, bookings and serious buying. Inside that goal are three tasks: answer order questions, book seats in the candle workshops, and pass serious buyers to Nour. Invoices and sales reports belong to other agents with their own prompts, so say they are out of scope.
Part 3: the rules. The third part is the rules, and this is where most prompts go wrong. A good rule is one that a checker can test. Only use the prices in the list is a rule you can check, because you can compare the reply with the list. Never promise a refund is also testable. Be friendly and kind sounds sensible, but nobody can check it, so it controls nothing. Hand complaints to a person is a rule too, because it tells the assistant exactly what to do. Keep the list short, and turn every wish into a test.
Part 4: the output format. The last part is the output format, which tells the model what shape its reply must take. For Nour's assistant, the format says to reply in under sixty words, in the language the customer wrote in, and to finish with one question or one next step. When a tool reads the reply, the format gets stricter. The assistant can return a few fields, such as the intent, the message to send, and whether a person should step in. That structure lets a booking system read the answer without guessing. So a system prompt has four parts in total: role, goal, rules and output format.
Putting the four parts together. Now let us put the four parts together. Here is a complete system prompt for Nour's candle shop, written in Python so you can run it. The role and the goal each take one line. The rules become a list, one item per line, so each rule stands on its own. The output format comes last. Then the parts are joined into one text, which is what gets sent before every customer message. Run it, and the full prompt appears, with its word count at the bottom. Keep it short, because every word travels with every single message.
Checking a reply against the rules. Writing the prompt is only half the job. You also need to check that the replies follow it. Here is a tiny checker, written in plain Python, that turns a rule into a test. It takes a reply and returns a list of problems. It flags any reply of sixty words or more. It also flags a promise, using the word guarantee as a simple signal. The first reply is short and promises nothing, so it passes. The second says a full refund is guaranteed, so the checker catches it and reports the problem. Every rule in your prompt should have a check like this, even a simple one.
Common mistake: wishes are not rules. The most common mistake is writing wishes instead of rules. Be friendly and helpful sounds right, and it feels like a good line to add. But nothing can check it, so the model reads it however it likes, and you never learn when it failed. Compare it with reply in under sixty words. You can count that. Never promise a refund works the same way: you can search the reply for a promise. When you find a wish in your prompt, rewrite it as something you can test, or delete it.
Recap: three takeaways. Let us recap in three takeaways. First, a system prompt has four parts: the role, the goal, the rules and the output format. Second, write every rule so that a checker can test it, and turn wishes into tests or delete them. Third, keep it short and clear, because every word is sent with every customer message, and that length is what you pay for. Next, we add guardrails for the moments when the assistant should refuse or hand over to a person.
Exercise: write your own prompt. Now it is your turn, and it should take a short session. Pick a small business you know, or use Nour's candle shop. Write the role in two sentences. Write one goal, an outcome you could check, with three tasks inside it. Write three rules that a checker could test. Write the output format, with its length and language. Finally, test the finished prompt against three customer messages, one easy and two tricky, and note every reply that breaks a rule. Bring your list to the next lesson.
Explora las animaciones
Las animaciones del video, exactas y en vivo: reprodúcelas, pausa, arrastra el control deslizante o salta a un paso a tu propio ritmo.
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Loading the animation...
Responde todas las preguntas y luego comprueba. Apruebas con 70%; puedes intentarlo las veces que quieras.
Resumen de la lección
- Lectura
- Video visto
- Cuestionario aprobado (70%)
- Four parts: role, goal, rules, output format
- Rules a checker can test
- Keep it short and clear