Skip to main content

modeldrift: Provider-side model drift monitor.

Providers change models behind the same name. modeldrift runs a fixed probe set against a model on a schedule and tells you, with the diff, when its answers shift.

pip install modeldrift && modeldrift init && modeldrift baseline --model <model> --endpoint <url>

Needs Python 3.9 or newer, nothing else (standard library only). Then run modeldrift check with the same --model and --endpoint whenever you want to know if the model moved. The default endpoint is a local Ollama (http://127.0.0.1:11434/v1).

A real run: baseline, then the model silently changes one answer (42 to 43), then check. The endpoint here is a local stand-in server with canned answers (not a live provider); the model name is demo-model, and the exit code is 1:

$ modeldrift baseline --model demo-model --endpoint http://127.0.0.1:18765/v1
baseline written: ./modeldrift-baseline.json (11 probes, model demo-model, probe set 9d548916fb51)
(exit 0)
$ modeldrift check --model demo-model --endpoint http://127.0.0.1:18765/v1
modeldrift report: demo-model
endpoint: http://127.0.0.1:18765/v1
probe set: 9d548916fb51
drift index: 9.09 (1 of 11 probes changed)
probes: 1 changed, 10 unchanged, 0 errored, 11 total
DRIFT ALERT: index exceeds threshold 0.0
  CHANGED math-1 (exact output differs)
    --- baseline
    +++ current
    @@ -1 +1 @@
    -42
    +43
  UNCHANGED fact-1 (exact output matches)
  UNCHANGED logic-1 (exact output matches)
  UNCHANGED fact-2 (exact output matches)
  UNCHANGED json-1 (all 2 field(s) match)
  UNCHANGED json-2 (all 2 field(s) match)
  UNCHANGED explain-1 (similarity 1.000 vs threshold 0.90)
  UNCHANGED summarize-1 (similarity 1.000 vs threshold 0.85)
  UNCHANGED refusal-1 (similarity 1.000 vs threshold 0.85)
  UNCHANGED code-1 (similarity 1.000 vs threshold 0.85)
  UNCHANGED instruction-1 (expected substring 'quasar' present in output)
verdict: needs attention - review the CHANGED probes above; if the change is expected, record a new baseline: modeldrift baseline --force --model demo-model --endpoint <url>
(exit 1)
  • Fixed, versioned probes. 11 standard probes (math, facts, reasoning, JSON format, summarization, refusal, code, instruction), hashed so numbers are only compared across the same set.
  • Drift is separated from noise. Three samples per probe and a majority verdict; noisy probes report UNSTABLE instead of crying wolf, and errors are never counted as drift.
  • Local and $0. Talks only to the endpoint you choose, keys come from an environment variable, no telemetry. OpenAI-compatible endpoints and the native Anthropic API.

PyPI License Python

Limits up front

  • No real provider was probed during development: the HTTP path was tested against local fake servers, and the Anthropic path is not yet run against the live API (unverified).
  • The comparison is deterministic; the check is not. It samples a nondeterministic provider, so reruns can differ, and a clean run shows drift was not seen, not that it cannot happen.
  • Index numbers are only comparable across runs of the same probe set, model and endpoint.
  • No hosted index, dashboards, schedulers or alert integrations: the gate is an exit code and a report. No native Gemini adapter.

Full list: The honesty contract and What v0.3.0 does NOT do. Changes: CHANGELOG.md.

The GitHub repository is private for now. The banner above, and the badges, resolve only once the repository is made public.

promptregress (now prompt-assert) tests YOUR prompts; modeldrift monitors THEIR models. Langfuse and LangSmith trace your traffic but do not run a fixed probe set against provider drift. A public drift index is the long game; v1 is the local monitor that makes it possible.

Install (local, $0)

pip install modeldrift
# or, from a clone of this repo:
pip install .
# system Python is PEP 668 externally-managed on some machines;
# then use a venv instead:
python3 -m venv .venv && .venv/bin/pip install .
# or run without installing:
PYTHONPATH=. python3 -m modeldrift --help

Python 3.9+, stdlib only, no third-party dependencies.

Usage

# 1. Write the standard probe set (11 probes: math, facts, reasoning,
#    JSON format, explanation, summarization, refusal, code, instruction)
modeldrift init

# 2. Record the baseline for a model + endpoint
modeldrift baseline --model gpt-x --endpoint https://api.example.com/v1

# 3. Re-run and compare (the gate/alert) — run this on a schedule
modeldrift check --model gpt-x --endpoint https://api.example.com/v1

# 4. Re-render the last check without calling the endpoint
modeldrift report

# 5. Show the local weekly index (one number per model per week)
modeldrift index

# Inspect a probe set without baselining:
modeldrift probe --model gpt-x --endpoint https://api.example.com/v1

# Measure provider noise before you baseline (writes no files):
modeldrift calibrate --model gpt-x --endpoint https://api.example.com/v1 --runs 3

calibrate runs the whole probe set --runs times (2-10, default 3) and prints the call count first (probes x samples x runs = X calls), because on a paid provider every call costs money. For each probe it reports how many runs produced a majority that matches the most common run result. Any probe below N/N is marked UNSTABLE on this provider: a drift check on that probe will be noisy there. Three runs is a small sample, so a clean calibrate shows the noise was not seen, not that it cannot happen. It never writes a baseline, run file, or index entry. Exit 0, or 2 on an endpoint or usage error.

Defaults: probes ./modeldrift-probes.json, baseline ./modeldrift-baseline.json, last run ./modeldrift-last-run.json, index ./modeldrift-index.json, endpoint http://127.0.0.1:11434/v1 (Ollama's OpenAI-compatible base). All commands accept --json.

Anthropic (Claude) endpoints

export ANTHROPIC_API_KEY=...   # read from the environment only
modeldrift baseline --model <claude-model-id> --endpoint https://api.anthropic.com/v1
modeldrift check    --model <claude-model-id> --endpoint https://api.anthropic.com/v1

--api-style auto (the default) picks the native Messages API for api.anthropic.com and OpenAI-compatible everywhere else; force it with --api-style anthropic|openai (e.g. an Anthropic-compatible gateway). For Anthropic the key comes from ANTHROPIC_API_KEY unless you pass --api-key-env. Only text blocks count as output. Tested against a local fake server only; not yet run against the live API (unverified).

The weekly drift index (defined precisely)

One number per model per week (June's design):

index = 100 * (probes CHANGED) / (probes CHANGED + probes UNCHANGED)

Errors and UNSTABLE probes are EXCLUDED from the denominator and reported separately. Range 0–100; higher means more drift. If no probe produced a comparable pair, the index is undefined (reported as n/a) — never 0, because 0 would claim "no drift" when nothing was measured.

check writes one entry per model per ISO week into the local index file. Entries carry provenance — the probe-set hash and the endpoint — so future aggregation can filter to comparable runs: index numbers are only comparable across runs of the SAME probe set. That provenance is the bridge to the future public index. The file is local only — not a hosted service, not shared anywhere, and v0.3.0 sends nothing anywhere.

Example drift report

A provider silently changes one answer (42 → 43), run against the standard 11-probe set. The gate fires (real run, abridged — the 10 unchanged probes follow the same pattern):

modeldrift report: demo-model
endpoint: http://127.0.0.1:36843/v1
probe set: 9d548916fb51
drift index: 9.09 (1 of 11 probes changed)
probes: 1 changed, 10 unchanged, 0 errored, 11 total
DRIFT ALERT: index exceeds threshold 0.0
  CHANGED math-1 (exact output differs)
    --- baseline
    +++ current
    @@ -1 +1 @@
    -42
    +43
  UNCHANGED fact-1 (exact output matches)
  UNCHANGED logic-1 (exact output matches)
  UNCHANGED json-1 (all 2 field(s) match)
  ... (7 more unchanged: fact-2, json-2, explain-1, summarize-1,
       refusal-1, code-1, instruction-1)

Exit code 1 (drift alert). With --drift-threshold 50, the same run exits 0 — the probe lines and the index are unchanged, but the report is NOT identical: the alert line flips from DRIFT ALERT to no drift alert, and the exit code flips with it. The threshold moves the verdict, not just a label.

The standard probe set (modeldrift-standard)

modeldrift init writes it. Eleven probes, temperature 0, 3 samples each. The set is deliberately stable — do not edit these prompts casually, because the probe-set hash is the comparability anchor: numbers are only comparable across runs of the same set.

Probe Surface Match
math-1 arithmetic exact
fact-1, fact-2 factual recall exact
logic-1 multi-step reasoning (average speed) exact
json-1, json-2 format compliance (JSON fields) fields
explain-1 explanation similarity 0.90
summarize-1 summarization of a fixed passage similarity 0.85
refusal-1 safety drift: does the model still refuse? similarity 0.85
code-1 code generation similarity 0.85
instruction-1 instruction following contains

The refusal probe is a standard safety-eval prompt. Refusal wordings vary run to run, so the stability rule (below) keeps it honest: noisy refusals report UNSTABLE, a stable flip from refusal to compliance reports CHANGED — which is exactly the drift that matters.

The honesty contract (read this before trusting a verdict)

  • Drift vs noise: repeat samples + majority consensus. Providers are nondeterministic even at temperature 0, so a single differing sample proves nothing. Every probe runs 3 samples by default (per-probe samples in the probe file, 1–10, covered by the hash). The verdict uses the MAJORITY sample, not the first: exact/fields take the modal output / field-set, contains/not_contains take the majority presence value, similarity takes the medoid (highest mean similarity to the others). A strict majority that differs from baseline is CHANGED; a strict majority that matches is UNCHANGED with a dissent note (1 of 3 sample(s) dissented...); no majority (all differ, or a tie) is UNSTABLE — model noise, not drift — excluded from the index and reported loudly. A probe that cannot reproduce itself cannot prove drift. The baseline command refuses an unstable baseline outright. A probe with samples=1 gets a stderr warning (no noise defence) — warned, not refused, because quick custom probes are legitimate.
  • Coverage floor: no verdict from a minority of probes. If fewer than half the probes produce comparable pairs, check exits 2 (no verdict: low coverage) and writes NO index entry, regardless of what the partial index value says. A 6/11 check with drift still alerts normally; a 1/11 check never passes green on one surviving probe.
  • Probe-set identity. The probe set is hashed (prompts, params, match rules, samples). A check against a baseline with a different hash is an ERROR, never a drift verdict. Changing the probe set starts a NEW baseline (baseline --force). The hash covers the format version + probes only, so renaming the set does not force a re-baseline.
  • Model + endpoint identity. The baseline records the model name and endpoint. A check for a different model or endpoint is an ERROR, not a comparison across models.
  • Errors are not drift. Endpoint failures (unreachable, HTTP errors, malformed responses, empty content) are reported as ERROR, excluded from the index, and listed loudly. If NO probe produced a comparable pair, the check exits 2 (no verdict) — never 0. Partial attempt failures (some samples errored, a stable consensus remains) are warned about, not hidden.
  • Partial errors don't hide drift. If some probes error but others show drift beyond threshold, the check still alerts (exit 1) with the errors listed. If some error and the rest are clean, it exits 0 with the errors listed.
  • No silent passes. A baseline is never written from a run where any probe fully failed or was unstable. report never fails the run — it re-renders a stored verdict — but it refuses a run file from a different probe set.
  • Two thresholds, don't confuse them. --drift-threshold (0–100, default 0) is the INDEX threshold: alert when the index exceeds it. Probe sensitivity lives in the probe file's similarity thresholds (0–1). The CLI validates the index threshold range (0–100) and refuses anything else.
  • Threshold comparison is strict and unrounded. The alert compares the FULL-PRECISION index to the threshold (the displayed number is rounded only): 1/11 = 9.0909… alerts against a 9.09 threshold, where the rounded 9.09 would not. Comparison is strict >, so a threshold of 100 NEVER alerts — the index maxes at 100. That is honest, not a bug: 100 means "alert on nothing".
  • Corrupt index files fail loud. A corrupt local index file is an error (exit 2 from index, and check refuses to overwrite it), never a silent reset to empty — silently resetting would destroy the weekly history and hide the corruption.
  • Index identity is (model, week, endpoint, probe set). The same model checked against two endpoints (or two probe sets) in one week is two entries, not one overwriting the other. The index listing prints each entry's short probe-set hash and endpoint, so you can see which entries are comparable.
  • System-fingerprint warnings. When the endpoint sends a system_fingerprint, it is stored (baseline + run files, alongside per-sample output lengths and usage) and check prints a WARNING — not an error, not drift — when it changes versus the baseline. A rotated fingerprint with stable outputs is still worth knowing; it never flips a verdict by itself.
  • Length-shift warnings. check compares each probe's median output length (in characters, over its samples) with the baseline's. When it more than doubles or falls below half, it prints WARNING length shift <probe>: <a> -> <b> chars (informational, not drift) to stderr, and --json lists it under length_warnings. A model that got wordier is worth knowing about, but verbosity is not drift: the warning never changes the verdict, the index, or the exit code.
  • Files are owner-only, baselines are backed up. Baseline, run, and index files are written with mode 0o600 (POSIX only; on Windows they inherit the folder's ACLs). A forced re-baseline first renames the old baseline to a .bak copy, so re-baselining never silently destroys the old record. A check that produces no verdict (no comparable probes) leaves the previous run file untouched.

Match types (no paid embedding API)

  • exact — normalized strings equal (whitespace-insensitive).
  • similarity — difflib ratio on normalized text vs a threshold (default 0.90); very long outputs fall back to token Jaccard.
  • contains — an expected substring is present in the output.
  • not_contains — a forbidden substring is absent from the output. Absolute rule, not comparative: the baseline command refuses a baseline that already contains the forbidden substring (misconfigured probe), so a CHANGED here is a real flip from clean to violating.
  • fields — named JSON fields compared (exact or similarity per field); missing fields and non-JSON output count as CHANGED, not as errors.

The COMPARISON function is deterministic: same baseline output, same run samples, same verdict, every time. The end-to-end CHECK is not deterministic, and must not be sold as such — it samples a nondeterministic provider, so reruns can legitimately differ (samples, majority, UNSTABLE verdicts). Determinism lives in the comparison; the check measures a moving target honestly. Temperature defaults to 0 in the standard probe set; params and samples live in the probe file and are covered by the hash — there is no CLI flag to override them, because an override would change what is measured without changing the hash.

contains/not_contains matching is case-insensitive (case-folded both sides), so a model answering Quasar… passes the quasar instruction probe. JSON fences (json … ) are stripped before fields comparison on baseline, current, and stability paths alike — a formatting habit is not drift. Similarity thresholds were NOT lowered in v0.3.0: lowering them would trade false greens for false reds.

Keys, privacy, $0

  • The tool is $0 and local-first. It talks only to the endpoint YOU point it at.
  • API keys come from an environment variable only (default OPENAI_API_KEY, override with --api-key-env). Keys are NEVER written to files, never stored in baselines, runs, or index files. Remote endpoints with no key set fail with a clear error. (That "never written" claim is scoped to KEYS: endpoint URLs ARE written to baselines, runs, and index files — but only in sanitized form, see below. Model outputs, fingerprints, usage, and output lengths are also stored; they are measurements, not credentials.)
  • Keyless use is allowed for loopback endpoints (Ollama, freellmapi, any local OpenAI-compatible server).
  • Endpoint URLs are sanitized before they are stored, printed, or used as identity: username/password, query string, and fragment are all stripped (https://user:pass@host/v1?api_key=x is reported as https://host/v1). The request itself still carries the query string — /chat/completions is inserted into the path BEFORE any query — but the sanitized form is what is stored, printed, and used as identity. Two URLs differing only in userinfo, query, or fragment are the same endpoint for identity purposes. (The raw URL you pass on the command line is used for the request only — it is never written to a baseline, run file, or index entry.)
  • No telemetry, no phone-home, no data collection. Baselines and runs live in your directory, nowhere else.

Scheduling (documented example, not a built service)

# Weekly drift check, every Monday 09:00 (cron):
0 9 * * 1 cd /path/to/project && modeldrift check --model gpt-x --endpoint https://api.example.com/v1 >> drift.log 2>&1

check and report also take --format markdown, which prints a GitHub-flavoured summary: the index, the counts, a table of CHANGED probes, and each diff in a fenced block (ERROR and UNSTABLE probes get their own tables). --json is the same as --format json.

examples/github-actions-weekly.yml is an example workflow that runs check every Monday and appends report --format markdown to the job summary, with the key taken from the OPENAI_API_KEY repository secret. It is an example to adapt, not something this repo runs: Install it from PyPI (pip install modeldrift) in the install step, or point it at your own copy of the source. When check gives no verdict (exit 2) it writes no run file, so the summary stays empty and the job fails.

Exit codes

Code Meaning
0 OK, or no drift alert (check/report/probe/baseline/index/calibrate)
1 Drift alert: index exceeds --drift-threshold (check only)
2 Usage error, endpoint error, identity mismatch, or no verdict possible

Live vs fixture honesty note

No live provider endpoint or API key exists in this sandbox, so no real provider was probed during development. What WAS tested live: the full HTTP client path (request bodies, params, auth headers, error handling) against real local OpenAI-compatible servers (stdlib http.server fixtures), including a full probe → baseline → check → report → index cycle with a simulated provider drift (42 → 43, index 9.09 over the 11-probe standard set, exit 1) and a rotating-output server proving the UNSTABLE path (same prompt, disagreeing samples → UNSTABLE, excluded from the index, exit 0). Provider scenarios (drift, noise, errors, unreachable endpoints) are fixture-driven and labeled as such in the tests.

What a real host needs for the full path: an OpenAI-compatible endpoint URL (--endpoint, e.g. Ollama at http://127.0.0.1:11434/v1 keyless, or a provider base URL with the key in OPENAI_API_KEY).

Toward the public index (the long game, not v0.3.0)

The future public index needs one thing from v1: comparable numbers. v0.3.0 puts it in place without building the service:

  • The standard probe set (modeldrift-standard) is the comparability anchor — same set, same hash, comparable numbers.
  • Index entries carry provenance (probe-set hash + endpoint), so a future aggregator can filter to same-set runs.
  • The aggregation contract: the future service will accept opt-in submissions of INDEX ENTRIES only — never raw outputs, never keys, never prompts beyond the public standard set.

Nothing in v0.3.0 sends anything anywhere. The hosted service, the submission protocol, and the data policy are a later build.

What v0.3.0 does NOT do

  • Hosted PUBLIC drift index / cross-customer probe data (see above — the bridge is built, the service is not).
  • Team-tier private monitoring and alerts (C$29/mo, later).
  • Dashboards, built schedulers, or alert integrations (email, Slack, webhooks) — the gate is a CLI exit code + report; wire it into your existing alerting.
  • Parallel probing (sequential by design, to avoid provider rate limits) or multi-model comparison in one run (one model per baseline, by design).
  • Native Gemini adapter. The client speaks OpenAI-compatible /chat/completions (OpenAI, Ollama, freellmapi, vLLM, LiteLLM, OpenRouter, most local servers) and, since the next release, the native Anthropic Messages API (see below). Gemini users: use an OpenAI-compatible gateway.

What's new in v0.3.0

  • Majority consensus + dissent-aware verdicts (the top fix): verdicts use the majority sample, not the first — partial / intermittent drift is no longer misclassified as noise, and dissent is noted on UNCHANGED and CHANGED lines alike.
  • Coverage floor: checks with < 50% comparable probes exit 2 with no index entry, instead of passing green on a minority.
  • Query/fragment sanitization + correct URL construction: ?api_key=… and #fragment never reach a stored, printed, or identity URL, and /chat/completions is inserted before any query on the request itself.
  • Baseline validation symmetry: contains and fields baselines are refused as misconfigured probes, like not_contains already was.
  • Corrupt index files fail loud (no silent reset), and index identity is (model, week, endpoint, probe-set hash) with hash + endpoint shown in index output.
  • Client robustness: non-UTF-8 bytes, whitespace-only content, and list-form content blocks are handled as endpoint errors (or joined text), never crashes or false empties.
  • Unrounded threshold comparison (1/11 alerts at 9.09) and documented threshold-100-never-alerts behavior.
  • samples=1 warnings, case-insensitive contains matching,
    length capture with fingerprint-change warnings, unknown-probe-
    key rejection, order-insensitive hashing with dead-threshold
    exclusion, baseline `.bak` backups, no-verdict run preservation,
    report identity checks, and 0o600 file modes.
    

Breaking change, stated plainly: v0.2.0 baselines are INVALID under v0.3.0. The standard set's probe-set hash changed from 20c3e612a27c… (v0.2.0) to 9d548916fb51… (v0.3.0), because hashing is now order-insensitive (probes sorted by id — the standard set was not in id order) and a fields threshold is omitted from the hash when no field rule is similarity (the standard JSON probes carry only exact fields, so their old default 0.90 threshold was dead weight in the hash). A check against a v0.2.0 baseline errors on the hash mismatch — that is the honesty contract working, not a bug. Re-baseline once (baseline --force); the old baseline is kept as a .bak copy. The tool is local-only and unreleased, so no user is affected.

What's new in v0.2.0

  • Repeat sampling + UNSTABLE verdict (the flagship fix): 3 samples per probe by default, consensus = first sample when stable, noise reported as UNSTABLE and excluded from the index. v0.1.0 alerted on any single differing sample — a cry-wolf machine against nondeterministic providers.
  • The 11-probe modeldrift-standard set replaces the 4-probe example (math, facts, reasoning, format, explanation, summarization, refusal, code, instruction).
  • not_contains match type, with baseline-violation refusal.
  • Endpoint sanitization (credentials stripped from stored, printed, and identity URLs).
  • Index provenance (probe-set hash + endpoint on every entry).
  • Threshold validation + clearer help (index 0–100 vs probe similarity 0–1).

Breaking change, stated plainly: v0.1.0 baselines are invalid under v0.2.0, because the probe-set hash now covers samples and the default set changed. Re-baseline (baseline --force) once. The tool is local-only and unreleased, so no user is affected.

Metadata

Release files for modeldrift 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modeldrift 0.4.0
File Size Uploaded Provenance Actions
modeldrift-0.4.0.tar.gz 67.1 kB Without provenance Details for modeldrift-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for modeldrift 0.4.0
File Interpreter ABI Platform Actions
modeldrift-0.4.0-py3-none-any.whl Python 3 none any Details for modeldrift-0.4.0-py3-none-any.whl

Total release size: 108.5 kB

Release files / modeldrift-0.4.0.tar.gz

Download URL modeldrift-0.4.0.tar.gz
Size 67.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d8958aeeb1c691d12d40931c7b69f4ed8ba7a42af7a529b3d5648f8d8303f0ec
BLAKE2b-256 checksum
How to use checksums
687ddb9684870e7afd994256de79ce8cedabf51debc06d21ec745f482dd907ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / modeldrift-0.4.0-py3-none-any.whl

Download URL modeldrift-0.4.0-py3-none-any.whl
Size 41.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30acf79ce6cf65d2b0278b4c664c42e2255b91841f8e6493abfb49b41d7d9d50
BLAKE2b-256 checksum
How to use checksums
0bc687a1c3bd517e4e22875f36fd41ca6eb0437fe3a9e952783a9c4c0a353d51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for modeldrift 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page