Model matrix and flakes
Qualify a cheaper model by running one suite across models side by side, and tell flaky failures from real regressions.
Qualify a model before you switch
A cheaper or newer model is a behavior change. Run the same suite across models and compare pass rate, cost and latency side by side before you switch:
uv run viewport-evals run --model claude-sonnet-4-6,claude-haiku-4-5
pnpm exec viewport-evals run --model claude-sonnet-4-6,claude-haiku-4-5Or set models in config ([tool.viewport.evals] models = [...], defineConfig({ evals: { models } }), or
VIEWPORT_EVALS_MODELS). In code, pass models= to run_cases or models to runCases.
Every case runs once per model, with one verdict per model:
- The agent receives the model as
CaseInput.model; call your provider with it. Outside a matrix it is unset, so the agent keeps its default. - Each model records to its own fixture,
<id>.<model>.fixture.json, so CI replays every column offline. - The trajectory carries the model in the
viewport.evals.modelattribute, and the verdict and report carry it too. - The pretty, markdown and GitHub reporters print a table with one row per model: counts, pass rate, cost and mean latency.
In this example, a support agent is checked on claude-sonnet-4-6 and the cheaper claude-haiku-4-5. Each case
runs three times and must pass two, so one lucky run cannot qualify a model:
# pyproject.toml in your project: the matrix lives in `models` (or `viewport-evals run --model a,b`).
#
# [tool.viewport.evals]
# models = ["claude-sonnet-4-6", "claude-haiku-4-5"]
MODELS = ["claude-sonnet-4-6", "claude-haiku-4-5"]// viewport.config.ts in your project: the matrix lives in `models:` (or `viewport-evals run --model a,b`).
export const config = defineConfig({
evals: { models: ["claude-sonnet-4-6", "claude-haiku-4-5"], worlds: { shop } },
});# yaml-language-server: $schema=https://getviewport.com/schemas/evals/case/v1.json
# One damaged item: refund that item only. Three runs; a model qualifies when two of them pass.
id: partial-refund
input: "My order LT-4810 came with a cracked kettle."
runs: 3
pass_threshold: 0.6 # 60% of 3 runs: at least 2 must pass
world:
shop:
seed:
customers:
CU-1: { id: CU-1, name: Odile, email: [email protected], card: { brand: visa, last4: "4242", status: valid } }
charges:
CH-1:
id: CH-1
customer_id: CU-1
amount: 8600
currency: usd
description: "Order LT-4810: cast iron kettle 5400, oolong sampler 3200"
idempotency_key: "order:LT-4810"
status: succeeded
amount_refunded: 0
expect:
tools:
in_order: [lookup_order, issue_refund]
calls:
- { tool_name: issue_refund, args: { amount: { lte: 5400 } } }
world:
shop:
state: { charges: { CH-1: { amount_refunded: 5400 } } }
# The cheaper model also has a tighter token budget to earn its place.
when:
- model: "claude-haiku-*"
expect: { budget: { tokens: 3500 } }
def test_the_cheaper_model_does_not_qualify_it_over_refunds() -> None:
cases = load_cases("evals/*.yaml", cwd=Path(__file__).parent)
config = resolve_config(agent=make_agent(), worlds={"shop": shop}, models=MODELS)
report = run_cases(cases, config=config, mode="live") # the models are scripts: nothing to record
print("\n".join(models_table(report["models"])))
assert [(r["model"], r["pass_rate"]) for r in report["models"]] == [
("claude-sonnet-4-6", 1),
("claude-haiku-4-5", 0.5),
]
haiku = next(v for v in report["verdicts"] if v["model"] == "claude-haiku-4-5" and v["id"] == "partial-refund")
assert haiku["status"] == "fail"
# Two of three runs must pass; after two failures that is out of reach, so the third run is skipped.
assert (haiku["passes"], haiku["required"]) == (0, 2)
assert not report["ok"] # in CI this run fails: do not switch yet
def test_model_narrows_the_matrix_the_way_the_cli_flag_does() -> None:
cases = load_cases("evals/*.yaml", cwd=Path(__file__).parent)
config = resolve_config(agent=make_agent(), worlds={"shop": shop}, models=MODELS)
# viewport-evals run --model claude-sonnet-4-6
report = run_cases(cases, config=config, mode="live", models=["claude-sonnet-4-6"])
assert report["ok"]
assert [(v["id"], v["model"], v["status"]) for v in report["verdicts"]] == [
("partial-refund", "claude-sonnet-4-6", "pass"),
("where-is-my-order", "claude-sonnet-4-6", "pass"),
]
test("the cheaper model does not qualify: it over-refunds", async () => {
const cases = await loadCases("evals/*.yaml", { cwd: import.meta.dirname });
const report = await runCases(cases, {
config: resolveConfig({ ...config.evals, agent: makeAgent() }),
mode: "live", // the models are scripts: nothing to record
});
console.log(modelsTable(report.models ?? []).join("\n"));
expect(report.models?.map((r) => [r.model, r.pass_rate])).toEqual([
["claude-sonnet-4-6", 1],
["claude-haiku-4-5", 0.5],
]);
const haiku = report.verdicts.find((v) => v.model === "claude-haiku-4-5" && v.id === "partial-refund");
expect(haiku?.status).toBe("fail");
// Two of three runs must pass; after two failures that is out of reach, so the third run is skipped.
expect(haiku?.passes).toBe(0);
expect(haiku?.required).toBe(2);
expect(report.ok).toBe(false); // in CI this run fails: do not switch yet
});
test("--model narrows the matrix, the way the CLI flag does", async () => {
const cases = await loadCases("evals/*.yaml", { cwd: import.meta.dirname });
const report = await runCases(cases, {
config: resolveConfig({ ...config.evals, agent: makeAgent() }),
mode: "live",
models: ["claude-sonnet-4-6"], // viewport-evals run --model claude-sonnet-4-6
});
expect(report.ok).toBe(true);
expect(report.verdicts.map((v) => [v.id, v.model, v.status])).toEqual([
["partial-refund", "claude-sonnet-4-6", "pass"],
["where-is-my-order", "claude-sonnet-4-6", "pass"],
]);
});Expectations per model
expect.when adds expectations that apply only when the run's model matches a name or a glob. The case above gives
the cheaper model a tighter token budget with when: [{ model: "claude-haiku-*", expect: ... }].
Assertions from a when block are named when[<i>].<name>. A when block cannot contain error, world or
another when.
Flaky or regressed
A failure in a nondeterministic agent is either a real regression or noise. run --repeat N re-runs each failed case
N more times, without writing fixtures, and classifies it:
- flaky: at least one re-run passed. Reported with the observed rate (
flaky: 2 of 3 re-runs passed), and it does not fail the run. - regressed: no re-run passed. It fails the run as before.
Pass repeat= to run_cases or repeat to runCases in code. It is most useful on live suites, where the model
really varies. For a known nondeterministic case, prefer runs with pass_threshold, which states the rate you accept up front (see
cases and expectations).
Next: results and the viewer.
Production replay
Turn a Langfuse, LangSmith or Braintrust trace into a regression test with one command, replay a new agent version against the trace's real tool responses, and assert the behavior diff.
Results and the viewer
Every local run writes a results directory of plain JSON files, served read-only by viewport-evals ui and readable by any tool.