Skip to content
mentoor

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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

  1. Turn the vibe check into a first eval set

    Skill: evals-why

    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)
    CaseTicket (shortened)Expected
    07Me cobraron dos veces el plan Probilling
    12(empty message)technical
    19Refund please, and move my order to 12 Elm Stbilling
  2. Rewrite the brittle test as an n-run test

    Skill: evals-nondeterminism

    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);});
  3. Add a regression gate with per-category floors

    Skill: evals-regression

    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

    1. Every category must stay at or above 85 percent.
    2. No category may fall more than 3 points below the stored baseline.
    3. Changes to eval cases need review by a second engineer and an explanation in the pull request.
  4. Run the gate in CI with least privilege

    Skill: sdlc-ci

    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 evals
  5. Release behind a flag with a canary and a kill switch

    Skill: llmops-release

    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
    StepAudienceMove on when
    1Kestrel staffNo wrong reply found in 100 tickets
    25% of tenantsMetrics within noise of control for 2 days
    325% of tenantsCost and quality still stable after 3 days
    4EveryoneOwner signs off; kill switch retested

Skills this scenario uses

Where to study