Lesson 43 — Beginner

Controlling Output — Style, Length & Format

Model apna jawaab khud shape karta hai — kabhi lamba paragraph, kabhi bullet, kabhi hazaaron words ka essay. Is lesson mein hum seekhenge style, length aur format ko instructions se kaise control karein (headings, labels, tables, JSON), aur kab prompt enough nahi hota — tab structured-output/schema enforcement ki zarurat padti hai.

⏱ 10 min• Beginner• System Prompt Design

Style, length aur format control

WHAT

Output control matlab prompt mein clearly likhna ki jawaab kaisi ho — tone, maximum length, structure (heading, bullets, table, JSON) aur kya include/exclude karna hai. Model khud guess na kare.

WHEN

Har production use-case mein — product mein UI fix hai toh format fix hona hi chahiye. User-facing text, API payloads, reports — sab jagah output spec likho.

WHERE

Chat replies (tone + length), reports (headings + bullets), APIs (JSON keys), tables (columns) — jahan bhi downstream kuch parse ya render karta hai, wahan format control compulsory hai.

# OUTPUT SPEC — prompt ke end mein apna block likho
Style   : professional, lekin Hindi/Hinglish. Slang nahi, emoji nahi.
Length  : 3 line se zyada nahi.
Format  : pehle ek heading, phir bullet points. Table mat use karo.
Include : order number aur expected date.
Exclude : apologies ya filler lines.

Har constraint ek measurable cheez ho — "chhota answer" vague hai, "3 line se zyada nahi" measurable hai. Model ko number do, tabhi follow hoga.

Headings, labels, table aur JSON

prompt = """Neeche diye order ke liye ek JSON object banao.
Sirf JSON, koi extra text ya explanation nahi.

Keys: order_id (string), status (one of: "packed", "shipped", "delivered"), eta_days (number)

Order: #A118 — aaj packing ho gayi, courier ko kal subah de denge."""
Trap: JSON maangna aur JSON guarantee karna alag baat hai. Prompt likhne se model aksar JSON deta hai — lekin kabhi kabhi ```json fences ya ek line ka preamble bhi saath mein. Parser ke liye woh crash hai.

Kab prompting enough nahi hai

# Prompt = request. Schema = guarantee. Dono alag layer hain.
resp = call_llm(prompt, response_format={"type": "json_schema", "schema": ORDER_SCHEMA})

try:
    order = json.loads(resp.text)
except json.JSONDecodeError:
    order = call_llm(prompt + "\nSirf valid JSON object do.", response_format=...)  # repair pass
Decision rule: Jawaab insaan padhega — prompt kaafi. Jawaab code padhega — schema/validation bhi lagao. Prompt engineering ko format enforcement ka replacement mat samjho.

Semantic instruction vs format enforcement

Do tarah ke control hote hain: semantic ("jawaab helpful aur neutral ho", "sensitive topic pe careful") — yeh prompt ki language se hi chalte hain. Aur enforcement ("status sirf teen allowed values mein se ek ho") — yeh schema ya code check se hoti hai. Dono ko mix mat karo.

Exercise

Question: Response 50 words ke andar chahiye — yeh kis type ka instruction hai: style, length, ya format?

Question: JSON output ki structure guarantee chahiye toh prompt ke alawa kya use karte hain? (schema / tone)

Question: Jawaab ka format batane wali line (jaise "table mein do") ya jawaab ka tone batane wali line ("professional ho") — kaunsi semantic instruction hai?

Common mistakes

Desi example: Dabba menu vs JSON

Kirane wale ko bolna "ek list banao" aur "bill ka format wahi rakhna — item, qty, rate, total ke columns" — dono alag baatein. Format instruction ke bina woh har baar alag list banayega:

text
VAGUE      : "Items ki list banao"
-> kabhi 5 item, kabhi sab, kabhi rate ke bina

FORMAT SPEC: "4 columns: item | qty | rate | total. Total row last mein."
-> har baar same shape — bill machine padh legi

Code wahi format expect kare = model JSON expect kare. Shape fix karo.
Interview angle — yahan se sawaal aate hain
  • Q: Output ka style control kaise karte hain? — Prompt mein tone/length/format ke labelled instructions; measurable bounds ke saath.
  • Q: Prompt aur schema enforcement mein farq? — Prompt semantic soft control deta hai; schema programmatic guarantee deta hai code-parseable output ke liye.
  • Q: Kab structured output use karna chahiye? — Jab output kisi program mein parse hota hai (API, DB); insaan ke liye prompt kaafi hai.
  • Q: JSON parse fail ho toh kya karo? — Repair pass (sirf JSON maango) ya retry, plus schema mode agar provider support karta hai.
Lesson complete?

Output control ka toolkit ready. Agla lesson — Prompt Reliability & Debugging — mein seekhenge prompts ko test-set se kaise debug karte hain.

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