Sub topic 10
Pinning model versions and detecting drift
This chapter assumes you can call an LLM API, write pytest tests, and read a GitHub Actions workflow. It also assumes you have a golden dataset and a baseline pass rate, as covered in earlier chapters.
Why pinning matters
Your eval suite measures one thing: how a specific model, prompt, and parameter set behave on your cases. If the model changes underneath you, the baseline stops meaning anything. A failing build then tells you nothing about your own change.
Providers publish two kinds of model names:
| Name type | Example form | Behavior |
|---|---|---|
| Alias | `vendor-model-latest` | Points to a new snapshot when the provider updates it. |
| Dated snapshot | `vendor-model-2025-06-01` | Stays fixed until the provider retires it. |
Use dated snapshots in CI and in production. Aliases are convenient for experiments, but they let the model change without any commit in your repository.
Keep the model ID in one place
Store the model ID in configuration, not scattered through code. Then a model change is a visible diff, and the CI path filter can trigger the suite when it changes.
import os
MODEL_ID = os.environ.get("LLM_MODEL_ID", "vendor-model-2025-06-01")
TEMPERATURE = 0.0
MAX_TOKENS = 512
def model_settings():
return {
"model": MODEL_ID,
"temperature": TEMPERATURE,
"max_tokens": MAX_TOKENS,
}Record these settings with every eval run. When a result changes, you can then tell whether the settings changed or the model's behavior did.
Two kinds of change
Pinning protects you from silent updates, but two situations remain.
- Planned upgrade. You choose a new snapshot. Run the full suite against it, compare with the baseline, and update the baseline deliberately if the new model is accepted.
- Drift. The model ID is the same, but results move. Providers can change serving infrastructure, safety layers, or retire and redirect a snapshot. Your code did not change, so only a scheduled run will catch it.
Detecting drift with a scheduled run
A pull request trigger only fires when files change. Drift happens when no files change, so you need a schedule trigger. The nightly run uses the same suite and the same baseline check from the thresholds chapter.
name: nightly-drift-check
on:
schedule:
- cron: "0 3 * * *"
workflow_dispatch:
jobs:
drift:
runs-on: ubuntu-latest
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
env:
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_MODEL_ID: vendor-model-2025-06-01workflow_dispatch lets you start the run by hand, which helps when you want to confirm a suspected change right away.
Separating drift from noise
A single dip can be ordinary variance. Before you call it drift, compare against what you expect from the noise alone. A simple rule is to alert only after the pass rate falls below the tolerance on two consecutive nightly runs.
def is_drift(history, baseline, tolerance=0.02, consecutive=2):
recent = history[-consecutive:]
if len(recent) < consecutive:
return False
return all(rate < baseline - tolerance for rate in recent)Here history is a list of nightly pass rates, oldest first. The function returns True only when each of the last consecutive runs is below the limit.
For finer detection, store the exact output of a few stable cases each night and diff them. A change in a deterministic case at temperature 0 is a stronger signal than a small shift in the overall rate.
Common errors
- Using an alias in CI. Results change with no commit. Pin a dated snapshot.
- Hard-coding the model in several files. One location gets updated and another is missed, so you test a different model than you ship.
- Updating the baseline during an upgrade without review. The baseline then absorbs a real regression. Change the model and the baseline in separate, reviewed steps, or at least state the reason in the pull request.
- Ignoring retirement notices. Providers announce when a snapshot will be removed. Add the retirement date to your team calendar and run the full suite on the replacement well before then.
Exercise
Your nightly run fails once with a pass rate 3 points below the baseline, and the next night it is back to normal. The model ID is a dated snapshot and no files changed. Should you alert on drift, and what would change your answer?
Show answer
Do not alert yet. One dip is consistent with ordinary variance, and the recovery suggests noise or a transient provider issue. Alert if the rate stays below baseline minus tolerance on consecutive runs, or if deterministic cases at temperature 0 start producing different output. Either would indicate the model behavior changed.
Exercise
Why does a planned model upgrade belong in a pull request while drift detection belongs in a scheduled workflow?
Show answer
An upgrade is a change to your repository (the model ID in config), so a pull request trigger catches it and lets reviewers see the diff and the eval results. Drift happens with no repository change, so only a time-based schedule can detect it.