Classify support tickets and score accuracy against gold standard
Triage customer support tickets by category and urgency with confidence scores. Compare model output against a gold standard dataset using confusion matrices.
Routing customer support tickets directly based on raw LLM responses without verification sends misclassified tickets to the wrong departments. Restrict classification to a closed taxonomy, require confidence ratings with verbatim evidence, and benchmark outputs against a curated gold standard dataset with confusion matrices. A similar validation pattern for structured output is covered in convert tables to CSV and validate columns.
[1] Prepare a test set of 30 tickets alongside a human-verified gold standard. This sample simulates a home appliance rental provider with 5 categories (Billing, Installation, Malfunction, Cancellation, Other) containing 6 tickets each. Situations involving safety hazards or immediate financial loss are flagged as Urgent.
T01 | Water is pouring out from under the ice water purifier and flooding the kitchen floor. I'm worried about an electrical short, please send a technician immediately.T02 | My rental fee was debited twice this month, once on the 25th and again on the 27th. Please verify the duplicate charge of $39.90 and issue an immediate refund.T03 | The dishwasher installation technician was scheduled to visit at 2 PM today but didn't show up without any notice. Our restaurant opens tonight, how are you going to handle this?…T14 | A repair technician visited three times already, but the dishwasher drying issue persists. If the unit cannot be replaced, I will cancel the contract without penalty.…T30 | I lost the user manual and want to download it from the website, but I cannot find the exact model number.Define the gold standard in a CSV file.
id,category,urgencyT01,Malfunction,UrgentT02,Billing,UrgentT03,Installation,Urgent…T14,Cancellation,Normal…T30,Other,Normal[2] Build the classification prompt. Define distinct category boundaries and instruct the model to assign Low confidence when a ticket overlaps multiple intents.
You are a support ticket triage specialist for a home appliance rental service.Read the 30 support tickets inside <tickets>, classify each into a Category and Urgency level, determine Confidence, and format the output as a Markdown table. [Classification Definitions]1. Category (Billing | Installation | Malfunction | Cancellation | Other)- Billing: rental payments, double charges, payment date/card changes, tax invoices, statements- Installation: new setups, relocations, technician appointments, site requirements, trade-ins- Malfunction: leaks, abnormal noise, error codes, component breakdowns, repair requests- Cancellation: lease completion, early termination, penalty fee inquiries, device pickup- Other: supplies purchase, shipping tracking, address updates, user manuals, account verification2. Urgency: Urgent (safety risk, business interruption, financial loss) | Normal (routine requests)3. Confidence: High (unambiguous single category) | Low (boundary cases or mixed intents) [Output Rules]- Output only a Markdown table: | ID | Category | Urgency | Confidence | Evidence |- Process IDs T01 through T30 sequentially without omissions.- Quote a verbatim sentence or phrase from the ticket body as Evidence. <tickets>(30 ticket texts)</tickets>[3] Execute the prompt non-interactively with external MCP tools and user settings disabled.
$ claude -p --model claude-sonnet-5-5 --max-turns 1 --tools "" --setting-sources "" --strict-mcp-config < run/triage.en.prompt.txt > run/triage.en.2.out.txt$ cat run/triage.en.2.out.txt| ID | Category | Urgency | Confidence | Evidence ||---|---|---|---|---|| T01 | Malfunction | Urgent | High | Water is pouring out from under the ice water purifier and flooding the kitchen floor. || T02 | Billing | Urgent | High | My rental fee was debited twice this month, once on the 25th and again on the 27th. || T03 | Installation | Urgent | High | Our restaurant opens tonight, how are you going to handle this? |…| T14 | Malfunction | Normal | Low | If the unit cannot be replaced, I will cancel the contract without penalty. |…| T30 | Other | Normal | High | I lost the user manual and want to download it from the website, but I cannot find the exact model number. |[4] Create an evaluation script to score accuracy and build a confusion matrix. It checks that the table has 5 columns, that no ID is repeated or missing, that category, urgency and confidence use the allowed values, and that each Evidence string appears word for word inside its own ticket. Structural errors stop the run before any score; an evidence mismatch is reported after the scores and makes the exit code 1. It only checks that the evidence is in the ticket, not that it is a good reason for the label.
import csv, sys CATS, URGS, CONFS = ["Billing", "Installation", "Malfunction", "Cancellation", "Other"], ["Urgent", "Normal"], ["High", "Low"]tickets = {k.strip(): v.strip() for k, v in (l.split("|", 1) for l in open(sys.argv[1], encoding="utf-8") if "|" in l)}gold = {r["id"]: r for r in csv.DictReader(open(sys.argv[2], encoding="utf-8"))}rows = [[c.strip() for c in l.strip().strip("|").split("|")] for l in open(sys.argv[3], encoding="utf-8") if l.startswith("|")]rows = [r for r in rows if not set("".join(r)) <= set("-: ")][1:] preds, errs, bad_evid = {}, [], []for n, r in enumerate(rows, 1): if len(r) != 5: errs.append(f"row {n}: {len(r)} columns"); continue tid, cat, urg, conf, evid = r if tid in preds: errs.append(f"row {n}: duplicate ID {tid}"); continue if cat not in CATS or urg not in URGS or conf not in CONFS: errs.append(f"{tid}: value out of range") if tid not in tickets or evid not in tickets[tid]: bad_evid.append(tid) preds[tid] = rerrs += [f"{t}: missing from the table" for t in gold if t not in preds]if errs: print("Validation failed:", errs); sys.exit(1) ok = lambda i, k: sum(preds[t][i] == g[k] for t, g in gold.items())print(f"category accuracy: {ok(1, "category")}/{len(gold)}, urgency accuracy: {ok(2, "urgency")}/{len(gold)}")print("confusion matrix (rows: gold, columns: predicted) " + " ".join(CATS))for a in CATS: print(f"{a}: " + " ".join(str(sum(1 for t, g in gold.items() if g['category'] == a and preds[t][1] == p)) for p in CATS))low = [t for t in gold if preds[t][3] == "Low"]print("low confidence:", ", ".join(f"{t}(gold {gold[t]["category"]}, predicted {preds[t][1]})" for t in low) or "none")if bad_evid: print(f"evidence not found verbatim in the ticket: {bad_evid}"); sys.exit(1)[5] Run it on both English outputs. Run 1 scores the same as run 2 but exits with 1, because the model changed the evidence of T08.
$ python run/verify_triage_en.py run/tickets.en.txt run/gold.en.csv run/triage.en.1.out.txtcategory accuracy: 29/30, urgency accuracy: 30/30confusion matrix (rows: gold, columns: predicted) Billing Installation Malfunction Cancellation OtherBilling: 6 0 0 0 0Installation: 0 6 0 0 0Malfunction: 0 0 6 0 0Cancellation: 0 0 1 5 0Other: 0 0 0 0 6low confidence: T14(gold Cancellation, predicted Malfunction)evidence not found verbatim in the ticket: ['T08']$ python run/verify_triage_en.py run/tickets.en.txt run/gold.en.csv run/triage.en.2.out.txtcategory accuracy: 29/30, urgency accuracy: 30/30confusion matrix (rows: gold, columns: predicted) Billing Installation Malfunction Cancellation OtherBilling: 6 0 0 0 0Installation: 0 6 0 0 0Malfunction: 0 0 6 0 0Cancellation: 0 0 1 5 0Other: 0 0 0 0 6low confidence: T05(gold Other, predicted Other), T13(gold Installation, predicted Installation), T14(gold Cancellation, predicted Malfunction)[6] Test the script on two hand-made bad outputs (not model output): one with a repeated ID (triage-bad-dup.en.out.txt) and one with an invented evidence sentence (triage-bad-evid.en.out.txt). Both exit with 1.
$ python run/verify_triage_en.py run/tickets.en.txt run/gold.en.csv run/triage-bad-dup.en.out.txtValidation failed: ['row 4: duplicate ID T03', 'T04: missing from the table']$ python run/verify_triage_en.py run/tickets.en.txt run/gold.en.csv run/triage-bad-evid.en.out.txtevidence not found verbatim in the ticket: ['T02'][7] Analyze failure points and boundary cases. In ticket T14 ("A repair technician visited three times already, but the dishwasher drying issue persists. If the unit cannot be replaced, I will cancel the contract without penalty."), the customer couples a recurring breakdown with a cancellation demand. The gold standard classifies this as Cancellation, whereas the model categorized it as Malfunction in both runs. The model marked T14 as Low confidence in both runs. In run 2 it also marked T05 and T13 as Low, and the remaining 27 tickets were all correct (27/27). In run 1 only T14 was Low. That is one batch of 30 tickets, so the ratio is not an estimate of production accuracy.
Evidence changed in run 1: the model rewrote the T08 evidence from "...and would like to apply..." to "I would like to apply...", which the script flagged. In run 2 the evidence matched the ticket. A precedence rule for compound tickets is one thing to try, but a run with that rule was not made, so its effect is unknown:
- Priority Rule: When a customer expresses dissatisfaction with repairs and demands contract cancellation, prioritize 'Cancellation' over 'Malfunction'.Establishing evaluation benchmarks before prompt iteration aligns with Anthropic's Prompt Engineering Overview. OpenAI's Prompt Engineering Guide similarly recommends validating prompt modifications against systematic test suites.