English | 简体中文
Durable, versioned, calibrated AI decisions for Postgres. Declare a semantic decision once ("is this complaint about debt collection?"). pgdocket keeps the answer stored as data, versioned, calibrated against your own labels, and honest about its uncertainty, in any Postgres and with any decision model.
Status: Phase 1 in progress. Working:
pgdocket checkmeasures how trustworthy an AI decision is on your table; the ledger stores decisions in Postgres and keeps them current as rows change;pgdocket estimategives counts with confidence intervals;pgdocket comparetests a revised decision against the current one before switching. It works with any/v1/systemoneserver, and Laya, run on your own machine, has been measured against Jev. Not built yet: adapters for other APIs, such as OpenAI Decisions, and a published release. The repository also contains the design (REPORT.md, ADRs) and the Phase 0 benchmark (findings). Progress is tracked in issues and milestones.
pg-jev lets you filter rows in plain language, such as WHERE jev(tickets, 'the customer threatens to cancel'), using TypeSafe's Jev decision model. That's good for exploring. To rely on the answers in production, they need to be stable, comparable and trustworthy, and today they aren't:
- they disappear when the database session ends, so every session judges the whole table again;
- they change when someone adds a label option, or switches model or backend;
- they change when you simply ask again, or send the row alongside different rows;
- a score of
0.7doesn't mean 70 %, andcount(*)over AI labels has no error bar; - they don't run on managed hosts like Supabase, Neon or RDS.
Model calls now cost roughly $6–25 per million rows (depending on text length and rows per request), so the bottleneck is no longer cost. It's whether people can trust and audit the answers.
2,000 real consumer-complaint narratives, judged by jev-1.13.0 through pg-jev, for about $0.30 in API calls in total.
| Finding | Result |
|---|---|
| Scores are over-confident | 9-way choice ECE 0.089; yes/no ECE 0.24–0.38 |
| ~100 labels fix most of it | Calibration on 100 labels removes 45–85 % of the error |
| Asking again changes answers | 4.8 % of rows change top answer across 3 identical runs |
| Neighbours change answers | Re-batching the same rows changes ~16.5 % of answers (≈ 5× noise) |
| One row per request is better | Judging rows singly: +2.4 pp accuracy, +0.05 macro-F1, at 1.8× tokens |
| Adding an option moves answers | 2.5 % of answers move to a new catch-all option |
| Scores are coarse | Probabilities come on a 0.01 grid with exact zeros |
Write-up for a general audience: Same row, different answer. Details, methods and limits: docs/phase0/FINDINGS-jev-1.13.md.
pip install "git+https://github.com/ElyasEbrahim/pgdocket" # Python 3.10+; installed from GitHub
pgdocket --versionOr as a container: docker build -t pgdocket . from this repository. New here? The 5-minute quickstart runs Postgres, the worker and 60 synthetic support tickets with Docker, through to calibration and trying a change before switching it on. It costs well under $0.01 in API calls.
Point it at a table, the text to send, a question and some labels (an existing column, or a CSV you label by hand). It reports agreement, calibration, a threshold with a stated precision guarantee, consistency and cost. It's read-only, and no row text goes in the report.
pgdocket check --table public.tickets --key id --text subject,body \
--kind choice --question "Which team should handle this ticket?" \
--options billing,technical,security,sales --label-column team --yesOn two years of Kubernetes issues, routing to 10 teams (SIGs) agreed with the human labels 88.8 % of the time. 90 % of issues could be auto-routed with precision ≥ 90 % guaranteed at 95 % confidence, or 56 % at ≥ 95 % (write-up, report). Full usage: pgdocket/README.md.
- Stored decisions. Built. Answers live in an append-only ledger and a view you can join and index. New and changed rows are judged automatically, one row per request. 100,000 rows: one row reads in 0.14 ms; on a live stream, the median time from insert to answer was 0.7 s (details).
- Calibration on your labels. Built. About 100–200 human labels per decision turn raw scores into probabilities that mean what they say. The view shows the calibrated confidence and an
autoflag. - Honest numbers. Built. Thresholds come with stated guarantees ("precision ≥ 90 % at 95 % confidence"). Answers that fall short of the target are flagged one by one, and
--per-answergives each answer its own guarantee. For yes/no decisions, a recall target also lets rows be answered no automatically while keeping, say, 90 % of the real yeses (details). Labels drawn at random rarely give a rare yes a threshold. Labels drawn within the top band of the model's scores give it one, with the same guarantee (details).pgdocket plansays how many rows people must review for the whole column to be at most, say, 5 % wrong (details). Counts come with confidence intervals:pgdocket estimatecombines the model's answers with a random sample of labels (prediction-powered inference). On real Kubernetes issues its intervals held 98–100 % of the time and were 30–50 % narrower than labels alone (details). A model as accurate as Jev is there needs more labels for that: at 50–100 labels its common answers often fall back on the betting interval described next, up to 1.9 times wider. For a rare answer, below 10 labelled rows with or without it, the usual interval can't be trusted; a betting interval takes over, valid at any number of labels, in SQL as in the CLI. That floor counts labels, not the model's errors, so since #52 the usual interval also needs 5 labelled rows where the model's answer and the label disagree. With too few of those it had held in only 91 % of draws in one of 269 cells of other deciders' decisions; with the second floor, 95 %. By group, betting cut the labels an answer on 1.8 % of complaints needed by 40–72 % (details). Weighted shares and several models get the same below their floors. With labels drawn by weight, the usual interval had held as little as 63 % of the time there, and betting held 96–100 % (details).--by regiongives a share per group, each corrected with its own labels, and--targetsays how many more labels each group needs. On 2,000 CFPB complaints, labels drawn within groups brought every region to ± 5 points with 36–66 % fewer than labels drawn across the table (details).--weighthandles queries that count a row many times, by what they sum or how often a join uses the row. There the rows that matter are the heaviest, so labels are drawn in proportion to weight. The 2,000 complaints, judged once as distinct texts, stand for 21,980 complaints. Drawing by weight brought their shares to ± 2 points with 112–192 labels, 53–94 % fewer than texts drawn at random (details).--withcombines several models' answers with the labels (Multiple-PPI), and--label-costfinds the cheapest mix of labels and rows each model judges. For a share of 100 million rows, judging a random sample instead of every row cut the cost of ± 2 points by 68–93 % (details). With--by, each group gets its own cheapest mix. Bringing every region to ± 3 points cost 49–67 % less this way than with one design drawn across the table (details). With--weight, the second model judges a longer run of the labels' ranking by weight. On a million texts with the CFPB join's fan-out, that cut the cost of ± 2 points by 10–19 % for the common answer, and saved little for rare ones. Run live on the 2,000-text join itself, every interval held and Jev cost $0.01, but it saved no labels: the heaviest texts get labelled anyway (details). - Versions. Built. Changing the question, options or model creates a shadow version.
pgdocket comparejudges a sample under both versions and reports which answers changed beyond run-to-run noise. It also reports which version is more accurate. Only the rows where the versions disagree need labels for that. On Kubernetes routing, dropping the option descriptions saved 14 % of tokens and moved 3.3 % of answers beyond noise. Labelling the 13 disagreements showed the descriptions were worth keeping (v1 right 8 times, v2 twice). With all labels, they also let 95 % of issues be auto-routed at the guaranteed 90 % precision, instead of 90 %.promoterecalibrates the new version, so automation carries over (details). - Drift checks. Built.
pgdocket driftchecks the two assumptions behind every guarantee. The first is that recent rows still look like the earlier ones; this check is free, from the answers already stored. The second is that the model still answers labelled rows as it did; this check asks some of them again, rows it hasn't asked yet in the series. Alarms share one false-alarm budget across repeated runs, and both checks also keep evidence that never expires, so a change that lasts still shows after months of checks. Over 52 weekly checks, a 20-point shift arriving halfway was caught in 67.5–100 % of runs, against 3–32 % before. On stored Jev answers, false alarms stayed at 0.5–4.5 % over a series of checks, and real shifts of 13–17 % in CFPB and Kubernetes labels were caught. Removing the option descriptions was caught from the model's scores. Over 12 model checks, a 5-point accuracy drop arriving halfway was caught by the end in 81 % of runs, against 2 % before. Rows without labels, re-asked as well, keep the evidence on the model's scores growing once every labelled row has been asked. Asked twice, they also show answers and scores that changed in no one direction, which no other check sees. Shuffled batches were caught in every simulated series, against 2.4 % before. jev-1.14 in place of jev-1.13, run forward on two fresh asks, was caught in every simulated series, against under 1 % from the answers alone. On fresh runs without a change, the test held (details).pgdocket auditchecks the accepted answers themselves. People label a few auto-accepted rows per batch without seeing the AI's answer, and an anytime-valid test alarms once precision is demonstrably below target; it can be read after every batch without raising the false-alarm rate. On real streams it raised no false alarm, and a fall to 70 % was caught in 93 % of audits (details). - Rows that try to steer the model. Built. When outsiders write the rows, they can write text aimed at the model. On 300 Kubernetes issues, a counterfeit routing policy appended by the issue's author sent 98.7 % of them to the team the author chose, and
autoaccepted 93.3 %: steered answers come out fully confident.pgdocket check --steermeasures this on your own table.--untrustedtells the model to ignore instructions in the rows; that policy then steered 1.3 % of issues.calibrate --hardenlets a row beautoonly once it passes a check. No answer may change when any one paragraph is removed (erase-and-check). The paragraphs are also judged alone (keep-one): for choice decisions they must not favour another answer, and for a yes/no row answered "no", none of them may be answered "yes". Erasing caught nearly every steered rowautowould have accepted, including misleading claims the sentence can't stop; it missed one issue in 300.- Together, every attack in our first set got through on at most 0.3 % of issues, except misleading claims written more than once. Keep-one cut a claim written twice from 7.3 % to 3.7 %. Attacks written later against the check did worse: the claim in three wordings, two of them inside the issue's own paragraphs, got 20.0 % through. Together the defences sent 8.5 % of clean accepted rows to review, and kept 82 % of issues
autoinstead of 95 %. These numbers are on the paragraphs the worker cuts, which often glue a payload to the issue's own text. - They don't hold against an author who can try again. Allowed 10 versions of the same issue, an author who saw the model's answer got 19.7 % of issues through both defences. One who saw only whether the issue went where they wanted got 13.3 %. With all 19 attacks we wrote, 23.0 % got through. Where the people who write the rows gain from the answer, keep that answer under review or leave the decision to people (details).
- On a yes/no decision, measured on the worker's own pieces, keep-one cut the worst attack towards a "no" from 15.6 % of the attacked issues to 3.3 %. A "yes" is harder: a claim written twice was accepted on 95.5 %, and nothing stopped it without sending over 20 % of the clean "yes" rows to review. Where the row's author gains from a "yes",
calibrate --review yeskeeps every "yes" under review and the "no" band automatic: 66 % of issues stayedautothere, 98.5 % of them right (details).
- Runs anywhere. Built and tested on PostgreSQL 14–18 as a non-superuser. Plain SQL plus an external worker, no untrusted extension. Not yet tested on Supabase, Neon or RDS themselves.
- Any backend. Built. pgdocket speaks the
/v1/systemoneAPI, so it can use TypeSafe's Jev or a model you run yourself; TypeSafe's key goes only to TypeSafe. On the same labelled rows, Laya (open weights, run locally, no API cost) was right 38 % of the time on Kubernetes routing, where Jev was right 88.8 %. The guarantees held: pgdocket would have sent all of Laya's answers to review rather than promise a precision it doesn't have. Calibrated on 2,000 CFPB labels, Laya's probabilities were as reliable as Jev's. An issue's author steered Laya far less than Jev, mostly because Laya reads only the start of a long issue; written first, a counterfeit policy still steered 21 %, and--untrustednever reached the model (details).- 18 other deciders, with no model call. DecideSQL ships 1.0 million recorded decisions from 3 decision models, 12 LLMs and 3 small models, on vehicle complaints, movie reviews and product reviews. pgdocket was replayed on them with 200 labels per question, in 269 cells:
- The precision and recall thresholds missed in 0.1 % and 0.3 % of draws, and in no cell above 5 %.
- DecideSQL's own expected precision and recall estimate, used the same way, missed in 37 % and 36 % of draws. Its count intervals held in 23 %.
- pgdocket's count intervals held in 96.8 % of draws, but fell to 91 % in one cell. A second floor added in #52 lifts that cell to 95 % (see 3 above).
- The cost: with 200 random labels, pgdocket certified no threshold for questions answered yes on 13 % of rows or fewer, and it dismissed far fewer rows than a perfect threshold could (details).
- For those rare questions,
label --bandnow draws the labels within the top band of the model's scores (#53). 200 of them certified a threshold in 42 % of draws, accepting 60 % of what any threshold could, with misses at 0.1 % (details).
- 18 other deciders, with no model call. DecideSQL ships 1.0 million recorded decisions from 3 decision models, 12 LLMs and 3 small models, on vehicle complaints, movie reviews and product reviews. pgdocket was replayed on them with 200 labels per question, in 269 cells:
Architecture and SQL sketch: REPORT.md §4. Decisions so far: docs/adr/.
Requires Docker. Everything runs in containers.
make up # Postgres 16 + pg-jev v0.2.1, pg-jev's mock API, a simulated backend
make test # harness unit tests
make smoke # pg-jev's README queries against the mock
make fetch load # 2,000 CFPB complaint narratives (CC0 mirror) → Postgres
make bench # all experiments on the simulated backend → results/<run_id>/report.mdTo run against the real Jev API, copy .env.example to .env, add your TypeSafe key, then:
make bench BACKEND=jev ARGS=--yes # prints the estimated spend; refuses anything over $1More commands (determinism, learning curve, batch context): harness/README.md.
| Path | What |
|---|---|
| REPORT.md | Project report: pg-jev teardown, research survey, candidates, design, evaluation plan, risks |
| ROADMAP.md | Phased plan with exit criteria |
| CHANGELOG.md | What changed, by date |
| docs/adr/ | Architecture decision records |
| docs/phase0/ | Phase 0 findings, status, draft upstream issue |
| docs/notes/ | Public write-ups |
| docs/phase1/ | Phase 1 results: the ledger, counts with error bars, version comparison, Kubernetes triage |
| pgdocket/ | The product: pgdocket check, the ledger and worker, estimate, compare |
| examples/ | The 5-minute quickstart, and option files for the example checks |
pyproject.toml, Dockerfile |
Packaging: the pgdocket command and the worker image (releasing) |
| harness/ | Benchmark harness: jevbench CLI, simulated backend, tests |
| results/ | Benchmark reports from the runs cited in the findings |
docker-compose.yml, Makefile |
The benchmark stack and its commands |
Every source, grouped by the feature it shaped and with what each was used for, is in REFERENCES.md.
This is a single-maintainer project. Issues and questions are welcome; pull requests are not accepted for now. See CONTRIBUTING.md.
Apache-2.0. Copyright 2026 ElyasEbrahim.