Pre-deploy regression tests for LLM prompts, with scoring you can verify.
diffscore.space · Python 3.12 · FastAPI · Next.js 15
Status: pre-alpha. Phases 0–5 are built: the landing page, a CLI that
runs a suite with cached model calls, a diff with a p-value that gates CI,
an LLM judge with calibration tooling, and an HTTP API, queue worker and web
screens. Not deployed yet, and the judge's kappa is not published: it needs a
hand-labelled gold set first. See the roadmap.
The problem
You ship an LLM feature. You tweak the system prompt, swap a model, change the
chunk size — and you verify it by eyeballing three examples in a playground. You
have no idea what broke everywhere else.
Diffscore answers one question: did my prompt change make this better or worse?
The workflow
- Define a suite — inputs plus what good looks like, as a CSV upload or a YAML file.
- Run it against a prompt version and a model.
- Read the diff against the previous run — which cases improved, which regressed, and why.
If you can do those three steps in under five minutes with your own API key, the
product works.
Not in v1: no prompt playground, no production request tracing, no
fine-tuning, no team accounts.
Quick start
Python 3.12 or newer, and an API key for any model provider (Gemini has a free tier).
pip install diffscore
diffscore init # writes evals/example.yaml, its prompt, and a .env
# put your key in .env, e.g. GEMINI_API_KEY=...
diffscore run evals/example.yaml # the first run becomes the baseline
Now edit evals/prompts/example.md the way you'd really change a prompt, and run
it again. Diffscore re-asks only what changed (everything else comes from its
cache) and tells you whether the change made things better, worse, or made no
real difference:
diffscore run evals/example.yaml
diffscore show <run-id> --failed --outputs # what failed, with the model's answers
diffscore runs # history
No database to set up: results and the response cache live in
.diffscore/diffscore.db beside your project. Add .diffscore/ and .env to
your .gitignore. --rpm 14 (or MODEL_RPM=14) keeps under Gemini's free-tier
limit of 15 requests a minute, and --model swaps the model.
Providers. Built in, with nothing extra to install: gemini/…, openai/…
(or bare gpt-…), anthropic/… (or bare claude-…), groq/…, openrouter/…
(which reaches most other models) and ollama/… for local models. Set the
matching key in .env, e.g. OPENAI_API_KEY. For the 100+ other providers
LiteLLM supports, install
pip install "diffscore[litellm]". Costs come from LiteLLM's public price
list, fetched once a week into .diffscore/.
The install is small on purpose (about 7 MB): no numpy, scipy or LiteLLM by
default. The statistics (McNemar, bootstrap, Cohen's kappa) are plain Python,
tested against statsmodels and scikit-learn.
A suite is a YAML file: a prompt, a model, and cases with graders.
diffscore validate <file> checks one without running it. Graders:
equals, contains, not_contains, regex, json_schema, max_latency_ms,
max_cost, and judge (an LLM with a rubric; see below).
How it's put together
Grading is a separate stage from generation, so fixing a rubric costs no model calls.
Web UI ──► API (FastAPI) ──► Workers (Redis/RQ) ◄──► Model providers
│ │ (built-in client)
│ ▼
│ Graders — deterministic, then LLM judge
│ │
▼ ▼
Postgres ◄── Aggregator — diff vs baseline, p-value
Four decisions carry the design:
- One job per case, not per run. A 500-case suite that dies at case 400
resumes from 400 — and you get a real progress bar.
- Generation and grading are separate rows. Model calls are expensive,
grader calls are cheap, so stored outputs can be re-graded with a new rubric
for free.
- Cache keyed on content hash —
hash(prompt + input + model + params).
Reruns cost nothing.
- Graders are plugins. A uniform
score / verdict / reason interface means
adding one is a single file.
The interesting work is the judge layer: measuring the judge against your own
labels (Cohen's kappa against a gold set), controlling for position, verbosity,
self-preference and version-leak bias, and never calling a two-case difference a
regression without a p-value.
Stack
| Layer |
Pick |
| API |
FastAPI + Pydantic v2, Python 3.12 |
| Database |
PostgreSQL 16 (JSONB), SQLAlchemy 2.0 + Alembic |
| Queue |
Redis + RQ |
| Model calls |
Built-in HTTPS client (6 providers); LiteLLM optional for the rest |
| Statistics |
Plain Python, cross-checked against statsmodels and scikit-learn in tests |
| Web |
Next.js 15 App Router, TypeScript, Tailwind + shadcn/ui, TanStack Query |
| Local dev |
Docker Compose — api, worker, postgres, redis |
| Hosting |
Vercel (web) + Fly.io or a Hetzner VPS (api, worker) |
Deliberately absent: Kafka, Kubernetes, GraphQL, a microservice split, a
separate vector database.
Roadmap
~71 hours across seven phases, each with a gate to pass.
| Phase |
|
Hours |
| 0 |
The face |
8 |
| 1 |
Foundations |
3 |
| 2 |
Core loop |
15 |
| 3 |
The verdict |
12 |
| 4 |
Judge and calibration ✦ |
14 |
| 5 |
Make it visible |
11 |
| 6 |
Ship it |
8 |
Phase 4 is the one that matters.
Docs
Using it
Did my change make it better or worse?
The first completed run of a suite becomes its baseline. Every later
diffscore run is diffed against it, and the verdict comes first:
regression on 7 cases (p = 0.02)
run #7 (baseline) -> run #10 | prompt changed | support
7 regressed, 0 improved, 43 unchanged | McNemar exact, alpha 0.05
mean score change -0.047 (95% CI -0.080 to -0.020)
That is a real run: the shipping section was deleted from the example prompt.
A tweak that fixes one case and breaks another reports
no significant change (p = 1.00) instead — two flipped cases are noise, not
a regression. The p-value is McNemar's test on the paired pass/fail flips
(exact below 25 flips); the interval is a paired bootstrap of the mean score.
uv run diffscore diff 10 # run 10 vs its suite's baseline
uv run diffscore diff 7 10 --all # any two runs, including unchanged cases
uv run diffscore baseline 10 # promote a run to baseline
uv run diffscore run suite.yaml --baseline previous # diff vs the last run instead
diffscore run and diffscore diff exit 1 only on a statistically
significant regression, so they can gate a pull request.
Grading what string checks can't: the judge
For faithfulness, helpfulness or tone, add an LLM judge with a rubric. It
grades each answer against every criterion and must quote the answer as
evidence. It sees the customer's input, the answer and your reference
material, never the prompt under test or which model wrote the answer.
graders:
- judge:
context_file: reference/policy.md # ground truth the judge may consult
rubric:
- name: accurate
description: Every fact agrees with the reference policy.
- name: tone
description: Polite and calm; acknowledges an upset customer.
The judge runs on JUDGE_MODEL (default gemini/gemini-3.1-flash-lite, which fits
Gemini's free tier; a stronger judge is better) and refuses
to grade answers from its own model. A judge that can't produce a verdict
marks the case as an error, not a failure, so it never shows up as a regression.
Can I trust the judge?
Not until you've measured it. Label some outputs yourself, then compare:
uv run diffscore label 15 # pass/fail in the terminal; the judge's verdict stays hidden
uv run diffscore calibrate examples/support.yaml
uv run diffscore calibrate examples/support.yaml --disagreements # which answers you and the judge disagree on
judge (version 1-<rubric hash>, judged by <judge model>)
kappa <κ> trustworthy | below 0.6: rewrite the rubric (raw agreement <%>)
bias checks
verbosity r = <r> (score vs length, flag > 0.3)
self-preference judge <model> vs outputs from <models>
position <k>/<n> pairwise verdicts survive swapping the order
variance <k>/<n> verdicts flipped across 3 repeats
evidence <k>/<n> quotes found verbatim in the output
Cohen's kappa below 0.6 means the judge is close to guessing: rewrite the rubric and calibrate
again. Calibration re-judges your labelled outputs with the rubric as the file
defines it now, so that loop never regenerates an answer. Labels belong to
outputs, not runs, so a label made once covers every later run that reuses
that answer. Around 50–100 labels make kappa stable.
The web app
Everything the CLI does is also an HTTP API, and the site has screens for it:
a runs list with live progress, a run page with every case, the judge's
evidence and its trust status, and a diff page that leads with the verdict.
docker compose --profile app up -d # + API on :8000 and the queue worker
cd web && npm install && npm run dev # http://localhost:3000/runs
A run started from the web is queued as one job per case, so a crashed
worker resumes where it stopped and the progress bar is real. Without the
API_KEY, visitors can read public projects, run a sample suite, or run their
own suite with their own provider key. That key is encrypted with
FERNET_KEY, used for that run only and wiped when it finishes. Visitor runs
are rate limited per IP, capped at MAX_CASES_ANONYMOUS cases and limited to
safe model params. Owner keys for a project are stored encrypted and never
returned. Everything key-shaped is scrubbed from logs and Sentry events.
API docs are served at http://localhost:8000/docs.
In CI
Run the suite on the base branch's prompt, then on the pull request's, and
diff the two. The job fails only when the regression is significant.
# .github/workflows/prompt-regression.yml
name: prompt regression
on:
pull_request:
paths: ["prompts/**", "evals/**"]
jobs:
diffscore:
runs-on: ubuntu-latest
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
MODEL_RPM: "14"
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- uses: actions/setup-python@v5
with: { python-version: "3.12" }
- run: pip install diffscore
- name: Baseline = the base branch's prompt
run: |
git worktree add /tmp/base "origin/${{ github.base_ref }}"
diffscore run /tmp/base/evals/support.yaml --no-diff --quiet
- name: Diff the pull request against it
run: diffscore run evals/support.yaml --baseline previous
The runner's SQLite file starts empty, so both runs make real model calls;
cache .diffscore/ between jobs with actions/cache to make repeats free.
Developing Diffscore
Needs uv and Docker.
uv sync --all-extras
uv run pytest && uv run ruff check . && uv run mypy
docker compose --profile app up -d # Postgres, Redis, the API and the worker
uv run alembic revision --autogenerate -m "..." # after changing a model
The CLI defaults to SQLite; set DATABASE_URL to use Postgres (pip install "diffscore[postgres]"). The API and worker need pip install "diffscore[server]".
Example suites live in examples/, and the website in
web/.
License
MIT. Use it, fork it, ship it in a closed product — no conditions
beyond keeping the copyright notice.
The name and the brand assets are not covered by that licence; see
TRADEMARK.md. Short version: use the mark to refer to this
project freely, give a fork its own name.