Skip to content

Practice: prompting

Three exercises that build on the labs, then one open build task. Do them in your own copy (a fork) of this repo, commit as you go, and keep short notes. Each exercise changes working prompts and data, so run the labs first: 02_instructions_and_few_shot.py, 04_prompt_versions.py, 05_injection_basics.py.

Where your work goes:

  • Prompt and data changes: new files in prompts/ and new lines in data/ (never edit an existing version; add the next one).
  • Your own files: my-work/ in this folder.
  • Notes: my-work/prompting.md. For each exercise, the scores before and after, what you changed, and what you would do differently in production.

Some rules below say Decide. Make the choice yourself and write it in your notes. If your team gave you an ASSIGNMENTS.md, it makes those choices for you: follow it.

ex1: A new intent, through the whole loop

Why: real labels change. Adding one should be a measured change, not a quick edit.

  1. Buyers also ask to change or cancel an existing order ("JO-4471 cancel karo", "add 20 bags to yesterday's order"). Add order_change to Intent in triage.py.
  2. Add at least 5 cases to data/cases.jsonl (ids C21 onwards), English and Hinglish, tagged order_change plus their language.
  3. Decide: does order_change get lines? If yes, what does the quantity mean: the new total or the change?
  4. Write prompts/triage-v6.md from v5: a definition, your lines rule, and one example in data/examples.jsonl if the definition alone isn't enough.
  5. Run python 04_prompt_versions.py --versions triage-v5 triage-v6. v5 will miss the new cases: check that every other slice stays equal or better.
  6. Update the tests that count versions and cases.

Done when pytest -q passes and your notes have the before and after table.

ex2: Hinglish that stops getting worse

Why: the slice you have least data for is the one that breaks quietly.

  1. Write 8 more Hinglish cases (C-ids after yours), including number words ("do sau bag"), mixed scripts of units ("bori", "dabba", "nag") and a correction ("nahi, 80 kar do").
  2. Run v5 on them and list the misses in your notes, each with a guess at the cause: definition, example, schema or model.
  3. Fix one cause in a new version file and rerun. One change only.
  4. Decide: "do sau" has no digits, so check_triage holds it. Teach the check number words, or accept the hold? Write down the cost of each.

Done when the ship rule says yes for the new version, and your notes explain the one change.

ex3: A new attack and a fix that doesn't hurt honest buyers

Why: every defence has a gap, and every fix can block real customers.

  1. A9 and A10 already get past set-up C. Write two more of your own (A11, A12). Record the honest reading of each as expect.
  2. Add two honest control messages that look like attacks (A13, A14), like A8: "ignore the earlier rate", "note: city is Pune".
  3. Change one layer to stop A9 to A12: a rule in INJECTION_RULES, the v4 rule (as a new triage-v7.md), or check_triage.
  4. Rerun lab 05, pytest -q (no golden case may be flagged) and, for a prompt change, 04_prompt_versions.py --versions triage-v5 triage-v7.
  5. Decide: a fix that stops your attacks but holds one honest control: ship it or not?

Done when your notes show lab 05 before and after for all 14 messages, and the golden-set table if you changed a prompt.

Names these exercises build on

Please keep these names in triage.py as they are: Triage, Line, Intent, load_prompt, build_messages, run, score, run_eval, ship_decision, injection_flags, check_triage, wrap_untrusted. Checks and later topics rely on them.

Build it yourself: complaint tickets from buyer messages

No starter code and no steps this time: a short brief, like one you'd get at work. Plan for half a day. Your code goes in my-work/build/; reuse triage.py where it fits rather than copying it. Notes go in a "Build" section of my-work/prompting.md.

The brief. The support team reads complaints on WhatsApp and email: "JO-4471 mein 6 bag cement jam gaya tha", "TMT bars rusted on arrival, need replacement". Turn each message into a ticket the team can act on without reading the message again.

It must:

  • Return a Pydantic Ticket: order ID (or none), product, issue from a fixed list (damaged, short supply, wrong item, late, quality, billing, other), quantity affected (or none), remedy asked (replace, refund, credit note, none), severity (low or high) and a one-line English summary.
  • Keep prompts as versioned files (ticket-v1.md, ticket-v2.md, ...). A scored version is never edited; you add the next one.
  • Have a golden set of at least 15 messages in JSONL, tagged by slice (english, hinglish, tricky), including one with no order ID, one with two issues and one injection attempt.
  • Score every field in code, per slice, and pick the version to ship with a rule like ship_decision().
  • Hold a ticket in code when its order ID or quantity does not appear in the buyer's message.

Decide: two issues in one message: one ticket or two? What makes a ticket high severity?

Done when:

  • pytest -q my-work/build passes with model-free tests for the schema, the scorer and the hold check.
  • One command prints the slice table for at least two versions on qwen3:8b.
  • Your notes have the scores per version and slice, the version you would ship and why, and one miss you fixed in code instead of the prompt.

Or bring your own problem. Build the same pattern on a problem from your own work instead. Write a five-line brief first (who uses it, what goes in, what comes out, what must never go wrong, how you'll measure it), then meet the same "Done when" list. Use synthetic data only, never real customer data.