Label-efficient calibration
Problem
A team needs to know how often its support assistant’s answers are correct, with an interval they can defend, and wants a calibrated gate that sends an answer without review only when the error rate among sent answers stays under 5%. Expert review costs a few dollars per item and they have 20,000 unreviewed conversations. A strong LLM judge can grade all 20,000 cheaply, but its grades are biased in ways nobody has measured.
Averaging the judge’s grades gives a precise-looking number with an unknown bias. Using only human labels is unbiased but needs thousands of them for a tight interval.
Primitives
calibration.judge_qualityandcalibration.estimate_rate_with_judge: local, network-free prediction-powered inference, to decide how many human labels are worth buying.calibration_profiles.label_with_judge: the hosted job that labels a pool with a judge and selects a uniformly random subset for humans, keeping the selection valid for prediction-powered inference.Gatewithguarantee="risk", calibrated on the human labels.- A risk monitor fed with a small trickle of human labels, with judge labels recorded alongside as assisted points.
Code
Estimate the rate locally
The script runs as-is on stand-in data; load_items is where your own
judge and human verdicts go.
import numpy as np
from cli_sdk.calibration import estimate_rate_with_judge, judge_quality
from cli_sdk.stats.evalues.anytime import normal_ppf
def load_items(seed: int = 0):
"""Stand-in data. Replace with your own: for every item, the judge's 0/1 verdict
("the assistant's answer was correct"), plus the human verdict on a random subset."""
rng = np.random.default_rng(seed)
n_items = 20_300
truth = rng.uniform(size=n_items) < 0.83 # unknown in real life
judge = np.where(rng.uniform(size=n_items) < 0.90, truth, ~truth) # judge agrees 90% of the time
return truth.astype(float), judge.astype(float)
truth, judge = load_items()
rng = np.random.default_rng(1)
human_idx = rng.choice(len(judge), size=300, replace=False) # uniformly random subset
pool_idx = np.setdiff1d(np.arange(len(judge)), human_idx)
human = truth[human_idx] # the 300 labels you pay for
judge_on_human = judge[human_idx] # the judge on the same 300 items
judge_on_pool = judge[pool_idx] # the judge on the other 20,000
quality = judge_quality(human, judge_on_human)
print(f"agreement {quality.agreement_with_humans:.3f} correlation {quality.correlation:.3f} "
f"label multiplier {quality.effective_label_multiplier:.2f}")
ppi = estimate_rate_with_judge(human, judge_on_human, judge_on_pool, alpha=0.05)
print(f"prediction-powered: {ppi.estimate:.3f} 95% CI [{ppi.ci_lower:.3f}, {ppi.ci_upper:.3f}] lambda {ppi.lam:.2f}")
se = human.std(ddof=1) / np.sqrt(len(human))
z = normal_ppf(0.975)
print(f"humans only: {human.mean():.3f} 95% CI [{human.mean() - z * se:.3f}, {human.mean() + z * se:.3f}]")
print(f"judge only (biased): {judge_on_pool.mean():.3f}")Output:
agreement 0.910 correlation 0.723 label multiplier 2.10
prediction-powered: 0.828 95% CI [0.799, 0.858] lambda 0.65
humans only: 0.837 95% CI [0.795, 0.879]
judge only (biased): 0.767Build the profile with the hosted job
label_with_judge needs a profile that is already bound to its query, so
create it and evaluate once (the answer is heuristic until there are
labels). Both models run through your provider connections.
import os
import time
import httpx
from cli_sdk import CalibrationExample, CLIClient, Gate, OpenAIBackend
PROFILE = "assistant-correctness-v1"
BACKEND = OpenAIBackend(model="gpt-4.1-mini-2025-04-14")
SEND = Gate(
instructions="Is the assistant's final answer in this conversation correct?",
calibration_profile=PROFILE,
guarantee="risk",
target=0.05,
)
API = os.environ.get("CLI_BASE_URL", "https://cci.gitdate.ink/api/v1").rstrip("/")
def wait_for_label_job(name, job_id):
# Poll GET .../label-with-judge/{job_id} until the human tasks are ready.
while True:
job = httpx.get(f"{API}/calibration-profiles/{name}/label-with-judge/{job_id}", timeout=30,
headers={"Authorization": f"Bearer {os.environ['CLI_API_KEY']}"}).json()
if job["status"] not in ("queued", "running"):
return job
time.sleep(30)
with CLIClient() as client:
client.calibration_profiles.create(name=PROFILE, backend=BACKEND, method="CRC", alpha=0.05)
client.evaluate(context=conversations[0], backend=BACKEND, queries={"send": SEND}) # binds the profile
job = client.calibration_profiles.label_with_judge(
PROFILE,
judge=OpenAIBackend(model="gpt-4.1-2025-04-14"),
unlabelled_examples=[{"context": conversation} for conversation in conversations], # 20,000
human_labelled_sample_size=300,
)
if job["status"] == "queued": # a pool this size runs as a background job
job = wait_for_label_job(PROFILE, job["job_id"])
print(job["status"], job["strategy"], job["seed"], job["ppi_valid"]) # awaiting_human_labels uniform ... True
send_to_reviewers(job["human_tasks"]) # 300 items: id, context, judge_label, judge_confidence
# After reviewers finish the selected items:
client.calibration_profiles.add_examples(
PROFILE,
examples=[
CalibrationExample(context=item_context, label=reviewer_verdict, source="human")
for item_context, reviewer_verdict in completed_reviews
],
)Keep watching on a trickle of labels
with CLIClient() as client:
client.calibration_profiles.monitors.create(
PROFILE,
type="risk",
target=0.07,
false_alarm_rate=0.05,
labelled_sample_rate=0.005,
use_judge_pseudo_labels=True,
)
# For 0.5% of conversations, a reviewer's verdict on the served gate decision:
send_outcomes(PROFILE, [{"request_id": request_id, "query_id": "send", "label": reviewer_says_correct}])send_outcomes is the httpx helper on
Drift monitoring.
Walkthrough
Diagnose before you pay. On the 300 items both humans and the judge
labelled, the judge agrees with humans 91% of the time, with correlation
0.72. effective_label_multiplier is : with a
large judge-labelled pool, each human label is worth about two human-only
labels. A judge with correlation 0.3 would be worth about 1.1, and buying
more human labels would be the better use of money.
The judge alone is wrong in a way you cannot see. The judge’s own average over the pool is 0.767, well below the true rate of about 0.83 in this stand-in data; nothing in the judge’s grades reveals that. The prediction-powered estimate uses the 300 human labels to measure and remove the judge’s bias (the rectifier term), then uses the 20,000 judge grades to shrink the variance. Its interval, , is about 30% narrower than the human-only interval from the same 300 labels: roughly what twice as many human labels alone would give.
The hosted job prepares the same design at profile scale.
label_with_judge labels all 20,000 conversations with the judge and
stores those labels on the profile as source: "judge" rows, which never
set the gate’s threshold. It selects the 300 items for human review
uniformly at random and returns the seed, so the selection can be
reproduced and stays valid for the prediction-powered estimate above
(ppi_valid: true). Its judge_quality diagnostic compares the judge
with human labels already on the profile, so on a new profile it is
null: the local diagnostic in the first step is the one to read before
you pay for labels. Upload the human verdicts with source="human"; the
finite-sample guarantee on the gate rests on those 300 examples, and
uploading them starts the gate’s calibration (as a background job, since
300 examples need more than 200 model calls).
Monitoring stays cheap, and honest. The risk monitor’s alarm rests
on the true labels you send: a reviewer’s verdict for 0.5% of
conversations is enough to keep watching, instead of a full labelling
pipeline. With use_judge_pseudo_labels=True, judge-labelled outcomes are
recorded next to them as assisted points, visible on the monitor’s
trajectory in the dashboard, but they never move the e-value, so a biased
judge cannot raise or suppress an alarm. The monitor’s target, 0.07, sits
a little above the gate’s 0.05 so that it reports drift rather than the
scatter of one calibration.
The human-labelled items must be a uniformly random subset of the same pool the judge labels. Hand-picking “interesting” items for review, or reviewing only the items the judge flagged, breaks the estimator’s unbiasedness. And a judge no more accurate than the model being evaluated cannot cut the required human labels by more than about half.
What the guarantee means
- The estimate. is a large-sample 95% confidence interval for the correct-answer rate over the population the 20,300 items were drawn from. It is valid whatever the judge’s quality — a worse judge gives a wider interval, not an invalid one — but it relies on a normal approximation, so it is not a finite-sample or anytime-valid interval.
lam(0.65 here) is the weight the estimator put on the judge. It is chosen from the data to minimize variance; 0 would ignore the judge entirely.- The gate’s cards carry the usual finite-sample guarantee: the expected rate of answers that are sent without review and wrong is at most 0.05, computed on the human-labelled examples, with the same exchangeability assumption: the calibration pool, the human subset, and production traffic must all come from the same distribution. Estimates that use the judge pool (PPI) are large-sample, not finite-sample.