TECHNOLOGIESTieInn Technologies

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:

  1. Task: what to do, in one or two sentences.
  2. Context: the data or background, clearly marked (e.g. inside <review> … </review> tags).
  3. Rules: length, tone, what to avoid, what to do if unsure.
  4. Output format: "Reply with one word: positive, negative or mixed."
  5. 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 →

Questions

Open in Code Lab5 free questions
5 questions

    Writing good prompts: instructions, context and examples

  1. Question 1easy

    Which prompt is most likely to give a short, safe support reply?

  2. Writing good prompts: instructions, context and examples

  3. Question 2easy

    The model keeps stating the wrong return window. What's the most direct fix?

  4. Writing good prompts: instructions, context and examples

  5. Question 3medium

    Why wrap the customer's message in tags like <customer_message> ... </customer_message>?

  6. Writing good prompts: instructions, context and examples

  7. 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))
  8. Writing good prompts: instructions, context and examples

  9. 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)

5 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.