gateledger
Pass/fail and cost receipts for multi-stage LLM pipelines. No server, just JSONL files. It records both the model you asked for and the model that answered, and a judge model that has not been checked against human labels never gets to stop the pipeline.
The image above comes from examples/diagnose.py run against a fake LLM, so its numbers are illustrative.
The numbers below were measured once on the held-out test set of the example app (maint-agent, an equipment-maintenance QA agent; 192 questions, 95% bootstrap CI). The questions were checked by a panel of two LLMs, not by people, and 10 of the original 202 that the panel flagged were not run:
| Fabricated quotes (before the check) | Unsupported claims (judge estimate) | Wrong answers to unanswerable questions | Cost per question | Share of cost spent on retries |
|---|---|---|---|---|
| 1.9% [0.9, 3.0] (all 18 affected answers recovered by one repair) | 69.0% [64.3, 73.4] (target 5%, missed) | 16.3% [6.1, 26.5] (target 10%, missed) | $0.174 [0.160, 0.188] at Bedrock list prices | 5.7% [3.2, 8.4] |
| Judge agreement (150 labels, dev set) | Cohen's κ [95% CI, resampling questions] |
|---|---|
| Judge vs. one other model that labelled without seeing the judge's verdicts (Fable 5.2, not human) | 0.37 [0.22, 0.53] |
| Judge vs. the earlier two-model panel (one of its two labellers was the judge's own model) | 0.85 [0.75, 0.93] |
| Judge vs. human | not measured |
The judge has no power to block: its labels are not human, and against the other model's labels κ is below the 0.6 bar. The first panel had cleared both numeric thresholds; the rule that model-made labels never grant blocking power is what kept the judge advisory. The 69.0% is therefore the rate under the judge's reading of the rubric. On the 150 dev-set claims the judge failed 68% and the other model 34%, and without human labels it is not known which reading is right. Either way the 5% target was missed. Evaluation report · Demo: 30 recorded runs replayed, no live LLM calls
pip install gateledger
Minimal example
Runs as is: the replies come from a fake LLM, so no API key is needed. Pass AnthropicProvider() as llm for real calls.
import json
from gateledger import FakeProvider, FakeReply, Gate, Ledger, Pipeline, PriceTable, Usage
from gateledger.report import render_text, summarize
SOURCE = "Probable cause: fuel filter clogged. Drain water and replace the element."
replies = [ # the 1st answer misquotes the source, the 2nd one fixes it
FakeReply('{"cause": "clogged fuel filter", "quote": "filter full of water"}', Usage(input=900, output=60)),
FakeReply('{"cause": "clogged fuel filter", "quote": "fuel filter clogged"}', Usage(input=1_000, output=60)),
]
llm = FakeProvider(replies)
pipe = Pipeline("diagnose", ledger=Ledger("runs"), prices=PriceTable.bundled("2026-11"), llm=llm)
@pipe.stage("answer", model="claude-opus-5-5") # a model missing from the price table fails here, not at run time
def answer(ctx, question):
fix = f"\nFix: {ctx.findings}" if ctx.findings else "" # findings of the failed gate, on the repair attempt
return json.loads(ctx.llm.complete([{"role": "user", "content": question + fix}]).text)
def quote_in_source(out, _input): # mechanical check: an empty list means pass
return [] if out["quote"] in SOURCE else [f"quote not in source: {out['quote']}"]
pipe.gate("answer", Gate("quote_exists", check=quote_in_source, on_fail="repair"))
result = pipe.run("Engine cranks but will not start. Why?")
print(result.output, f"${result.cost:.4f}")
print(render_text(summarize(pipe.ledger.read(result.run_id)))) # stage, gate and cost table
The run is written to runs/<run_id>.jsonl: two calls (initial, then repair), the failed and the passed gate, and the cost of each.
gateledger report --dir runs --svg report.svg --html report.html renders the latest run as above.
A longer example with a judge, a waived gate and a model mismatch is in examples/diagnose.py.
Rules
| Rule | What it means |
|---|---|
| No argument skips a gate | To go past a gate, call pipe.waive(stage, gate, reason). Every run then records waived with the reason |
| The failure mode is required | block (stop), repair (pass the findings back and retry once; anything left is recorded and the run goes on) or record (record only) |
| Unknown models are an error | A stage's model is checked against the price table when the stage is added. If the model that answered is not in the table, the call is recorded with an empty cost and then raises. It is never booked as $0 |
| Every call has a reason | initial / repair / rejudge, so cost per reason is a plain aggregation (fallback is reserved and not written yet) |
| Requested and served model | Cost uses the served model's price. A mismatch shows up in the report. LiteLLM and Inspect AI also record both sides of a fallback; what gateledger adds is that the served model decides whether a judge's verdict may block (see the next section) |
| Fingerprints | Stage input and output are stored as the SHA-256 of normalized JSON |
| Mechanical checks first | Within a stage, mechanical gates run before judge gates regardless of the order they were added, so nothing a free check already rejected is sent to a paid judge |
| Verdict reuse | The key is the fingerprint of what the judge was shown (view) plus the rubric version. The model is recorded but not part of the key, so switching judges reuses earlier verdicts at no cost. A reused verdict keeps the original run id and the amount it saved. If view returns None, nothing is judged (no cost, treated as pass) |
| Rubric versions | The version comes from the SHA-256 of the rubric file (supported@bf57b3922ae8). Editing the file changes the version, and earlier verdicts and calibrations stop applying. The version cannot be forgotten |
When a judge may stop the pipeline
Even on an on_fail="block" gate, a judge verdict stops the run only when all three conditions hold. Otherwise the verdict is recorded as advisory (with advisory_reason) and the run continues; the report shows why it did not stop (uncalibrated, below the bar, panel labels only, or a different model answered).
| Condition | Threshold | Why |
|---|---|---|
| Agreement with human labels | Cohen's κ ≥ 0.6 | The lower end of "substantial agreement" (0.61–0.80, Landis & Koch). Below that, the reason for stopping cannot be explained to a person |
| Number of labels | ≥ 100 | At 85% raw agreement and 50% chance agreement, the 95% interval of κ is about ±0.14 with 100 labels and about ±0.2 with 50, too wide to tell 0.6 from 0.4 |
| Served model | Same as requested | The calibrated judge is the one that was asked. A verdict from a model that stood in after a rate limit or outage does not inherit that authority, even if the stand-in has its own calibration |
- κ and the label count are tracked per (rubric version, served model), and each verdict records the values in force at the time.
- The thresholds cannot be lowered by an argument. They are
gateledger.MIN_KAPPAandMIN_LABELS. - On a block gate, if the only earlier verdict is advisory and the requested judge is calibrated, the item is judged again (reason
rejudge). - Limitation: with a single labeller, κ measures agreement with that one person. The bootstrap interval of κ is reported alongside the count. The interval resamples labels independently; when several labels come from the same question it is too narrow, so resample by question in your own code (the example app does).
- Label source: each calibration records where its labels came from,
humanormodel_panel(labels made by one or more other models, a silver standard). A calibration frommodel_panellabels alone does not give the judge the power to block, because agreement with people was never measured. PassPipeline(..., allow_panel_calibration=True)to accept it explicitly; the report then says the authority rests on model-panel labels.
Calibration matches a JSONL of labels against the verdicts in the ledger, one line per label: {"judged_fp": "sha256:…", "human": "pass"} for a human label, or {"judged_fp": "sha256:…", "label": "pass", "source": "model_panel"} for a model-panel label. It stops if any label has no matching verdict, or if one file mixes the two sources.
gateledger calibrate rubrics/supported.md labels.jsonl --model claude-sonnet-5-5 --dir runs
# prints n, raw agreement, κ with its 95% interval, the confusion matrix and whether the judge may block;
# appends the result to runs/calibration/calibrations.jsonl
Watching for degradation
gateledger watch compares the runs of a recent window with the period just before it and exits with 1 when it suspects degradation, so it can run from cron or CI.
gateledger watch --dir runs --window 1d --baseline 14d --pipeline diagnose
| Kind | Signals | How it decides |
|---|---|---|
| Changes (facts) | A served model not seen in the baseline (per stage, and per judge rubric). A stage, gate or rubric version present on one side only | Flagged as is, no test |
| Shifts | Cost per run (per stage and per judge rubric), judge fail rate and judged items per run (per rubric), fail rate of each mechanical gate, share of runs that did not end ok |
Two-sided permutation test with the run as the unit, Holm-adjusted so that the chance of any false alarm in one comparison stays at α (default 0.05). Each shift is printed with its n and a 95% bootstrap interval of the difference |
- The run is the unit because verdicts within one run are not independent; counting them one by one raises false alarms.
- Gates count the verdict of the last attempt. Waived gates and judge slots that judged nothing (
viewreturnedNone) are not counted. A signal that has the same value in every run is not tested, since no split of the runs can change it. - With few runs only large shifts can be told from noise: 3 runs against 3 cannot flag even a gate that went from always passing to always failing (there are only 20 ways to split them).
- From Python,
watch(baseline, current)takes two lists of runs (each the records fromLedger.read) and returns aWatchReport. - Tried once on the example app, 10 runs per side: it flagged 3 of 4 deliberately broken configurations (exact 95% interval 19–99%) and missed the one where a manual was removed from the index. One unchanged rerun raised no alarm, which says nothing about the false-alarm rate. Experiment notes (Japanese)
What it does not do
Where a good tool already exists, gateledger leaves the job to it.
| Need | Use | Why |
|---|---|---|
| Trace UI, dashboards | Langfuse, Phoenix (via OpenTelemetry, planned) | Good UIs already exist |
| Prompt versioning | git | Files are enough |
| Prompt and model sweeps, red teaming | promptfoo | Config-driven sweeps are a solved problem |
| RAG metric definitions | Ragas | Use names and definitions people already know |
| Output tests in pytest | DeepEval | CI tests already exist |
| Validating one call's output and re-asking | Structured outputs, Pydantic | The SDK does this |
| Routing and fallback across models and providers | LiteLLM | gateledger only records which model answered |
It is not an orchestrator either (no parallelism, resume or scheduling). Pipeline calls its stages in order and is meant to be called from inside whatever orchestrator you already use.
Record format
One JSONL file per run (runs/<run_id>.jsonl), one record per line. Record types are run_start, call, stage, gate and run_end. A judge call is a call with gate set, and a judge gate's gate record carries the verdict under judge.
{"type":"call","run_id":"20261127T091403512Z-7f3a","stage":"answer","attempt":2,"reason":"repair",
"model_requested":"claude-opus-5-5","model_served":"claude-opus-5-5",
"usage":{"input":2200,"output":1000,"cache_read":5000,"cache_write":0},"cost_usd":0.0298,"latency_ms":8120}
{"type":"gate","run_id":"20261127T091403512Z-7f3a","stage":"answer","gate":"supported","on_fail":"block",
"attempt":2,"artifact_fp":"sha256:41d0…","verdict":"fail",
"findings":[{"claim":"drain water and replace the element","reason":"the next check is not in the quote"}],
"judge":{"rubric":"supported@bf57b3922ae8","judged_fp":"sha256:7a2b…",
"model_requested":"claude-sonnet-5-5","model_served":"claude-sonnet-5-5","score":0.5,"cost_usd":0.0039,
"reused_from":null,"saved_usd":null,"calibration":null,"advisory_reason":"not calibrated (agreement with human labels not measured)"}}
Where the rules come from
The author has run a multi-stage LLM system that produces long-form content every day for about six months. Each rule answers something that went wrong there.
| What happened | What gateledger does |
|---|---|
| Checks were pasted into each pipeline's launch script; a copy missed one, and on the same day one of three pipelines ran without it | Checks live behind a single entry point, so they cannot be forgotten |
| "Optional" checks were eventually left switched off | No skip argument. Waivers are explicit, per gate, and always recorded |
| A defect visible from the input alone was found after an expensive, irreversible stage that took hours | A check goes where its inputs are available; input-only checks run before the expensive stage |
| A model missing from the price table was booked at $0, hiding its cost | Unknown models raise |
| The judge's provider hit its rate limit and judging failed in every pipeline | A judge reply that cannot be parsed raises; it is never retried on another model. Moving to another model when one is unavailable is left to the provider or a router, and a verdict from the stand-in is recorded under the model that answered and cannot block |
| A default model name was routed to the wrong provider and failed | The provider is chosen from the model name, and the served model is checked on the response and recorded |
| Re-judging everything whenever the judge changed made costs jump | Freshness depends on content and rubric version; the model is only recorded |
| The same prompts were re-sent on every rerun, but nothing said why, so the waste was invisible | Every call carries a reason |
| Per-stage model choices and cost-saving switches were compared by joining separate logs | Models are configured per stage, and quality and cost come out of the same ledger |
gateledger and its example app were built over two days (27–28 November 2026) with a coding agent (Claude Code) doing the implementation, the evaluation runs and the first drafts of the documents; every commit carries a Co-Authored-By trailer. The author set the direction, made the design calls and signed off on the work; no person checked the test questions or the labels used to calibrate the judge, as the tables at the top say. The rules in the table above come from the author's own production system.
Status (v0.1.0)
Included: stages, the JSONL ledger, price tables, mechanical gates (block / repair / record / waive), judges (Judge) with verdict reuse, calibration (gateledger calibrate), gateledger report (terminal table, SVG, HTML), gateledger watch (degradation checks), and LLM adapters (fake and the Anthropic SDK, pip install "gateledger[anthropic]").
Not yet: with ledger.stage(...) for using only the ledger and gates inside an existing orchestrator; separate records before and after a fallback (reason fallback; today the total uses the served model's price); a SQLite index (verdict reuse reads the JSONL ledger); the cost command; an OpenTelemetry exporter.
Reports and CLI output are in English. Exception messages raised by the library (for example, invalid labels or an unknown model) are still in Japanese.
Changes are listed in CHANGELOG.md. A Japanese version of this README is in README.ja.md.
Development
uv sync --extra dev
uv run pytest && uv run ruff check && uv run mypy # CI runs the same with the versions in uv.lock
python examples/diagnose.py # regenerates docs/report.svg and docs/report.html
License
MIT
Metadata
Release files for gateledger 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 |
|---|---|---|---|---|
| gateledger-0.1.0.tar.gz | 64.3 kB | With provenance | Details for gateledger-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gateledger-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for gateledger-0.1.0-py3-none-any.whl |
Total release size: 116.9 kB
Release files / gateledger-0.1.0.tar.gz
| Download URL | gateledger-0.1.0.tar.gz |
|---|---|
| Size | 64.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77d3b46576d91721bfbcf3b6e94e6c352601e1f0360c3d1c549a3d280934ed37
|
|
BLAKE2b-256 checksum How to use checksums |
e17c004ec5d6f7a0683849c0d65cee0cfdc58b677ea28db10e32e9f87447b895
|
| 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 28, 2026.
Transparency logRelease files / gateledger-0.1.0-py3-none-any.whl
| Download URL | gateledger-0.1.0-py3-none-any.whl |
|---|---|
| Size | 52.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
131944ded49dcbbd8035016619acebc4da678e6ce84c08ed7ee928db805d47b0
|
|
BLAKE2b-256 checksum How to use checksums |
3483c6bf6ede3d279280bf05fa7e3883ad28f2c0be427bfd7f5c6ac72a0ac580
|
| 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 28, 2026.
Transparency logSecurity for gateledger 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 gateledger-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 28, 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.