Writing good prompts: instructions, context and examples
LLM Fundamentals & Prompting · 10 questions
Short notes
Key idea
A good prompt reads like a brief for a smart new colleague: clear task, the context they need, the format you want, and an example or two. Vague prompts get generic answers.
Syntax
A reliable shape:
- Task: what to do, in one or two sentences.
- Context: the data or background, clearly marked (e.g. inside
<review>…</review>tags). - Rules: length, tone, what to avoid, what to do if unsure.
- Output format: "Reply with one word: positive, negative or mixed."
- Examples (few-shot): one to three input → output pairs.
Example
Weak: "Is this review good?" Strong: "Classify the customer review inside the tags as positive, negative or mixed. Reply with one word. If it mentions both praise and a complaint, say mixed." Followed by two short examples, then <review>Fast delivery, but the box was damaged.</review>. Answer: mixed.
Traps
- Unstated assumptions: the model can't read your mind about format or audience.
- Examples that are all alike make the model copy them too closely; vary them.
- Mixing instructions and data lets text inside the data act like instructions; separate them.
- Test on many inputs, not one; a prompt that works once can fail on the next case.
Want the full lesson with step-by-step examples, a project and a certificate? LLM Fundamentals & Prompting course, ₹180 →
- Question 1easy
Which prompt is most likely to give a short, safe support reply?
- Question 2easy
The model keeps stating the wrong return window. What's the most direct fix?
- Question 3medium
Why wrap the customer's message in tags like <customer_message> ... </customer_message>?
- Question 4medium
You want one example ticket for every category. How many examples does this pick?
one_each = support_tickets.groupby("category").head(1) print(len(one_each)) - Question 5hard
The practice model replies with a function that checks the prompt. What does this print?
from practice_llm import ScriptedModel def check(messages): prompt = messages[-1]["content"] return "ok" if "<article>" in prompt else "missing article" def build(question, article=None): text = f"<question>{question}</question>" if article: text = f"<article>{article}</article>\n" + text return text model = ScriptedModel([check, check]) a = model.generate([{"role": "user", "content": build("Return window?", "10 days")}]).text b = model.generate([{"role": "user", "content": build("Return window?")}]).text print(a, "/", b)
Writing good prompts: instructions, context and examples
Writing good prompts: instructions, context and examples
Writing good prompts: instructions, context and examples
Writing good prompts: instructions, context and examples
Writing good prompts: instructions, context and examples
5 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.