Lesson 45 — Beginner

Prompt Versioning, Cost & Caching

Prompt bhi code ki tarah versioned asset hai — badalta rehta hai, kisi ne kuch gadbad ki toh trace hona chahiye. Is lesson mein hum dekhenge prompts ko git ki tarah kaise track karein, variants ko quality/latency/token/cost pe kaise compare karein, unnecessary context kaise kaatein, aur prompt caching ka faayda kaise uthaayein.

⏱ 10 min• Beginner• Prompt Reliability & Debugging

Prompts ko code ki tarah version karo

WHAT

Prompt versioning matlab har prompt ka apna record — kaunsa version, kis model ke saath, aur kis result ke peeche kaunsa combination tha. Git-style tracking se debugging aur rollback dono aasaan ho jaate hain.

WHEN

Jaise hi prompt application mein jaaye (chatbot, pipeline) — wahan se har change ek "release" hai. Experiment phase mein bhi version labels rakhna baad mein pachtane se bachata hai.

WHERE

Repo mein prompts/ directory, config files, ya prompt registry — jahan bhi, ek jagah centred ho aur reviewable ho. Code review ke saath prompt review bhi lo.

prompts/
  triage/
    v1.md   # baseline — 2/3 test pass
    v2.md   # few-shot examples add kiye -> 3/3
    v3.md   # JSON keys fix kiye, token 20% kam
    current.md -> v3.md

# Har file ke upar header:
# model: <tumhara model>   changed: 2026-10-12   test-score: 3/3
# changelog: v2 se farq — examples add kiye, urgency label fix kiye

Har production result ke saath prompt version + model name log karo. Warna "pehle toh theek chalta tha" wali debugging kabhi khatam nahi hoti — tumhe pata hi nahi hoga kaunsa prompt tha jo user ko dikh raha tha.

Quality, latency, tokens, cost — charon dekho

import time

t0 = time.time()
resp = call(prompt, ticket)
latency = time.time() - t0
in_tok, out_tok = resp.usage.input_tokens, resp.usage.output_tokens
print(f"latency={latency:.1f}s  in={in_tok}  out={out_tok}")

# Compare: v3 ka score 3/3, v2 ka 2/3 -> v3 jeeta (quality first).
# Score same ho toh tie-break: kam tokens ya kam latency wala version.

Unnecessary context kaato

Rule of thumb: Har line ka prompt mein justification ho — "yeh kabhi kaam aati hogi" wali lines hata do. Chhota prompt: tez, sasta, aur aksar behtar follow karta hai instructions ko.

Prompt caching aur reusable prefixes

[STABLE PREFIX — har request mein same]  <- caching ka faayda yahin milta hai
- system rules
- tool definitions / schema
- few-shot examples

[VARIABLE TAIL — sirf yahi badalta hai]
- aaj ka user ticket
- current conversation turn

Bahut se LLM providers prompt caching support karte hain: agar tumhara prompt ka prefix pehle se gaya hai, toh provider us hisse ko dobara process nahi karta — input ke ush hisse ka rate (aur aksar latency) kam ho jaata hai. Faayda tabhi milta hai jab prefix bilkul byte-for-byte same ho.

Structure rule: Stable cheezein (system, tools, examples) hamesha prompt ke TOP mein, variable cheezein (user input) end mein. Beech mein timestamp ya random ID daal diya — prefix toot gaya, caching gayi. Provider docs mein caching support aur exact rules check karo.

Exercise

Question: Prompt caching ka faayda uthane ke liye prompt ka kaunsa hissa stable hona chahiye?

Question: Prompt file ka record rakhne ka best tareeka — comments mein changelog ya git version control?

Question: Prompt ki token count ka direct proxy kya hai — sirf latency, sirf cost, ya dono?

Common mistakes

Desi example: Kirana ledger — har naye rate list ka record

Dukaandar har naye rate list ko taarikh ke saath register mein likhta hai — purana bill dikhao toh kis rate pe bana hai pata chalta hai. Prompt versioning bhi wahi:

text
Register (git) :
  v1 : baseline list         -> bill #12 test-pass
  v2 : GST alag column       -> bill #18 test-pass
  v3 : 10 item se upar discount -> bill #25 test-pass

Kal complaint aaye "bill galat tha" -> v2 wali file kholo, diff dekho, turant pata chalo.
Interview angle — yahan se sawaal aate hain
  • Q: Prompt versioning kyun zaroori hai? — Har production result ke peeche kaunsa prompt+model combo tha wo trace karna, rollback possible karna.
  • Q: Prompt variants compare kaise karo? — Quality (test score) pehle, phir tie-break: token count aur latency.
  • Q: Prompt caching kaam kaise karti hai? — Provider purane prefix ko cache karta hai; faayda ke liye prefix byte-for-byte same aur stable hona chahiye.
  • Q: Context trim karte waqt kya dhyan rakho? — Test set chalao; kabhi kabhi ek useful clue chala jaata hai aur score gir jaata hai.
Lesson complete?

Versioning, cost aur caching clear. Agla lesson — Prompt Injection Basics — mein dekhenge external text ko untrusted kaise treat karna hai.

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