Metadata-Version: 2.4
Name: passgate
Version: 0.2.2
Summary: Statistical pass^N gate: require an eval candidate to clear a Wilson-bound bar on every round, not just on average
Author-email: "Calas Automations Inc." <office@calasautomations.com>
Maintainer-email: "Calas Automations Inc." <office@calasautomations.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/calasdan-sketch/passgate
Project-URL: Repository, https://github.com/calasdan-sketch/passgate
Project-URL: Issues, https://github.com/calasdan-sketch/passgate/issues
Project-URL: Changelog, https://github.com/calasdan-sketch/passgate/blob/main/CHANGELOG.md
Keywords: evals,llm,reliability,wilson,statistics,gate,regression,ci,pass-at-k,flaky-evals
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Testing
Classifier: Environment :: Console
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<!-- Image URLs are absolute on purpose: GitHub resolves relative paths, PyPI does not. -->
![passgate: Pass once is luck. Pass^N is a gate.](https://raw.githubusercontent.com/calasdan-sketch/passgate/main/docs/brand/passgate-banner.png)

**A statistical reliability gate for LLM evals: a candidate must clear a Wilson-bound pass bar on every evaluation round, not just on average.**

```bash
pip install passgate && passgate gate rounds.json --threshold 0.9 --min-rounds 3
```

Needs Python 3.9 or newer, nothing else (standard library only). `rounds.json` is one entry per eval round (example below).

A real run on three rounds. Exit code 1, so CI fails:

```
passgate: 1/3 round(s) clear Wilson-lower >= 0.900 (lower bound of the two-sided 95% Wilson interval, ~97.5% one-sided; min 3 rounds)
  FAIL baseline-eval-set: 93/100 = 0.930 (lower 0.863)
  FAIL adversarial-set: 95/100 = 0.950 (lower 0.888)
  PASS regression-set: 116/120 = 0.967 (lower 0.917)
verdict: FAIL
```

*Pasted from a real run in a temporary folder. 93/100 does not certify 0.9 at 95% confidence: you need more data or a lower bar.*

- **Every round has to clear the bar.** Each round's conservative pass rate (lower bound of the Wilson score interval) must reach your threshold. Averaging hides the weak round; this does not.
- **Plan and compare.** `passgate plan` says how many trials a round needs; `passgate compare` tests a candidate against a baseline (pooled z-test, Fisher's exact, or paired McNemar).
- **Fits CI.** Reads JSON, CSV or JUnit XML, `--json` for machines, `--markdown` appends to `$GITHUB_STEP_SUMMARY`.

[![CI](https://github.com/calasdan-sketch/passgate/actions/workflows/ci.yml/badge.svg)](https://github.com/calasdan-sketch/passgate/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/passgate)](https://pypi.org/project/passgate/)
![License](https://img.shields.io/badge/license-MIT-blue)
![Python](https://img.shields.io/badge/python-%3E%3D3.9-blue)

## Limits up front

- The bar is the lower bound of the two-sided 95% Wilson interval (about 97.5% one-sided): conservative, not exactly 95%.
- pass^N here means every round clears the bar. It is not tau-bench's pass^k (all k trials of one task succeed).
- `plan` is a planning estimate, not a power calculation: at the expected rate a round of that size still fails some of the time.
- `compare` exits 0 only when the improvement is significant at `--alpha`; "inconclusive" exits 1 like "not better".
- Exit codes: 0 passed, 1 the gate failed (or `compare` found no significant improvement), 2 the input could not be used (missing or malformed file, bad number, `--alpha` outside 0 to 1).

More detail in [Notes](#notes). Changes: [CHANGELOG.md](CHANGELOG.md).

Eval flakiness is the quiet killer: a prompt scores 91% once, ships, and regresses. `passgate` requires each round's conservative pass-rate estimate to clear your bar, so a candidate that needs 3 good rounds to ship must produce 3 good rounds.

## Install

```bash
pip install passgate
```

## The gate

```bash
passgate gate rounds.json --threshold 0.9 --min-rounds 3
```

`rounds.json` (or `.csv`) holds one entry per round:

```json
[
  { "label": "baseline-eval-set", "trials": 100, "passes": 93 },
  { "label": "adversarial-set",   "trials": 100, "passes": 95 },
  { "label": "regression-set",    "trials": 120, "passes": 116 }
]
```

A `.xml` file is read as JUnit XML (`pytest --junitxml`, most eval runners and CI):
each `<testsuite>` is one round, failures and errors are fails, skipped cases are not counted as trials.

```bash
pytest evals/ --junitxml=rounds.xml && passgate gate rounds.xml --threshold 0.9 --min-rounds 3
```

Output is a per-round scoreboard and a verdict; exit code `1` fails CI:

```
passgate: 1/3 round(s) clear Wilson-lower >= 0.900 (lower bound of the two-sided 95% Wilson interval, ~97.5% one-sided; min 3 rounds)
  FAIL baseline-eval-set: 93/100 = 0.930 (lower 0.863)
  FAIL adversarial-set: 95/100 = 0.950 (lower 0.888)
  PASS regression-set: 116/120 = 0.967 (lower 0.917)
verdict: FAIL
```

Note what the gate does: **93/100 does not certify ≥ 0.9** at 95% confidence with 100 trials — you need more data or a lower bar. That is the point: the bar scales with evidence, not vibes. Add `--json` for machines.

## How many trials do I need?

```bash
passgate plan --threshold 0.9 --expected-rate 0.95
```

```
passgate plan: 140 trials per round to clear Wilson-lower >= 0.900
assumptions:
  - each round scores exactly floor(expected_rate * n) passes (133/140); real rounds vary
  - planning estimate, not a power calculation: at that true rate a round of this size will still fail some of the time, so add margin
  - bar = lower bound of the two-sided 95% Wilson interval
```

`plan` returns the smallest round size that *could* clear the bar if the round scored exactly the rate you expect. It is not a power calculation. A flawless round (the default `--expected-rate 1.0`) needs 35 trials to clear 0.9. If the expected rate is at or below the threshold, no round size can clear it, and `plan` exits `2`.

## Candidate vs baseline

```bash
passgate compare --candidate 93/100 --candidate 95/100 \
                 --baseline  85/100 --baseline  88/100
```

Pooled two-proportion z-test with a one-sided p-value, plus Fisher's exact p (exact hypergeometric enumeration — right for small rounds where the normal approximation lies). Exit `0` only when the improvement is statistically significant at `--alpha` (default 0.05). The verdict uses the z-test; Fisher's p is reported alongside as a cross-check, not used for the verdict.

### Paired: the same cases run by both

When candidate and baseline ran the **same** eval cases, the pooled test above throws away the pairing. Use `--paired` with one JSON line per case:

```jsonl
{"id": "case-001", "candidate": true,  "baseline": false}
{"id": "case-002", "candidate": true,  "baseline": true}
```

```bash
passgate compare --paired cases.jsonl
```

This runs an exact McNemar test: b = cases only the candidate passed, c = cases only the baseline passed, and the one-sided p-value is P(X >= b) for X ~ Binomial(b + c, 1/2), computed from exact integer binomial sums. Cases both passed or both failed carry no information about which is better and are ignored. The output shows b, c and the discordant count. With no discordant cases the verdict is `inconclusive`. Duplicate ids, or `candidate`/`baseline` values that are not `true`/`false`, exit `2`.

## Markdown summary

`gate` and `compare` take `--markdown PATH` to append a markdown table and the verdict to a file. It appends rather than overwrites, so it works with GitHub's `$GITHUB_STEP_SUMMARY`:

```bash
passgate gate rounds.json --threshold 0.9 --markdown "$GITHUB_STEP_SUMMARY"
```

## Python API

```python
from passgate import Round, evaluate_rounds, compare

result = evaluate_rounds(
    [Round(trials=100, passes=93), Round(trials=100, passes=95)],
    threshold=0.9, confidence=0.95, min_rounds=2,
)
assert result.passed, str(result)

cmp = compare([Round(100, 93)], [Round(100, 85)])
print(cmp.verdict)  # candidate-better | baseline-better | inconclusive
```

## CI

```yaml
- run: pip install passgate
- run: python run_evals.py --out rounds.json   # your eval runner
- run: passgate gate rounds.json --threshold 0.9 --min-rounds 3
```

## Notes

- Wilson interval (not Wald): behaves correctly near 0% and 100%, where the naive interval explodes.
- The bar is the lower bound of the two-sided 95% Wilson interval (`--confidence 0.95`). That is equivalent to a ~97.5% one-sided bound: conservative, not exactly 95%.
- pass^N here means *every round* clears the bar. It is not tau-bench's pass^k (all k trials of the same task succeed).
- `gate` fails when rounds < `--min-rounds`, so "we only ran it once" cannot pass a 3-round gate.
- Pure stdlib — no scipy, no pandas.

## License

MIT — see `LICENSE`.
