llm-drift-bench
llm-drift-bench is a Python CLI and library for comparing captured LLM outputs across model updates, prompt revisions, and quantizations. It measures lexical differences, JSON structure and field agreement, numeric changes, and recorded latency.
Why llm-drift-bench?
When upgrading model checkpoints or quantizing weights for production inference, subtle regressions frequently slip past perplexity benchmarks:
- Broken JSON Conformity: Markdown fence artifacts or missing required keys in structured outputs.
- Structural Key-Path Drift: Schema-valid payloads that drop optional nested fields or alter value types.
- Numeric Field Drift: Extracted financial or confidence numbers drifting beyond acceptable tolerances.
- Tail Latency Regressions: P95 latency spikes across specific prompt categories.
The runtime uses Pydantic and Rich, together with their transitive dependencies.
Similarity measures agreement with a baseline, not factual correctness or semantic equivalence. The validator implements a JSON Schema subset and rejects unsupported keywords before checking the response. It is not a complete JSON Schema implementation.
Quickstart after publication
pip install llm-drift-bench
llm-drift-bench init-sample --dir ./demo
llm-drift-bench run -b ./demo/baseline_fp16.jsonl -c ./demo/candidate_int4.jsonl -p ./demo/prompts.json
Visual Terminal Output
1. Drift Benchmark Comparison (llm-drift-bench run)
==============================================================================
LLM DRIFT BENCHMARK REPORT [PASSED]
==============================================================================
Baseline Model : llama-3-8b-fp16
Candidate Model : llama-3-8b-q4_k_m
Total Samples : 2 (Drifted: 0 / 0.0%)
------------------------------------------------------------------------------
Metric | Baseline | Candidate / Value
------------------------------------------------------------------------------
JSON Conformity Rate | 100.0% | 100.0%
Mean Composite Drift | 0.0000 (ref) | 0.0426
Max Composite Drift | 0.0000 (ref) | 0.0852
Mean Token Jaccard Similarity | 1.0000 (ref) | 0.9412
Mean Levenshtein Similarity | 1.0000 (ref) | 0.9930
Mean JSON Structural Similarity | 1.0000 (ref) | 1.0000
Mean JSON Numeric Relative Drift | 0.0000 (ref) | 0.0160
P50 Latency (ms) | 130.2 | 82.8
P95 Latency (ms) | 141.3 | 88.6
------------------------------------------------------------------------------
Prompt ID | Category | JSON OK | Struct Sim | Drift | State
------------------------------------------------------------------------------
extract_invoice_01 | extraction | YES | 1.0000 | 0.0000 | OK
classify_ticket_02 | classificati | YES | 1.0000 | 0.0852 | OK
==============================================================================
2. Standalone JSON Conformity Validation (llm-drift-bench validate)
llm-drift-bench validate -i ./demo/candidate_int4.jsonl -p ./demo/prompts.json --strict
========================================================================
JSON CONFORMITY VALIDATION [2/2 passed (100.0%)]
========================================================================
[PASS] extract_invoice_01 | Conformant
[PASS] classify_ticket_02 | Conformant
========================================================================
Input & Configuration Formats
Prompt Suite with JSON Schemas (prompts.json)
[
{
"prompt_id": "extract_invoice_01",
"category": "extraction",
"prompt": "Extract invoice fields as JSON.",
"schema": {
"type": "object",
"required": ["invoice_id", "total_usd", "status"],
"properties": {
"invoice_id": {"type": "string", "minLength": 3, "pattern": "^INV-"},
"total_usd": {"type": "number", "minimum": 0},
"status": {"type": "string", "enum": ["paid", "pending", "overdue"]}
},
"additionalProperties": false
}
}
]
Model Outputs (baseline_fp16.jsonl / candidate_int4.jsonl)
{"prompt_id": "extract_invoice_01", "model_name": "llama-3-8b-fp16", "latency_ms": 142.5, "output": "{\"invoice_id\": \"INV-2026-09\", \"total_usd\": 1250.00, \"status\": \"paid\"}"}
CLI Reference & CI Gating
Gate your CI/CD pipeline on model drift and JSON conformity thresholds using --fail-on-drift:
llm-drift-bench run \
--baseline ./baseline_fp16.jsonl \
--candidate ./candidate_int4.jsonl \
--prompts ./prompts.json \
--max-drift 0.15 \
--min-conformity 0.98 \
--max-numeric-drift 0.05 \
--max-latency-regression 25.0 \
--output ./artifacts/drift_report.json \
--fail-on-drift
| Flag | Default | Description |
|---|---|---|
-b, --baseline |
(Required) | Path to baseline model outputs (.json or .jsonl). |
-c, --candidate |
(Required) | Path to candidate model outputs (.json or .jsonl). |
-p, --prompts |
None |
Optional prompt definitions with per-prompt JSON Schemas. |
--max-drift |
0.25 |
Maximum allowed mean/per-sample composite drift score [0.0, 1.0]. |
--min-conformity |
0.95 |
Minimum required candidate JSON Schema conformity rate [0.0, 1.0]. |
--max-numeric-drift |
0.15 |
Maximum allowed relative numeric drift on shared JSON number fields. |
--max-latency-regression |
50.0 |
Maximum allowed P95 latency regression percentage (%). |
-o, --output |
None |
File path to save the structured JSON benchmark report. |
--format |
table |
Output format on stdout (table, rich, json, or markdown). |
--fail-on-drift |
False |
Exit with code 1 if any threshold is violated or sample drifts. |
Current behavior of the unreleased revision
Levenshtein similarity always compares characters (Unicode code points),
including whitespace and case. Each response is limited to 16,384 characters
for this metric. Longer responses raise an error (CLI exit code 2), rather
than being truncated or scored using a different unit. Unicode normalization
is not applied.
Commands are run, report, validate, and init-sample.
--suite and --prompts are aliases for the suite path.
Use existing captured-output files for both comparison targets.
Missing files, directory paths, and model identifiers are input errors
(CLI exit code 2). The tool does not call model endpoints or generate
responses. The library also accepts explicit sequences of ModelSample.
init-sample creates illustrative fixtures, not measured model outputs.
Baseline and candidate must contain exactly the same non-empty prompt IDs,
with no duplicates. An explicitly supplied suite must cover exactly those
IDs and cannot be empty. The validate --prompts command applies the same
suite-coverage rule. Matching errors return CLI exit code 2.
Comparison results are ordered by prompt ID, independently of input order.
For library callers, evaluate_suite([], baseline, candidate) still means
infer the prompts from the complete matching output sets; it never selects
only their intersection.
Table and JSON output use the benchmark engine. Rich and Markdown output currently recompute scores through a second evaluator with different weights. Until these paths are unified, their scores are not interchangeable.
Missing measurements appear as n/a in reports and null in JSON.
Throughput requires an explicit tokens_generated count and positive measured
latency_ms; text token estimates are not substituted. Zero latency remains
a recorded value, but cannot produce throughput or a baseline-relative
percentage regression.
Suite means and latency percentiles require complete measurements for that side of the comparison. If either side lacks timings, the latency regression check is skipped; a passing result does not certify latency performance. Other drift and conformity thresholds still apply.
Saved engine reports lose some information when converted by report.
Unavailable latency means and throughput remain n/a; percentiles are not
substituted for means or individual observations.
Python Library API
Use llm-drift-bench directly inside your evaluation pipelines or pytest suites:
from llm_drift_bench import (
DriftBenchmarkEngine,
DriftThresholds,
ModelSample,
PromptCase,
format_report_table,
)
prompts = [
PromptCase(
prompt_id="invoice_1",
prompt="Extract invoice total.",
schema={
"type": "object",
"required": ["total"],
"properties": {"total": {"type": "number", "minimum": 0}},
},
)
]
baseline = [ModelSample(prompt_id="invoice_1", model_name="fp16", output='{"total": 100.0}')]
candidate = [ModelSample(prompt_id="invoice_1", model_name="int4", output='{"total": 99.5}')]
engine = DriftBenchmarkEngine(thresholds=DriftThresholds(max_composite_drift=0.10))
report = engine.evaluate(baseline, candidate, prompts)
print(format_report_table(report))
assert report.passed
Contributing & License
Contributions are welcome! Please read CONTRIBUTING.md for development setup, testing instructions, and our good first issue roadmap.
Licensed under the MIT License.
Metadata
Release files for llm-drift-bench 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llm_drift_bench-0.1.0.tar.gz | 46.1 kB | With provenance | Details for llm_drift_bench-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_drift_bench-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for llm_drift_bench-0.1.0-py3-none-any.whl |
Total release size: 78.4 kB
Release files / llm_drift_bench-0.1.0.tar.gz
| Download URL | llm_drift_bench-0.1.0.tar.gz |
|---|---|
| Size | 46.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d81e608a1ef67a776170b00361bde80be58832c8d99e2b31df76681b8a26a9f
|
|
BLAKE2b-256 checksum How to use checksums |
06df9ca2ccc5d7cfb10569866e8d8a937abf3684ba393d786e2b19aa4008b9de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / llm_drift_bench-0.1.0-py3-none-any.whl
| Download URL | llm_drift_bench-0.1.0-py3-none-any.whl |
|---|---|
| Size | 32.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e242825c626cc84d3dc7ed4d3d7fe335cc0ff3844f6fd793dd09e9696dbc585e
|
|
BLAKE2b-256 checksum How to use checksums |
4a0496d593a821ffe36ecc65e64499b6b1e1811fde614abc67341215cac8c7ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for llm-drift-bench 0.1.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for llm_drift_bench-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA 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.