Lesson 42 — Beginner
System Prompt Design
System prompt tumhare app ka blueprint hai — persona, rules, boundaries aur output expectations jo har request mein same rehti hain. Is lesson mein hum dekhenge system prompt mein kya aata hai, stable rules ko task instructions se kaise alag rakhte hain, missing ya out-of-scope input ka kya karte hain, aur guardrails ko lightweight kaise rakhte hain.
System prompt mein kya aata hai
WHAT
System prompt app ke behavior ki specification hai — tum kaun ho (persona), kya kar sakte ho (scope), kaise jawaab dena hai (style/length) aur kya kabhi nahi karna (boundaries). User message se pehle bheja jaata hai.
WHEN
Har LLM API call mein, chahe chat app ho ya batch pipeline. Bina system prompt ke model ka default behavior generic hota hai — kabhi kabhi theek, production mein kabhi nahi.
WHERE
Chatbots, coding agents, support bots, internal tools — har product ka system prompt chhupa hota hai. Codebase mein woh ek config file ya constant ke roop mein rehta hai.
SYSTEM
Tum "DSBank" ka chat assistant ho.
Kaam: sirf balance, statement aur card-block se related sawaalon ke jawaab do.
Rules:
- Sirf banking topics. Loan approval ya interest rate ka promise kabhi mat karo.
- Jawaab 3 line tak. Hindi/Hinglish hi use karo.
- Zaroori detail missing ho toh ek hi clarifying sawaal poochho.
- Refund/block jaise action kabhi mat khud karo — bolo "agent se connect kar raha hoon".
- Purpose: app kya hai, tum kis role mein ho — pehli 1-2 line.
- Scope: kaunse topics in, kaunse out — hallucination sabse yahin rokti hai.
- Behavior: tone, language, length, aur kaise clarify karna hai.
- Boundaries: kabhi na karne wale kaam — promises, actions, data leaking.
Stable rules vs task instructions
SYSTEM_RULES = "Tum ShopKart support assistant ho. Sirf order/billing topics. 3 line tak jawaab do."
def answer(ticket, history):
messages = [
{"role": "system", "content": SYSTEM_RULES}, # stable — har request same
*history,
{"role": "user", "content": f"Ticket: {ticket}\nEk line next-action batao."}, # task-specific
]
return call_llm(messages)
- Stable rules = app ke wo rules jo hafte-hafte nahi badalte — system prompt mein daalo, code mein constant rakho.
- Task instructions = is call ka kaam ("ticket classify karo", "summary 2 bullet mein") — user message mein daalo.
- Task instruction system prompt mein daal di toh har call ke liye prompt badalna padega — caching bhi tootegi (agle level ke M3.7 mein).
- Isko hi kehte hain: system = policy, user = payload.
Missing, ambiguous aur out-of-scope input
# System prompt ka fallback section — likhna hi padta hai
Missing info : Zaroori field missing ho toh ek hi sawaal poochho, guess mat karo.
Ambiguous : Do matlab ho toh dono bolo aur poochho kaunsa sahi.
Out of scope : Topic scope se bahar ho toh seedha bolo:
"Yeh mere kaam se bahar hai — agent se connect kar raha hoon."
Refusal style: Tone polite rahe, excuse mat banao, aur policy ka jawaab mat do.
Model ka default behavior hai sabka jawaab dene ka — detail missing ho toh guess karega, scope bahar ho toh bhi gyaan ulega. Fallback behavior likhna padta hai, warna hallucinated answers production mein aayenge.
- Missing vs ambiguous dono ka alag treatment likho — dono mein model ka response alag hona chahiye.
- Out-of-scope ka ek fixed sentence do — user experience consistent rahega, agent handoff smooth.
- Jab bhi model ko "no" bolna ho, saath mein agla step bhi batao (agent, help page, retry) — warna conversation dead end ho jaati hai.
Lightweight guardrails — rulebook mat banao
Guardrails matlab halki lines jo behavior ko track pe rakhein — 200-line ka rulebook likhne ki zarurat nahi. Bahut se rules ek doosre se takrate hain ya model ignore kar deta hai; 5-8 clear rules zyada kaam karte hain.
- Har rule ka ek line — agar rule ko explain karna pad raha hai toh woh rule nahi, paragraph hai.
- Zaroori rules 3-4 priority ke hisaab se likho — conflict ho toh pehle wale jeetenge.
- Guardrail ko test set se test karo (agle module M3.6 mein) — bina test ke "lagta hai kaam kar raha hai" illusion hai.
- Jo cheezein prompt se reliably control nahi hoti — sensitive actions, data access — wo code mein permission check se karo, prompt se nahi (M3.8).
Exercise
Question: Model ka persona aur behavior set karne ke liye kaunsa message role use hota hai?
Question: Agar user ki zaroori info missing ho toh system prompt mein kya likhna chahiye — model guess kare ya ek clarifying sawaal poochhe?
Question: System prompt aur user message — kaunsa stable app rules ke liye hai?
Common mistakes
- System prompt mein sab kuch bhar dena: 200 rules likhoge toh model unme se 5 hi seriously lega. 5-8 clear, priority-ordered rules likho — har ek line ka matlab hona chahiye.
- Task-specific instruction system prompt mein daalna: Aaj wali ticket ka data ya is-call ka kaam system prompt mein likh diya — har call pe rewrite, prompt lamba, aur purana context reh jaata hai. Task user message mein rakho.
- Out-of-scope behavior specify hi na karna: Loan approval tak ka sawaal aaye toh model apne aap gyaan ulega ya promise kar baithega. Scope se bahar hone pe kya bolna hai — ek fixed sentence likho.
Hotel ke receptionist ko apni role ki fixed sheet milti hai — greet karo, check-in karo, complaint ho toh manager bulao. Yehi system prompt hai; aur aaj ka khaas order (user task) alag se aata hai:
ROLE SHEET (system — hamesha same):
- Guest ko English/Hindi dono mein samjho
- Refund kabhi mat promise karo — manager ko bolo
- Complaint 2 line mein note kar ke escalate karo
TODAY KA ORDER (user — badalta rehta hai):
"Room 214 ka AC kaam nahi kar raha"
Receptionist role sheet se hat-ta nahi — model bhi.- Q: System prompt mein kya aata hai? — Purpose, scope, behavior (tone/length), boundaries aur output expectations — sab stable rules.
- Q: Stable rules aur task instructions kaise alag karte hain? — System = policy (har call same), user message = is-call ka payload.
- Q: Model jab missing info pe guess kare toh? — System prompt mein fallback likho: ek clarifying sawaal poochho, guess nahi.
- Q: System prompt ko security boundary maanna sahi hai? — Nahi; wording se attack nahi rukte, sensitive actions code mein permission check se control karo.
System prompt design clear. Agla lesson — Controlling Output — mein seekhenge style, length, format aur JSON kaise maangein.