Controlling the Output Format
Telling the AI exactly what shape the answer should take saves you editing time and makes the output usable in other tools.
Format Instructions You Can Use
| You want | Say |
|---|---|
| A short answer | "Answer in one sentence." |
| A list | "Give 5 bullet points." |
| A table | "Make a table with columns: Item, Price, Notes." |
| A formal message | "Write it as a formal email with a subject line." |
| Simple language | "Use words a Class 7 student understands." |
| A specific length | "Under 100 words." |
| A language | "Reply in simple Urdu." |
| Data for a program | "Return only valid JSON, no extra text." |
Tables
Tables are great for comparing things:
Example
Compare laptops for a university student in Pakistan with a
budget of Rs 150,000. Make a table with columns:
Type, Good for, Watch out for. Include 3 rows.JSON for Programs
JSON is a text format that programs can read easily. When you build an app, ask the AI for JSON and give the exact shape:
Example
Extract the details from this order message and return ONLY
JSON in this shape:
{"name": string, "item": string, "quantity": number, "city": string}
Message: "Assalam o Alaikum, I am Sana from Multan. Please send
2 cotton bedsheets."A good reply looks like {"name": "Sana", "item": "cotton bedsheet", "quantity": 2, "city": "Multan"}.
Using the JSON in Python
Never trust that the AI's text is perfect JSON. Parse it and handle errors:
Example
import json
ai_reply = '{"name": "Sana", "item": "cotton bedsheet", "quantity": 2, "city": "Multan"}'
try:
order = json.loads(ai_reply)
print(f"{order['name']} ordered {order['quantity']} x {order['item']}")
except json.JSONDecodeError:
print("The AI reply was not valid JSON. Ask again.")Sana ordered 2 x cotton bedsheet
Sometimes models wrap JSON in extra words like "Here is your JSON:". A small cleaning step helps:
Example
import json
ai_reply = 'Here is the data: {"city": "Multan", "quantity": 2} Hope this helps!'
start = ai_reply.find("{")
end = ai_reply.rfind("}") + 1
data = json.loads(ai_reply[start:end])
print(data["city"], data["quantity"])Multan 2
Many AI APIs offer a "structured output" or "JSON mode" setting that forces valid JSON. Use it in real apps, and still check the values.
Tone and Length
Format also includes how it sounds:
Example
Rewrite this reply to a customer. Tone: polite and warm.
Length: 2 sentences. Do not promise a refund.
Reply: "We can't do anything, the parcel is with the courier."Templates to Fill
You can give a template and ask the AI to fill it:
Example
Fill this template for a Python workshop:
Title:
Date:
Who should attend:
3 things you will learn:
-
-
-Exercise
Exercise
You are building an app that reads AI replies with code. Which instruction is best?
