4.4.10 · HinglishAlignment, Prompting & RAG

Prompt engineering best practices

1,859 words8 min readRead in English

4.4.10 · AI-ML › Alignment, Prompting & RAG


Prompt actually kya karta hai


Best practices (WHY / HOW ke saath)

1. Specific aur unambiguous raho

Bad: "Summarize this." Good: "Summarize the text below in 3 bullet points, each ≤15 words, for a non-technical manager."

2. Model ko ek role / persona do

3. Examples do — few-shot prompting

4. Step-by-step reasoning maango — Chain-of-Thought (CoT)

5. Prompt ko structure karo

6. Output format control karo

JSON, tables, ya ek fixed schema maango. WHY: Downstream code ko parseable output chahiye; schema specify karne se free-form drift kam ho jaati hai.

7. Model ko "I don't know" kehne do

8. Iterate karo: Forecast → Verify → Refine

Predict karo ki aapka prompt kya output dega, run karo, compare karo, aur gap ko steel-man karo. Prompting empirical hai.

Figure — Prompt engineering best practices

Worked examples


Common mistakes (Steel-manned)


Recall Feynman: 12-saal ke bacche ko explain karo

Socho ek bahut smart tota hai jo tumhare sentences finish karta hai us har kitaab ki madad se joh usne kabhi suni hai. Agar tum mumble karo, toh woh koi bhi random ending se complete kar deta hai. Agar tum clearly kaho, "Pretend you're a math teacher, show me each step, and answer at the end," toh tota usi careful style ko copy karta hai aur sahi kar leta hai. Prompt engineering sirf yeh seekhna hai ki tote se is tarah pucho jo use smart awaaz copy karne par majboor kare — clear instructions ke saath, kuch examples ke saath, aur "sochne" ki jagah ke saath.


Active-recall flashcards

Prompt fundamentally model ke output mein kya change karta hai?
Next tokens par conditional probability distribution — yeh steer karta hai ki learned distribution ka kaunsa region sample ho.
Chain-of-Thought hard reasoning kyun improve karta hai?
Transformers har token par fixed compute karte hain; reasoning tokens emit karne se computation kaafi tokens mein spread ho jaata hai, zyada effective serial compute milta hai (ek scratchpad ki tarah).
Zero-shot vs few-shot?
Zero-shot = prompt mein koi example nahi; few-shot = input→output examples jo weight updates ke bina in-context learning enable karte hain.
In-context learning kya hai?
Model inference time par prompt mein examples/instructions se task ka pattern infer karta hai, bina kisi parameter update ke.
<doc>...</doc> jaisi delimiters kyun use karein?
Instructions aur data ko alag karne ke liye, ambiguity kam karne aur prompt-injection attacks block karne ke liye.
Explicitly "I don't know" kyun allow karein?
Kisi bhi sawal ka default most-probable continuation ek jawab hota hai, isliye model hallucinate karta hai; abstain karne ki permission honest refusal ki probability badhati hai.
Steel-man: "lamba prompt = better" kyun nahi hai?
Filler attention dilute karta hai aur models mid-context tokens par under-attend karte hain ("lost in the middle"); high signal-to-noise length se behtar hai.
CoT kab use NAHI karna chahiye?
Trivial lookup/classification tasks par — yeh cost, latency add karta hai aur over-thinking errors inject kar sakta hai.
Acha few-shot example hone ki ek zaroorat?
Woh dono correctly formatted AUR correctly labeled hone chahiye, aur ideally diverse bhi.

Connections

  • Chain-of-Thought prompting — reasoning tokens par dedicated deep dive.
  • In-context learning — few-shot ke peeche ka mechanism.
  • Retrieval-Augmented Generation (RAG) — hallucination kam karne ke liye factual context supply karta hai.
  • Prompt injection & LLM security — kyun delimiters matter karte hain.
  • Temperature and sampling — randomness prompt steering ke saath kaise interact karti hai.
  • Alignment & RLHF — kyun models instructions follow karte hain.
  • Hallucination in LLMs — woh failure mode jise good prompting mitigate karta hai.

Concept Map

conditioned on

reshapes

has no goal, only

is a

steers sampling toward

shaped by best practices

reduce entropy via

condition on competence

define task by demo

spread compute

triggers

adds

more tokens equals

LLM next-token predictor

Context window

Prompt

P answer given prompt

Retrieval key into distribution

Correct region

Best practices

Be specific

Role / persona

Few-shot examples

Chain-of-Thought

In-context learning

Reasoning tokens as scratchpad

More effective compute