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.

⏱ 20 min• Beginner• Reasoning & Decomposition

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".

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)
Rule of thumb: Sawalo se poocho: "Kya yeh rule next month bhi same rahega?" Haan toh system prompt, nahi toh user message. Isse prompt ka lifecycle clean rehta hai.

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.

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.

Boundary yaad rakho: System prompt behavior ka contract hai, security boundary nahi. Wording se attack nahi rukte — permissions hamesha application code mein. Yeh line interview mein bhi poochhi jaati hai.

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

Desi example: Hotel receptionist vs chef

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:

text
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.
Interview angle — yahan se sawaal aate hain
  • 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.
Lesson complete?

System prompt design clear. Agla lesson — Controlling Output — mein seekhenge style, length, format aur JSON kaise maangein.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course