tutorials
Writing eval suites for LLM email classifiers
September 23, 2026

You moved your inbox triage from regex to an LLM. It works on the three emails you tested. Then you reword the prompt to fix one edge case and, three weeks later, notice it stopped flagging refund requests. Nothing failed. Nothing logged. There was no test.
An LLM email classifier is code that happens to be expressed in English, and like any code it regresses. Unlike code, a one-word prompt change can flip a decision boundary you never see, and there is no compiler to catch it. The fix is the same discipline LLM teams use everywhere else: an eval suite. This is how to build one for email classification by hand, what makes email-specific evals tricky, and how Tinbox ships an eval suite attached to every interpreter so a prompt change cannot regress quietly.
What is an eval suite for an LLM email classifier?
An eval suite is a table of fixture emails, each paired with an explicit expectation, scored into a pass/fail report. It is the LLM-shaped equivalent of a unit test: instead of asserting add(2, 2) === 4, you assert "this angry email fires the complaint classifier as high severity" and "this billing question does not fire it at all."
Three properties make it useful:
- It is ground truth you control. The cases encode what you mean by "complaint" or "OTP," not what a benchmark means.
- It is a regression guard. Run it on every prompt, schema, or model change and you find out immediately when a boundary moved.
- It is deterministic when you want it to be. By recording model outputs you can run the suite in CI with zero token cost and zero flakiness, then run it against the live model on demand.
Everything below builds toward those three properties.
How do I build a classifier eval from scratch?
Start with the classifier itself, then wrap a scorer and a fixture table around it. Here is a minimal complaint classifier with a structured output schema, the shape any serious classifier should have.
// classifier.ts
import { z } from "zod";
const Output = z.object({
is_complaint: z.boolean(),
severity: z.enum(["low", "high"]).optional(),
issue: z.string().optional(),
});
type Output = z.infer<typeof Output>;
const INSTRUCTIONS = [
"Decide whether the customer is expressing a complaint, frustration, or a threat to leave.",
"If so, rate severity (high if angry, threatening to churn, or escalating; else low) and",
"summarize the specific issue in one short line. Respond as JSON:",
'{ "is_complaint": boolean, "severity"?: "low"|"high", "issue"?: string }',
].join(" ");
export interface Email {
from: string;
subject: string;
body: string;
}
// `callModel` is your provider call: it takes a prompt, returns a JSON string.
export async function classify(
email: Email,
callModel: (prompt: string) => Promise<string>,
): Promise<Output> {
const prompt = `${INSTRUCTIONS}\n\nFrom: ${email.from}\nSubject: ${email.subject}\n\n${email.body}`;
const raw = await callModel(prompt);
return Output.parse(JSON.parse(raw)); // schema-validate; throws on garbage
}
The structured output schema is the load-bearing decision here. Classifiers that return free text are nearly impossible to eval because you end up string-matching prose. A schema gives you stable fields to assert against and makes a malformed response a loud ZodError instead of a silent wrong answer.
What should an eval case actually assert?
Assert the structured decision you act on, never the model's raw words. LLM phrasing drifts between runs even at temperature 0, so asserting the exact issue string is a recipe for flaky tests. Assert the fields that change behavior: did it fire, what severity, what category.
// evalTypes.ts
import type { Email } from "./classifier";
export interface Expectation {
/** Should the classifier fire at all? The most important single field. */
matched?: boolean;
/** Severity the verdict must report, when it fires. */
severity?: "low" | "high";
}
export interface EvalCase {
name: string;
email: Email;
expect: Expectation;
/** Recorded model JSON for this fixture (deterministic eval). */
stubOutput: unknown;
}
Note matched is optional but central, and that we carry a stubOutput per case. That field is what makes the eval deterministic, covered next.
How do I make LLM evals deterministic and free to run?
Do not call the live model in CI. Run the model once per fixture, record the JSON it returns, and feed that recorded JSON back through a stub model. The eval then exercises your parsing and decision logic deterministically, with no tokens spent and no network flake.
// runEvals.ts
import { classify, type Email } from "./classifier";
import type { EvalCase } from "./evalTypes";
export interface CaseResult {
name: string;
pass: boolean;
failures: string[];
}
export async function runEvals(cases: EvalCase[]): Promise<CaseResult[]> {
const results: CaseResult[] = [];
for (const c of cases) {
// Stub model: ignore the prompt, return this case's recorded JSON.
const stubModel = async (_prompt: string) =>
typeof c.stubOutput === "string" ? c.stubOutput : JSON.stringify(c.stubOutput);
const out = await classify(c.email, stubModel);
const failures: string[] = [];
if (c.expect.matched !== undefined && out.is_complaint !== c.expect.matched) {
failures.push(`matched: expected ${c.expect.matched}, got ${out.is_complaint}`);
}
if (c.expect.severity !== undefined && out.severity !== c.expect.severity) {
failures.push(`severity: expected ${c.expect.severity}, got ${out.severity}`);
}
results.push({ name: c.name, pass: failures.length === 0, failures });
}
return results;
}
This separates two concerns that people wrongly fuse. The offline eval (above) checks "given this model output, does my code do the right thing?" It is deterministic, free, and belongs in CI. The online eval checks "does the live model produce the right output for this email?" It costs tokens and varies run to run, so you run it locally on demand, then re-record the outputs. Conflating them gives you a CI suite that is both expensive and flaky, which teams quietly stop trusting.
Why are negative cases the ones that catch real bugs?
Negative cases assert the classifier does NOT fire on normal mail, and they catch the regressions that positive cases structurally cannot. A classifier that returns is_complaint: true for every email passes 100% of your positive cases and is completely useless. Only a negative case ("a polite billing question is not a complaint") fails it.
Here is a fixture table with the ratio you want: positives, but also explicit negatives.
// cases.ts
import type { EvalCase } from "./evalTypes";
export const complaintCases: EvalCase[] = [
{
name: "angry churn threat -> high",
email: {
from: "angry@customer.com",
subject: "This is unacceptable",
body: "Third time my order is late. If this isn't fixed today I'm cancelling.",
},
stubOutput: { is_complaint: true, severity: "high", issue: "repeatedly late orders" },
expect: { matched: true, severity: "high" },
},
{
name: "mild grumble -> low",
email: {
from: "user@customer.com",
subject: "Small issue",
body: "The widget is a little confusing to set up, took me a while.",
},
stubOutput: { is_complaint: true, severity: "low", issue: "confusing setup" },
expect: { matched: true, severity: "low" },
},
// --- Negatives: these MUST NOT fire ---
{
name: "happy customer -> no fire",
email: {
from: "fan@customer.com",
subject: "Love it!",
body: "Just wanted to say the new feature is fantastic. Keep it up!",
},
stubOutput: { is_complaint: false },
expect: { matched: false },
},
{
name: "neutral billing question -> no fire",
email: {
from: "user@customer.com",
subject: "Question about billing",
body: "Do you offer annual plans? Trying to understand the options.",
},
stubOutput: { is_complaint: false },
expect: { matched: false },
},
];
Run it as an ordinary test and you get a regression guard:
// evals.test.ts
import { describe, it, expect } from "vitest";
import { runEvals } from "./runEvals";
import { complaintCases } from "./cases";
describe("complaint classifier evals", () => {
it("passes every case", async () => {
const results = await runEvals(complaintCases);
const failed = results.filter((r) => !r.pass);
expect(failed.map((f) => `${f.name}: ${f.failures.join(", ")}`)).toEqual([]);
});
});
A green run when you change the prompt is the whole point. Now watch a real failure mode. Suppose you reword the instructions to fire on "any negative sentiment." Re-record the live model outputs, run the suite, and the neutral billing case turns red:
FAIL evals.test.ts > complaint classifier evals > passes every case
AssertionError: expected [ 'neutral billing question -> no fire: matched: expected false, got true' ] to deeply equal []
That single line is the entire value proposition. The prompt change you thought was harmless made the classifier trigger-happy, and you found out in two seconds instead of from a customer wondering why their pricing question got escalated.
How do I keep the suite honest as the classifier evolves?
Add every real misclassification as a new case the moment you find it. The suite should encode your production failures, not a fixed snapshot from launch day. When a complaint slips through, copy the email (scrubbed), write the expectation it should have met, and add it. The next prompt change that would reintroduce that miss now fails loudly.
Three practices keep the suite trustworthy:
- Re-record outputs when you change the prompt, schema, or model id. Stale recordings test old behavior. Treat the recorded JSON like a fixture you regenerate, not a constant you hand-edit.
- Run the online eval before shipping a prompt change. The offline suite validates your code; the online run validates that the live model still produces the outputs you recorded. Both, then ship.
- Keep cases self-contained. Each case carries its own email, expectation, and recorded output. No shared mutable state, no ordering dependency. A case you can read in isolation is a case you trust.
How does Tinbox handle classifier evals?
Tinbox ships every email classifier as an interpreter with its eval suite attached, so the discipline above is the default rather than something you bolt on. An interpreter is the classifier; the eval suite is the ground truth that travels with it. The shapes you built by hand map one-to-one onto the real API.
// app/interpreters.config.ts
import { defineInterpreters, complaint } from "@tinbox/engine/interpreters";
export default defineInterpreters([
complaint(),
// ...your own interpreters
]);
Each interpreter declares an output schema and a pure toVerdict function, and packages a cases array as an InterpreterWithEvals. The eval runner is the same runEvals you wrote, only batteries-included: LLM cases feed a per-case stubOutput through a one-shot stub model (deterministic, zero tokens), and you pass a real model to run the same cases online in dev.
import { runEvals } from "@tinbox/engine/interpreters";
import { complaintEvals } from "@tinbox/engine/interpreters/builtins";
// Deterministic, offline: scores recorded outputs. Costs nothing, runs in CI.
const report = await runEvals(complaintEvals);
console.log(`${report.passed}/${report.total} passed`);
// Online eval (dev only): run the SAME cases against the live tenant model.
const live = await runEvals(complaintEvals, { model: myModel });
The expectation language is richer than the toy version too. A case can assert matched, exact extra keys (subset match), required flags, a category, a component, and whether the interpreter proposed a draft (draft: true) without sending it. The built-in suites run as real vitest tests, so the same green-bar gate protects the defaults you inherit. And the inbox playground exposes a "Run evals" button that scores the same suite per case, so a non-engineer can sanity-check a rule change before it ships.
Two honest caveats. First, drafts are proposed only: a Tinbox interpreter can draft an apology, but a human reviews and sends it, by design. Second, the online eval against the live model costs tokens and is dev-only; it never runs on the ingest path, where every inbound message would otherwise pay for an LLM call.
For the surrounding machinery (how classification fires on inbound mail, and how the same classifier feeds search and triage), see building AI inbox triage rules and the broader AI-native inbox stack. If you want the OTP-extraction angle specifically, detecting OTP and verification emails walks the same eval pattern for code extraction.
What does a good eval suite buy you, concretely?
A green eval run is permission to change a prompt without fear. That is the deliverable. You stop treating the classifier as a fragile artifact you are afraid to touch and start iterating on it like normal code: tweak the instructions, run the suite, read the diff in pass/fail, ship. The cases accumulate into a precise, executable definition of what your classifier means, which is worth more than any prose spec.
Build it by hand and you understand exactly what it is doing. Or skip the plumbing: Tinbox interpreters arrive with the eval runner, the stub-model determinism, the negative-case discipline, and a playground button already wired, so the only thing left for you to write is the cases that matter to your inbox.
Deploy this yourself: npx tinbox init <domain>, then open the interpreters playground and hit "Run evals." The interpreter and eval docs cover the full expectation language and the online-versus-offline split.
Frequently asked questions
What is an eval suite for an LLM email classifier?
It is a table of fixture emails, each paired with an expectation (should the classifier fire, with what category, flags, or extracted fields), scored by a function into a pass/fail report. It plays the role unit tests play for ordinary code: a regression guard you run on every prompt or model change.
How do I make LLM evals deterministic in CI?
Do not call the live model in CI. Record the model's JSON output once per fixture and feed that recorded output through a stub model, so the eval exercises your parsing and verdict logic deterministically and costs zero tokens. Run the real model on demand locally as a separate online eval when you change the prompt.
Why do negative cases matter in classification evals?
Precision regressions are the dangerous ones. A classifier that fires on every email passes all positive cases. Negative cases assert the classifier does NOT fire on normal mail (a billing question is not a complaint, a receipt is not an OTP), which is the only way to catch a prompt change that made the model trigger-happy.
How many eval cases do I need to start?
Start with 10-20 cases per classifier: a handful of clear positives, a handful of clear negatives, and the ambiguous edge cases that already burned you. Grow the suite by adding any real misclassified email as a new case, so the suite encodes your production failures over time.
Should evals assert exact model output or downstream behavior?
Assert downstream behavior, not the raw model text. LLM phrasing drifts run to run even at temperature 0. Score the structured result you actually act on: did it fire, what category, which flags, what extracted fields. That is stable and is what your application depends on.