Testing what you cannot predict
For engineers
Non-deterministic outputs, regression suites, release gates and CI for LLM features.
The one-sentence idea: an AI feature gives different answers on different runs, so you test it with a written set of real cases, a pass rate instead of an exact match, a CI gate that cannot be weakened quietly, and a staged release with a switch that turns it off.
The case
Kestrel Helpdesk sells support software to small shops. Its team has added a reply suggester: it reads an incoming ticket, picks a category (billing, account, shipping, technical) and drafts a reply for the agent. Maya, the developer, tried six tickets by hand and all six looked good. The product lead wants it live by Friday.
Nothing in the code is wrong. The risk is that nobody knows how often the suggester is right, whether the next prompt edit makes it worse, or how to stop it if it misbehaves. A normal unit test cannot answer those questions, because the output is not the same on every run. This scenario walks through the five pieces that do.
Why it matters
A support reply that quotes the wrong refund rule costs real money and trust. Because models sample their output, a feature can pass on Monday and fail the same case on Tuesday with no code change. Providers also retire and replace models, which changes behaviour without a commit. Teams that rely on a vibe check find out about these problems from customers.
How to do it
- Replace the vibe check with evidence. Collect about 30 real tickets with personal data removed, including the ugly ones: a non-English message, an empty one, an angry one, one with two requests. Write the expected category for each. A person reviews every label. This is the first eval set, and it turns "feels good" into a number you can compare.
- Test with tolerances. Run each case several times and assert a pass rate, for example at least 9 of 10 runs correct. Temperature 0 and a fixed seed reduce variation but providers do not promise identical output, so exact-match tests stay fragile. Record the model version with every result.
- Guard against regressions. Keep a fixed suite of cases that passed before and run it on every prompt, model or tool change. Gate on per-category floors and on the drop from the baseline, not only on the overall average, which hides a collapse in one category. Run the same suite on the old and new model before an upgrade.
- Run it in CI, safely. The suite runs as a required check on every pull request that touches a prompt or model setting. Give the job the least access it needs. Do not hand model API keys to code from forks. If an agent proposes fixes for red builds, it opens a pull request that a person approves. Watch for the three fake fixes: lowering the threshold, deleting the failing case, and rerunning until green.
- Release in stages. Put the feature behind a flag read at request time. Serve staff first, then a 5 percent canary compared with a control group, then 25 percent, then everyone. A launch review checks evals, budget, data retention, a tested kill switch and a named on-call owner. After launch, watch quality, cost and abuse together.
Before and after
Before: "Six tickets worked, ship it Friday to everyone."
After: "30 real tickets, 10 runs each, per-category floors, a required CI check, 5 percent canary on Friday with the kill switch tested, and a decision to widen on Monday from the monitoring table."
The second plan takes a few more days and removes the surprise.
What goes wrong
- Leaked test cases. The hardest tickets get pasted into the prompt as examples, then the same tickets score the prompt. The gain is memory, not skill.
- A gate people learn to ignore. A zero-miss rule on sampled output fails by chance, so the team reruns or lowers the bar until it goes green.
- A green average with a red category. Refund replies fall from 95 to 78 percent while the overall rate rises.
- Evals and live traffic differ. Offline suites cover the cases someone wrote down. Only a canary shows what customers really send.
Steps
Turn the vibe check into a first eval set
Maya lists 30 real tickets from the last month, strips names and emails, and writes the expected category beside each. She adds a Spanish ticket, an empty message and a ticket that asks for a refund and an address change. A colleague checks every label.
First eval set (excerpt) Case Ticket (shortened) Expected 07 Me cobraron dos veces el plan Pro billing 12 (empty message) technical 19 Refund please, and move my order to 12 Elm St billing Rewrite the brittle test as an n-run test
The first test compared one output to one string and failed one run in five. Maya runs each case 10 times, asserts a pass rate of at least 0.9 and stores the model name and date with the result.
tests/classify.test.ts tests/classify.test.ts
const RUNS = 10;const MIN_RATE = 0.9;test.each(cases)('$id', async ({ ticket, expected }) => { const labels = await Promise.all( Array.from({ length: RUNS }, () => classify(ticket)), ); const rate = labels.filter((l) => l === expected).length / RUNS; expect(rate).toBeGreaterThanOrEqual(MIN_RATE);});Add a regression gate with per-category floors
The full suite becomes the baseline. A candidate passes only if each category stays above its floor and no category drops more than 3 points from the baseline. The same suite runs on the old and the new model before the provider's retirement date.
Eval gate policy v2 Eval gate policy v2
- Every category must stay at or above 85 percent.
- No category may fall more than 3 points below the stored baseline.
- Changes to eval cases need review by a second engineer and an explanation in the pull request.
Run the gate in CI with least privilege
The workflow runs on pull requests that touch prompts or model settings. It uses the plain pull request trigger, so code from forks never sees the model key. A fix agent may open pull requests, and a person approves the merge.
.github/workflows/evals.yml .github/workflows/evals.yml
name: evalson: pull_request: paths: ['prompts/**', 'config/model.ts']permissions: contents: readjobs: run: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: npm ci && npm run evalsRelease behind a flag with a canary and a kill switch
The suggester is read from a flag service on each request, off by default. Friday: staff, then 5 percent of tenants. Maya compares the canary with a control group on acceptance, latency, cost per ticket and escalations before widening to 25 percent.
Rollout plan Step Audience Move on when 1 Kestrel staff No wrong reply found in 100 tickets 2 5% of tenants Metrics within noise of control for 2 days 3 25% of tenants Cost and quality still stable after 3 days 4 Everyone Owner signs off; kill switch retested
Skills this scenario uses
Where to study
- Develop test cases (Claude docs) (opens in a new tab)DocsFree
How to write test cases with expected answers and grade model output, including model-graded checks.
- Working with evals (OpenAI docs) (opens in a new tab)DocsFree
A second vendor's guide to building eval sets and running them against prompts and models.
- Secure use reference (GitHub Actions) (opens in a new tab)DocsFree
Least-privilege tokens and the risks of secrets with untrusted pull request code.
- About protected branches (GitHub Docs) (opens in a new tab)DocsFree
Required checks and required reviews that keep an agent or a hurried developer from merging past the gate.
- Feature Toggles (martinfowler.com) (opens in a new tab)ArticleFree
Kinds of flags, how to pick who sees a feature and how to retire a flag once it is no longer needed.
- Release Engineering (Google SRE Book) (opens in a new tab)BookFree
Reproducible releases, staged rollout and why release practice belongs with the engineering team.