Sub topic 9
Controlling cost and runtime with test tiers
This chapter assumes you have a golden dataset in JSONL, pytest checks that run against it, and a CI workflow like the one in the previous chapter. Here you will split that suite into tiers. Each tier trades coverage for cost and speed, and each runs at a different point in your workflow.
Why one suite is not enough
Every eval case is a model call. It costs tokens and takes seconds. A suite of 500 cases, each run three times to handle nondeterminism, makes 1,500 calls. If a pull request triggers that on every push, you pay for it repeatedly and developers wait on it.
Teams respond in one of two bad ways. They run everything on every push and the bill grows. Or they trim the suite until it no longer catches regressions. Tiers avoid both. A small suite gives fast feedback, and a larger suite runs less often.
A three-tier layout
| Tier | Runs when | Cases | Repeats | Checks | Target time |
|---|---|---|---|---|---|
| Smoke | Every push to a pull request | 20 to 50 | 1 | Deterministic only | Under 2 minutes |
| Full | Nightly schedule, or before merge on risky changes | All | 3 to 5 | Deterministic and judge | 10 to 30 minutes |
| Release | Before a model upgrade or release | All, plus adversarial and long-context | 5 or more | All, with human spot checks | As long as needed |
Smoke catches broken formats, missing keys, and failed API calls. Full measures pass rate against the baseline. Release is where you compare a candidate model with the pinned one.
Marking cases with tiers
Put the tier in the data, so you can change it without editing code. Add a tier field to each case, and a smoke flag for the fast subset.
{"id": "refund-001", "tier": "smoke", "input": "I want my money back", "required_keys": ["intent", "reply"], "must_contain": ["refund"]}Then register a pytest marker and select cases at collection time. Put this in evals/conftest.py:
import os
def pytest_addoption(parser):
parser.addoption("--tier", default=os.environ.get("EVAL_TIER", "smoke"))
def pytest_generate_tests(metafunc):
if "case" not in metafunc.fixturenames:
return
import json
from pathlib import Path
tier = metafunc.config.getoption("--tier")
lines = Path("evals/cases.jsonl").read_text(encoding="utf-8").splitlines()
cases = [json.loads(line) for line in lines if line.strip()]
if tier == "smoke":
cases = [c for c in cases if c.get("tier") == "smoke"]
metafunc.parametrize("case", cases, ids=[c["id"] for c in cases])With this hook, the test function from the earlier chapter needs no CASES list or parametrize decorator of its own. You run pytest evals --tier=smoke for the fast suite and pytest evals --tier=full for everything.
Wiring tiers into CI
Use the pull request trigger for smoke and a schedule for the full tier. Both can live in one workflow file.
name: prompt-regression
on:
pull_request:
paths:
- "prompts/**"
- "evals/**"
- "app/**"
schedule:
- cron: "0 3 * * *"
workflow_dispatch:
jobs:
evals:
runs-on: ubuntu-latest
env:
EVAL_TIER: ${{ github.event_name == 'pull_request' && 'smoke' || 'full' }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -r requirements.txt
- run: pytest evals -q -n 4The -n 4 flag needs the pytest-xdist package in requirements.txt. Parallel workers cut wall-clock time, but watch your provider's rate limits. If you see 429 errors, lower the worker count or add retries with backoff.
Other ways to cut cost
- Cache responses. Key a cache on the model name, parameters, and the full prompt text. When none of those changed, reuse the stored output. Invalidate on any change to the prompt or settings, or the cache will hide the regressions you are looking for.
- Run cheap checks first. If the output is not valid JSON, skip the judge call for that case.
- Use a smaller judge. Validate it against human labels first, as described in the judge chapter.
- Run only when relevant. The
pathsfilter in the workflow stops evals from running on documentation changes. - Cap output length. Set
max_tokensin the eval configuration so a runaway response cannot inflate cost.
Choosing the smoke subset
Pick cases on purpose. Include at least one case for each output format, each safety constraint, and each prompt in the application. Add any case that failed in production. Avoid picking at random, because a random sample can miss an entire feature.
Exercise
Your full suite has 400 cases and runs each case 3 times, with one model call per run. A pull request touches only one prompt. Give two changes that reduce the cost of checking that pull request, and say what risk each one adds.
Show answer
Run the smoke tier with 1 repeat, which cuts calls from 1,200 to about 50 but gives a noisier signal, so use it only for hard failures. Cache responses for cases whose prompt did not change, which avoids repeat calls but risks stale results if the cache key leaves out the model name or parameters. The full tier still runs nightly to catch what the smoke tier misses.