DriftScope
DriftScope is a local-first Python library for detecting semantic drift in LLM outputs. It wraps your model calls, stores prompts and responses in SQLite, embeds outputs locally, calibrates a baseline from your own traffic, and reports when later outputs move outside the learned normal range.
No hosted dashboard. No external data pipeline. No cloud account required.
Install
pip install llm-driftscope
For sentence-transformer embeddings:
pip install "llm-driftscope[embeddings]"
Quick Start
from driftscope import monitor
@monitor(session="support-bot")
def call_llm(prompt: str) -> str:
return my_llm_client.chat(prompt)
answer = call_llm("How do I reset my password?")
By default, events are stored at .driftscope/driftscope.sqlite3.
Generate a local report:
driftscope report --session support-bot
Try the included drift simulation:
python examples/simulate_drift.py
Sample output:
DriftScope report
Session: demo
Samples: 9
Status: drift
Latest score: 1.0015
Latest distance: 1.0202
Threshold: 0.2229
Topic: warming up; topic drift needs two windows
Changepoint: warming up; changepoint detection needs more samples
Drift events: 3
Why DriftScope Exists
Infrastructure metrics can tell you that a service is healthy. They cannot tell you that an LLM has quietly started answering in a different semantic region than it used to. Hosted observability platforms can help, but many developers need a small embeddable library that works inside an existing codebase and keeps data local.
DriftScope focuses on that gap.
Methodology
Fixed distance thresholds are brittle. A customer support bot should usually be consistent. A creative writing assistant naturally has wider semantic variation. DriftScope avoids hardcoded assumptions by calibrating against each application's own warmup data.
During warmup, DriftScope stores output embeddings and estimates the empirical distribution of distances from the baseline centroid. Once enough samples exist, it sets the alert threshold from a high percentile of that null distribution. New outputs are compared against the centroid, smoothed with EWMA, and flagged when the smoothed drift score crosses the calibrated threshold.
The v1 detector reports:
- raw semantic distance from the baseline
- EWMA-smoothed drift score
- calibrated threshold
- drift status
- warmup progress
- topic distribution drift
- changepoint detection over semantic distance
API
from driftscope import DriftConfig, DriftScope
config = DriftConfig(
warmup_samples=50,
threshold_percentile=99,
ewma_alpha=0.3,
)
scope = DriftScope(session="my-app", config=config)
result = scope.record(prompt="hello", output="world")
if result.drifted:
print(result.score, result.threshold)
Decorator form:
from driftscope import monitor
@monitor(session="my-app")
def generate(prompt: str) -> str:
return "model output"
CLI
driftscope report
driftscope report --session my-app
driftscope report --db .driftscope/driftscope.sqlite3
driftscope report --json
driftscope sessions
driftscope export --format csv --out events.csv
Optional sidecar API:
pip install "llm-driftscope[server]"
driftscope serve
The sidecar exposes GET /health, POST /events, and GET /report.
Optional Extras
pip install "llm-driftscope[topics]"
pip install "llm-driftscope[changepoints]"
pip install "llm-driftscope[server]"
pip install "llm-driftscope[full]"
Development
pip install -e ".[dev]"
python -m pytest
python -m build
Metadata
Release files for llm-driftscope 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 | |
|---|---|---|---|---|
| llm_driftscope-0.1.0.tar.gz | 15.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_driftscope-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.6 kB
Release files / llm_driftscope-0.1.0.tar.gz
| Download URL | llm_driftscope-0.1.0.tar.gz |
|---|---|
| Size | 15.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5a1395e885a7c6c370ab784a5f11c38d63ced6c7c2106b3b780c65c5111bba8
|
|
BLAKE2b-256 checksum How to use checksums |
09d27231e7a373cdfea4f84ddb1a279c3c9769fc0fd2acde46d9affd6441c260
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|
Release files / llm_driftscope-0.1.0-py3-none-any.whl
| Download URL | llm_driftscope-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd7190a298175670798589137db9d512eabdc0483a981ac9a79c9458ea45b6f8
|
|
BLAKE2b-256 checksum How to use checksums |
74e054f7f71a4ae3b93b2ec9eb85c5577610c8cc93537ae1a5a1cb8da61bf3b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|
Security for llm-driftscope 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.
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.