Skip to content
Forward Deployed

Forward Deployed
T3 exercise

Exercise: one triage task, three prompts, two models

Track
Prompt & Context Engineering
By
Sourav Banerjee
Last updated
30 Nov 2026

Report an issue

01 Context

Problem statement

Larkspur Cloud wants its support inbox triaged by a model. Each ticket must come back as JSON with a category the router can match exactly (Billing, Technical or Security, the handbook's three) and the language the ticket is written in. Before anyone picks a prompt or a model, you run the same 20 tickets through three prompt patterns on two local models and score every reply.

The rule you apply comes from lessons 3 and 4 of T3.1: freeze the prompt set and the labelled tickets, swap only the pattern or the model, and let code check every reply against the contract. A reply that reads well but breaks the contract counts as a failure.

02 Outcomes

What you will learn

  • Write one output contract and three prompts that differ only in their pattern.
  • Check every reply with a strict parser instead of reading it by eye.
  • Compare two models through one wrapper, with the model id in one place.
  • Weigh accuracy against contract failures, latency and prompt tokens per call.
  • Find the tickets a pattern or a model gets wrong and say why.

03 Setup

Before you start

Lessons

Dataset

20 labelled support tickets (7 Billing, 7 Technical and 6 Security, with 12 in English and 8 in Spanish, Portuguese, German and French), 3 few-shot example tickets kept apart from them, and the Larkspur handbook, whose support page holds the routing rule. All in data/.

Code

load_jsonl from src/lab_kit.py, ChatOllama from langchain_ollama, and json from the standard library for the parser.

Environment

The course's default environment (uv run jupyter lab), plus Ollama running locally with ollama pull qwen2.5:3b and ollama pull llama3.2:3b. Everything runs offline, with no API keys. The two local models stand in for the two hosted providers of lesson 3 of T3.1. The comparison method is the same, but the numbers say nothing about hosted models.

04 Architecture

Experiment workflow

The tickets, the contract, the parser, the temperature and the reply cap stay fixed. Only the pattern and the model change.

Diagram: Load the tickets, the examples and the handbook rule; Zero-shot template; Few-shot, one example per category; Reason-then-answer; Each prompt on qwen2.5:3b and llama3.2:3b, temperature 0; Strict parser: one JSON object, exact category; Valid replies, category and language accuracy, seconds and tokens per call; List the failures and the misrouted tickets; Pick a pattern for each modelDiagram: Load the tickets, the examples and the handbook rule; Zero-shot template; Few-shot, one example per category; Reason-then-answer; Each prompt on qwen2.5:3b and llama3.2:3b, temperature 0; Strict parser: one JSON object, exact category; Valid replies, category and language accuracy, seconds and tokens per call; List the failures and the misrouted tickets; Pick a pattern for each model

Extension: send each contract failure back once with the parser's error, and count the failures left.

05 Build

Implementation tasks

  1. Task 1: Load the data

    Load tickets.jsonl and examples.jsonl, and read the routing rule from the handbook's support page (Support tiers) instead of retyping it.

  2. Task 2: Write the contract and three prompts

    Every prompt has the same persona line, the routing rule, the ticket inside triple quotes and the contract: one JSON object with category and language. The zero-shot prompt is only that. The few-shot prompt adds the three example tickets with their replies, one per category. The reason-then-answer prompt adds a reason field, written before category.

    {"category": "Billing" or "Technical" or "Security", "language": "<English name of the ticket's language>"}
    
  3. Task 3: Write a strict parser

    A reply passes only if the whole reply is one JSON object, category is exactly one of the three names and language is a string. Anything else is a contract failure and scores as wrong.

  4. Task 4: Run every configuration

    Put the model id in one wrapper. Run the three prompts on both models at temperature 0 with the same reply cap, and record each reply, its time and its prompt tokens. Make one warm-up call per model first.

    ChatOllama(model="qwen2.5:3b", temperature=0, num_predict=200)
    

    New here: msg.usage_metadata["input_tokens"] gives the prompt tokens of each call, and time.perf_counter() around the call gives its latency.

  5. Task 5: Score and read the misses

    Score each configuration, then list every contract failure with its error and every ticket at least one configuration misrouted.

  6. Task 6: Extension: one retry with the error

    Send each failed reply back once with the parser's error, as lesson 4 of T3.1's validation loop does, and count how many failures are left.

06 Measure

Record results

What you enter stays in this browser only.

Model and patternValid replies (of 20)Category accuracyLanguage accuracySeconds per callPrompt tokens per callFailures left after one retry (extension)
qwen2.5:3b, zero-shot
qwen2.5:3b, few-shot
qwen2.5:3b, reason-then-answer
llama3.2:3b, zero-shot
llama3.2:3b, few-shot
llama3.2:3b, reason-then-answer

Accuracy is over all 20 tickets, so a contract failure counts as wrong on both fields. Seconds per call depend on your machine. Prompt tokens per call are each model's own count, so compare them between patterns, not between models.

07 Verify

Done when

0 of 4 done

What you enter stays in this browser only.

08 Debug

Common mistakes

Reading replies by eye

A fluent reply in a code fence still breaks a parser. Lesson 4 of T3.1 calls this the unchecked contract.

Few-shot examples from the test set

If the examples are test tickets, the model can copy the answer. Lesson 3 of T3.1 calls this the leaky test.

Ranking on one number

A pattern can raise accuracy on one model and break the contract on the other. Compare each row on every column.

Parsing leniently for one configuration

If one row strips code fences and another does not, the parser, not the prompt, decides the comparison.

09 Transfer

Interview angle

“How would you choose a prompt and a model for a step whose output code must parse?”

Show a model answer

Fix the contract, a labelled set and a strict parser. Run each candidate prompt on each candidate model through one wrapper, and compare contract failures, accuracy, latency and tokens per call. Then add validation and one retry, because no prompt keeps a contract every time.

10 Review

Worked solution

The worked solution is solution/p02_exercise_solution.ipynb (open in Colab). Locally, open it from exercise/solution/ so ../data/ resolves, start Ollama, pull both models and run the notebook top to bottom. In Colab, clone the repository first, because the notebook reads its data and src/lab_kit.py from it, and install and start Ollama in the runtime.

Show our run and the reasoning

Our run: qwen2.5:3b and llama3.2:3b through Ollama 0.40.6, langchain-ollama 1.1.0, offline.

Model and pattern Valid replies (of 20) Category accuracy Language accuracy Seconds per call Prompt tokens per call Failures left after one retry (extension)
qwen2.5:3b, zero-shot 20 0.95 0.95 1.85 180 none to retry
qwen2.5:3b, few-shot 20 0.95 1.00 0.96 307 none to retry
qwen2.5:3b, reason-then-answer 20 0.90 0.95 1.12 201 none to retry
llama3.2:3b, zero-shot 20 0.85 1.00 0.60 176 none to retry
llama3.2:3b, few-shot 20 0.90 1.00 0.44 303 none to retry
llama3.2:3b, reason-then-answer 20 0.70 1.00 0.94 197 none to retry

Every one of the 120 replies kept the contract, so the extension had nothing to retry. At temperature 0, with the contract written out in full, both 3B models returned bare JSON every time. That is one run on 20 tickets, not a guarantee, and the parser stays in place.

All six configurations misroute t12, the ticket that asks how to give a support engineer access to a server. Every model reads "server" and picks Technical. The handbook routes access to Security, and no example in the prompt sits on that boundary. It is the easy-boundary failure of lesson 1 of T3.1, and the fix is an example on it, not a different pattern.

Few-shot is the best row on both models. On qwen2.5:3b it fixes the one language miss (t15, a Portuguese ticket that zero-shot labelled English) and keeps 0.95 on category. On llama3.2:3b it routes t16 correctly and lifts category accuracy from 0.85 to 0.90. It costs about 127 more prompt tokens on every call. The example tickets were not test tickets, so the gain is not a leaky test.

Reason-then-answer is the worst row on both models. On llama3.2:3b it falls to 0.70, and its reasons show why: "The ticket matches the 'Billing' category because it mentions a server issue and a potential storage problem" (t14). The sentence names Technical evidence and then picks Billing, so the reasoning does not drive the answer. On qwen2.5:3b it newly misroutes t07, reasoning that suspended servers are "a technical issue with the servers" and ignoring the failed payment. A one-word label gains nothing from a written step here, and the step costs about 20 prompt tokens and a longer reply on every call.

Seconds per call are noisy on a server shared with other jobs. In an earlier run of the same notebook, the same 120 calls gave the same labels and token counts but different times, so read the timing column as rough. The decision is few-shot on both models, with a fourth example on the access boundary as the next change to test.