Skip to content

feat: add promptlens compare for run-to-run regression detection - #47

Open
brainsparker wants to merge 1 commit into
mainfrom
feature/2026-08-18-run-compare
Open

feat: add promptlens compare for run-to-run regression detection#47
brainsparker wants to merge 1 commit into
mainfrom
feature/2026-08-18-run-compare

Conversation

@brainsparker

Copy link
Copy Markdown
Owner

What this adds

promptlens compare BASELINE CANDIDATE: a run-to-run comparison command with regression detection, answering the question that matters after any prompt tweak or model swap: is this better or worse than what we had?

# Compare a known-good baseline against the most recent run
promptlens compare 20260810_120000 latest

# Gate CI on it
promptlens compare baseline-run pr-run --fail-on-regression

# Write reports for PR comments or CI artifacts
promptlens compare baseline-run pr-run --output comparison.md --json-output comparison.json

How it works:

  • Runs are referenced by run ID (from promptlens list-runs), run directory, or a direct results.json path. latest resolves via the existing symlink.
  • Test cases are paired by (test case ID, model), so comparisons survive reordered, added, and removed cases. Added and removed cases are reported but never counted as regressions.
  • A paired case is regressed when its judge score drops beyond --score-threshold (default 0, any decrease) or when it newly errors. Error transitions dominate scores: ok to error is always a regression, error to ok is always an improvement. --score-threshold 1 ignores one-point judge jitter on the 1-5 scale.
  • Terminal output is a rich summary table plus a list of regressed cases. --output writes a Markdown report suitable for PR comments; --json-output writes the full typed comparison.
  • --fail-on-regression exits non-zero when any paired case regressed, mirroring the --fail-under gate shipped in feat: add JUnit XML exporter and --fail-under CI quality gate #43. Without the flag the comparison is informational.

Why this, why now

Runner-up candidates considered today: GitHub Copilot export target for you.md, and a drift-check command for you.md. Both remain good future options; this one had the strongest demand evidence and the cleanest single-PR fit.

Implementation notes

  • New module promptlens/comparison.py: pydantic models (CaseComparison, ModelSummary, ComparisonResult), pairing/classification logic, and a Markdown renderer. No new dependencies.
  • New compare command in promptlens/cli.py with _resolve_run_reference accepting run IDs, run directories, or results.json paths.
  • Status classification: regressed, improved, unchanged, unscored, added, removed. Regressions sort first in reports.
  • Per-model aggregates reuse the existing RunResult.get_average_score / get_total_cost helpers.
  • README: feature bullet, CLI reference entry, and a "Comparing Runs and Catching Regressions" section in CI/CD Integration with a baseline-artifact recipe.

Test status

  • 25 new tests in tests/test_comparison.py covering classification (score drops, thresholds, error transitions, unscored cases), pairing (reordering, added/removed cases, multi-model), aggregates, Markdown rendering, and the CLI (run-ID and path resolution, exit codes, report writing).
  • Full suite: 83 passed locally on Python 3.9.
  • Verified end to end against fabricated baseline/candidate run directories: correct terminal output, Markdown and JSON reports, exit code 1 with --fail-on-regression, exit code 0 without.

Adds a compare command that diffs two evaluation runs, pairs test
cases by (test case ID, model), classifies each pair as regressed,
improved, unchanged, unscored, added, or removed, and can gate CI
with --fail-on-regression. Includes Markdown and JSON report output,
a rich terminal summary, 25 new tests, and README documentation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant