Calibrating decision models
Deep Knowledge: Use mcp__documentation__fetch_docs with technology:
decision-calibration and one of these topics:
calibration: ECE variants, debiased estimators, isotonic and vector scaling, bootstrap CIs, contextual calibration.
order-bias: position and label bias, flip-rate measurement, PriDe.
conformal: LAC, APS and RAPS, plus class-conditional coverage.
provider-logprobs: request examples for each provider.
eval-harness: a complete runnable harness that compares Jev with an LLM on your own corpus and writes the decision report.
A probability is useful only if "0.9" means right about nine times in ten on
your data. No vendor can promise that for you: calibration depends on your
inputs, your language and your label set, and it shifts with every model
version. This skill is the procedure; typed-decision-models has the evidence
about Jev in particular. The code below was run on simulated data with known
over-confidence before it was written here (Python 3.12, numpy 2.5, scipy 1.18,
scikit-learn 1.9.1).
1. The corpus comes first
It outlives every model you try against it, and it is the only thing that lets
you compare them.
- Draw from production traffic, not from what is easy to label. Same
language, same state shape, same class balance — and include the ambiguous
cases, which are the ones thresholds exist for.
- Size. About 50 labels per question can fit a one-parameter correction;
fewer than ~30 can make calibration worse (observed on Jev). Isotonic
regression needs on the order of 1,000 (scikit-learn warns against it when
the number of calibration samples is "too low (≪1000)"). Thresholds for rare, expensive classes need enough
examples of that class.
- Split into a calibration half and a test half; never report a metric on
the data a correction was fitted on.
- Label what a person on the team would do, not what the model said. A
corpus labelled by another model measures agreement, not correctness — the
exact flaw in the Jev launch benchmark.
- Record the model version alongside every stored probability, so a
re-tune can be triggered when it changes.
2. Measure
import numpy as np
def ece(confidence, correct, n_bins=10):
"""Expected calibration error with equal-mass bins (less biased than equal-width)."""
confidence = np.asarray(confidence, float)
correct = np.asarray(correct, float)
order = np.argsort(confidence)
total = len(confidence)
return sum(
len(b) / total * abs(correct[b].mean() - confidence[b].mean())
for b in np.array_split(order, n_bins)
if len(b)
)
def ece_noise_floor(confidence, n_bins=10, n_sims=2000, seed=0):
"""ECE a *perfectly calibrated* model would show on this many items with these
confidences. A measured ECE inside this band is indistinguishable from noise."""
rng = np.random.default_rng(seed)
confidence = np.asarray(confidence, float)
sims = [ece(confidence, rng.random(confidence.size) < confidence, n_bins) for _ in range(n_sims)]
return np.percentile(sims, [50, 95])
def brier(probs, labels):
"""Multiclass Brier score; probs is (n, k), labels are column indices."""
probs = np.asarray(probs, float)
return np.mean(np.sum((probs - onehot) ** 2, axis=1))
Report, per question:
- accuracy with a confidence interval. n = 77 gives roughly ±10 points;
- ECE next to its noise floor. The floor depends on n and on how spread
the confidences are: at n = 60 a perfectly calibrated model scores a median
≈ 0.06 when confidences cluster near 1, but ≈ 0.13 when they spread over
0.4–1 (simulated with
ece_noise_floor). A bare ECE is uninterpretable;
- Brier score, which punishes both miscalibration and poor discrimination;
- direction: is the error over-confident (most binned accuracy below binned
confidence) or compressed toward the middle?
What "confidence" means:
- Choice: use
p_max, or the probability of the chosen option.
- Noul: use
max(p, 1 − p), with correctness judged at your threshold.
Do not calibrate Jev's confidence field. It is a dispersion statistic
derived from the distribution ((p_max − 1/n)/(1 − 1/n) for Choice), not a
probability. Calibrate probabilities or noul.
3. Fit
Choice / Score: one temperature
from scipy.optimize import minimize_scalar
from scipy.special import softmax
# Jev rounds probabilities to 0.01 and returns exact zeros. log(0) is -inf, and a
# tiny floor (1e-6) turns every zero into a huge negative logit that inflates the
# fitted temperature. Half the rounding quantum is the honest floor.
FLOOR = 0.005
def to_matrix(answers, options):
"""[{'billing': 0.88, ...}, ...] -> (n, k) array in a fixed option order."""
return np.array([[a[o] for o in options] for a in answers], float)
def fit_temperature(probs, labels, floor=FLOOR):
logits = np.log(np.clip(probs, floor, 1.0))
labels = np.asarray(labels)
def nll(t):
p = softmax(logits / t, axis=1)
return -np.mean(np.log(p[np.arange(len(labels)), labels]))
return minimize_scalar(nll, bounds=(0.05, 20.0), method="bounded").x
def apply_temperature(probs, t, floor=FLOOR):
return softmax(np.log(np.clip(probs, floor, 1.0)) / t, axis=1)
T > 1 means the model was over-confident; T < 1 means it was under-confident.
The floor is not a detail:
- Simulation: true over-confidence T = 2.0, outputs rounded to 0.01 like
Jev's. A 0.005 floor recovered T = 1.84; a 1e-6 floor reported 3.02.
- Published study: the same artefact made an independent Jev audit publish
temperatures of 3.29 and 3.40. Its author corrected them on 2026-09-22 to
1.30 and 1.92.
Noul: Platt (two parameters)
from scipy.special import logit
from sklearn.linear_model import LogisticRegression
def fit_platt(p_yes, y, floor=FLOOR):
x = logit(np.clip(np.asarray(p_yes, float), floor, 1 - floor)).reshape(-1, 1)
return LogisticRegression(C=1e6).fit(x, y) # effectively unregularised: two parameters
def apply_platt(model, p_yes, floor=FLOOR):
x = logit(np.clip(np.asarray(p_yes, float), floor, 1 - floor)).reshape(-1, 1)
return model.predict_proba(x)[:, 1]
Platt's slope also corrects compression toward 0.5, which independent work
reports for Jev and which a pure shift cannot fix.
Your own scikit-learn classifier
scikit-learn ≥ 1.8 has method="temperature" alongside "sigmoid" and
"isotonic". cv="prefit" was deprecated in 1.6 and 1.9.1 rejects it with
InvalidParameterError; wrap an already-fitted model in FrozenEstimator:
from sklearn.calibration import CalibratedClassifierCV
from sklearn.frozen import FrozenEstimator
calibrated = CalibratedClassifierCV(FrozenEstimator(clf), method="temperature").fit(X_cal, y_cal)
What one fit buys
- Classic result: temperature scaling alone fixes most of the
miscalibration of modern networks (Guo et al., ICML 2017).
- On Jev: refitting a Platt intercept on 50 labels cut held-out ECE by
62% in-domain; the slope did not transfer to new domains.
- This skill's simulation: ECE went 0.145 → 0.035 on held-out data.
Fit one correction per question. Never share one across Noul, Choice and
Score, or across fields.
4. Remove option-order bias before trusting a Choice
Multiple-choice selectors favour positions:
- Zheng et al., Large Language Models Are Not Robust Multiple Choice
Selectors (ICLR 2024).
- Pezeshkpour & Hruschka (2023) measured gaps of 13–75% from reordering alone.
- TypeSafe documents that
jev-1.13 "leans toward the option that comes first".
Cyclic permutation averages over n orders instead of n!. With Jev, all the
orders go into one request: questions are independent and share one read of
the state, so the extra orders cost tokens, not a round trip.
def rotations(criteria, limit=None):
"""Cyclic rotations of a Choice's options (Zheng et al., ICLR 2024): n orders, not n!."""
items = list(criteria.items())
n = len(items)
count = n if limit is None else min(limit, n)
shifts = sorted({round(j * n / count) % n for j in range(count)}) # evenly spread, first order kept
return [dict(items[i:] + items[:i]) for i in shifts]
def order_checked_choice(client, state, instructions, criteria, limit=None):
"""Ask the same Choice under several option orders in ONE request and average.
Questions in a request are independent and share one read of the state, so
the extra orders cost only their question tokens, not another round trip.
"""
from typesafe_sdk import Choice
orders = rotations(criteria, limit)
questions = {f"order_{i}": Choice(instructions=instructions, criteria=c) for i, c in enumerate(orders)}
result = client.system_one(state, questions)
answers = [result.choices[key] for key in questions]
averaged = {o: sum(a.probabilities[o] for a in answers) / len(answers) for o in criteria}
winner = max(averaged, key=averaged.get)
stable = all(a.choice == winner for a in answers)
return winner, averaged, stable
- Cost: n orders cost ~n× the question tokens. All of them must fit in the
64k request budget.
- Many options: set
limit (e.g. 3–4 evenly spaced rotations).
- How to use it:
- Run it offline over the corpus first, to measure how often the answer
flips.
- Add it in production only for decisions whose
stable=False rate justifies
the tokens.
- Calibrate the averaged probabilities, not the single-order ones.
- Option names matter too. Renaming labels moved AUC from 0.81 to 0.58 on
hosted Jev (arXiv 2609.26758). Once a wording is tuned, freeze option names
like an API.
- Contextual calibration (Zhao et al., Calibrate Before Use, ICML 2021)
is the complementary fix for a label prior. Score a content-free input such
as "N/A", then divide out the bias it reveals.
5. Choose thresholds from cost, then check coverage
def risk_coverage(confidence, correct):
"""For each candidate bar: the share of items kept and the error rate among them."""
confidence = np.asarray(confidence, float)
correct = np.asarray(correct, bool)
rows = []
for bar in np.unique(confidence):
kept = confidence >= bar
rows.append((bar, kept.mean(), 1 - correct[kept].mean()))
return rows
def lowest_bar_for(target_error, confidence, correct, min_kept=30):
"""Lowest bar whose kept items err at most target_error, with at least min_kept items."""
for bar, coverage, error in risk_coverage(confidence, correct):
if error <= target_error and coverage * len(confidence) >= min_kept:
return bar, coverage, error
return None
- Ask for each direction's cost separately. For a Noul, the false-positive
and false-negative costs set where the bar sits. TypeSafe's own advice: raise
it when acting on a false yes is expensive, lower it when missing a true yes
is.
- Read coverage alongside error. A bar that hands 80% of traffic to an LLM
costs more than no decision model at all; the hand-off rate is the number
that shows it.
- Bars are ranges, not points. Jev's probabilities move by a few hundredths
between identical calls, so leave margin.
- For a guarantee rather than an estimate, use selective classification
with a risk bound (Geifman & El-Yaniv, NeurIPS 2017). It picks the bar so
that the target error holds with high probability.
- Re-tune whenever any of these change: model version, option wording,
option set, or traffic mix.
6. Conformal sets: "one of these, with 90% coverage"
When acting needs a guarantee and a single label is too strong, return a
set. Use split conformal with the LAC score (Kumar et al. 2023), on
calibrated probabilities:
def conformal_qhat(p_true_label, alpha):
"""p_true_label: calibrated probability each calibration item gave its *true* label."""
scores = np.sort(1.0 - np.asarray(p_true_label, float))
n = len(scores)
k = int(np.ceil((n + 1) * (1 - alpha)))
return 1.0 if k > n else scores[k - 1] # too few items: the set must be everything
def prediction_set(probabilities, qhat):
return [option for option, p in probabilities.items() if 1.0 - p <= qhat]
- What it guarantees: the true label is in the set at least 1 − α of the
time, provided traffic is exchangeable with the calibration data. In
simulation, α = 0.1 gave 91.7% coverage.
- How to act on it:
- singleton → act automatically;
- two or more options → ask the user or a human;
- empty → treat as out of distribution.
- Variants: APS (Romano et al. 2020) and RAPS (Angelopoulos et al., ICLR
- give adaptive or smaller sets.
- When the guarantee breaks: it does not survive a shift in traffic.
Re-calibrate when the input mix changes.
7. Which providers give you probabilities at all (2026-10-03)
| Provider |
Class probabilities |
Notes |
| TypeSafe Jev |
yes, native |
probabilities / noul, rounded to 0.01 |
| Anthropic (Claude) |
no |
Messages API has no logprobs; OpenAI-compat logprobs/top_logprobs are "Ignored", response field "Always empty". Structured outputs give a typed enum, not a distribution |
| OpenAI |
yes, restricted |
logprobs + top_logprobs 0–20. On GPT-6, with reasoning effort other than none these must be removed — no logprobs from a reasoning model that is reasoning |
| Google Gemini |
documented, not on 3.x |
responseLogprobs: true, logprobs 0–20; text/x.enum for enums. A Google staff member stated on the developer forum (2026-08-05) that "logprobs are no longer returned for 3.X models"; Vertex users report 2.5 losing them too. Test the exact model |
| vLLM |
yes |
logprobs (cap max_logprobs, default 20); structured choice output. Default logprobs_mode is raw_logprobs — before logit processors, so a constraint is not reflected |
| llama.cpp server |
yes |
n_probs; post_sampling_probs for after the sampling chain; grammar / json_schema constraints |
With logprobs, constrain the label to a single token. For a single-token
enum, a grammar's renormalisation is exactly the conditional class posterior.
For multi-token labels it is not.
Without logprobs (Claude), each option costs more than one call:
- Sample k times and use label frequency.
- Verbalized confidence. It is better calibrated than token probabilities
for RLHF models (Tian et al., EMNLP 2023), but over-confident (Xiong et al.,
ICLR 2024).
- A panel of prompts that vote.
Post-training makes this worse: GPT-4's MMLU ECE went from 0.007 pre-trained
to 0.074 after RLHF (GPT-4 Technical Report, Fig. 8). Calibrate whatever you
end up with.
Checklist before a threshold goes to production
1---2name: decision-model-calibration3description: |4 Turning a model's class probabilities into numbers you can set a threshold on:5 building the labelled corpus, measuring accuracy and calibration honestly (ECE6 with a noise floor, Brier, risk–coverage), fitting temperature/Platt, removing7 option-order bias, conformal prediction sets, and choosing per-action8 thresholds. Applies to Jev and any typed classifier with probabilities, and9 says which LLM providers expose logprobs at all.1011 USE WHEN: user asks whether a confidence/probability can be trusted, how to12 pick a threshold, about "calibration", "ECE", "reliability diagram",13 "temperature scaling", "Platt", "isotonic", "CalibratedClassifierCV",14 "conformal prediction", "abstain", "selective prediction", "risk coverage",15 "position bias", "option order", "logprobs", or wants to evaluate Jev or an16 LLM classifier against labels.1718 DO NOT USE FOR: training classifiers from scratch, or generic LLM evals of19 free-text output (no class probabilities to calibrate).20allowed-tools: Read, Grep, Glob, Write, Edit, Bash21metadata:22 source: https://skillmd.com/skills/claude-dev-suite/decision-model-calibration23---2425# Calibrating decision models2627> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology:28> `decision-calibration` and one of these topics:29> - `calibration`: ECE variants, debiased estimators, isotonic and vector scaling, bootstrap CIs, contextual calibration.30> - `order-bias`: position and label bias, flip-rate measurement, PriDe.31> - `conformal`: LAC, APS and RAPS, plus class-conditional coverage.32> - `provider-logprobs`: request examples for each provider.33> - `eval-harness`: a complete runnable harness that compares Jev with an LLM on your own corpus and writes the decision report.3435A probability is useful only if "0.9" means right about nine times in ten **on36your data**. No vendor can promise that for you: calibration depends on your37inputs, your language and your label set, and it shifts with every model38version. This skill is the procedure; `typed-decision-models` has the evidence39about Jev in particular. The code below was run on simulated data with known40over-confidence before it was written here (Python 3.12, numpy 2.5, scipy 1.18,41scikit-learn 1.9.1).4243## 1. The corpus comes first4445It outlives every model you try against it, and it is the only thing that lets46you compare them.4748- **Draw from production traffic**, not from what is easy to label. Same49 language, same state shape, same class balance — and include the ambiguous50 cases, which are the ones thresholds exist for.51- **Size.** About 50 labels per question can fit a one-parameter correction;52 **fewer than ~30 can make calibration worse** (observed on Jev). Isotonic53 regression needs on the order of 1,000 (scikit-learn warns against it when54 the number of calibration samples is "too low (≪1000)"). Thresholds for rare, expensive classes need enough55 examples *of that class*.56- **Split** into a calibration half and a test half; never report a metric on57 the data a correction was fitted on.58- **Label what a person on the team would do**, not what the model said. A59 corpus labelled by another model measures agreement, not correctness — the60 exact flaw in the Jev launch benchmark.61- **Record the model version** alongside every stored probability, so a62 re-tune can be triggered when it changes.6364## 2. Measure6566```python67import numpy as np686970def ece(confidence, correct, n_bins=10):71 """Expected calibration error with equal-mass bins (less biased than equal-width)."""72 confidence = np.asarray(confidence, float)73 correct = np.asarray(correct, float)74 order = np.argsort(confidence)75 total = len(confidence)76 return sum(77 len(b) / total * abs(correct[b].mean() - confidence[b].mean())78 for b in np.array_split(order, n_bins)79 if len(b)80 )818283def ece_noise_floor(confidence, n_bins=10, n_sims=2000, seed=0):84 """ECE a *perfectly calibrated* model would show on this many items with these85 confidences. A measured ECE inside this band is indistinguishable from noise."""86 rng = np.random.default_rng(seed)87 confidence = np.asarray(confidence, float)88 sims = [ece(confidence, rng.random(confidence.size) < confidence, n_bins) for _ in range(n_sims)]89 return np.percentile(sims, [50, 95])909192def brier(probs, labels):93 """Multiclass Brier score; probs is (n, k), labels are column indices."""94 probs = np.asarray(probs, float)95 onehot = np.eye(probs.shape[1])[labels]96 return np.mean(np.sum((probs - onehot) ** 2, axis=1))97```9899Report, per question:100- **accuracy with a confidence interval**. n = 77 gives roughly ±10 points;101- **ECE next to its noise floor**. The floor depends on n *and* on how spread102 the confidences are: at n = 60 a perfectly calibrated model scores a median103 ≈ 0.06 when confidences cluster near 1, but ≈ 0.13 when they spread over104 0.4–1 (simulated with `ece_noise_floor`). A bare ECE is uninterpretable;105- **Brier score**, which punishes both miscalibration and poor discrimination;106- **direction**: is the error over-confident (most binned accuracy below binned107 confidence) or compressed toward the middle?108109What "confidence" means:110- **Choice:** use `p_max`, or the probability of the chosen option.111- **Noul:** use `max(p, 1 − p)`, with correctness judged at your threshold.112113**Do not calibrate Jev's `confidence` field.** It is a dispersion statistic114derived from the distribution (`(p_max − 1/n)/(1 − 1/n)` for Choice), not a115probability. Calibrate `probabilities` or `noul`.116117## 3. Fit118119### Choice / Score: one temperature120121```python122from scipy.optimize import minimize_scalar123from scipy.special import softmax124125# Jev rounds probabilities to 0.01 and returns exact zeros. log(0) is -inf, and a126# tiny floor (1e-6) turns every zero into a huge negative logit that inflates the127# fitted temperature. Half the rounding quantum is the honest floor.128FLOOR = 0.005129130131def to_matrix(answers, options):132 """[{'billing': 0.88, ...}, ...] -> (n, k) array in a fixed option order."""133 return np.array([[a[o] for o in options] for a in answers], float)134135136def fit_temperature(probs, labels, floor=FLOOR):137 logits = np.log(np.clip(probs, floor, 1.0))138 labels = np.asarray(labels)139140 def nll(t):141 p = softmax(logits / t, axis=1)142 return -np.mean(np.log(p[np.arange(len(labels)), labels]))143144 return minimize_scalar(nll, bounds=(0.05, 20.0), method="bounded").x145146147def apply_temperature(probs, t, floor=FLOOR):148 return softmax(np.log(np.clip(probs, floor, 1.0)) / t, axis=1)149```150151T > 1 means the model was over-confident; T < 1 means it was under-confident.152The floor is not a detail:153- **Simulation:** true over-confidence T = 2.0, outputs rounded to 0.01 like154 Jev's. A 0.005 floor recovered T = 1.84; a 1e-6 floor reported **3.02**.155- **Published study:** the same artefact made an independent Jev audit publish156 temperatures of 3.29 and 3.40. Its author corrected them on 2026-09-22 to157 1.30 and 1.92.158159### Noul: Platt (two parameters)160161```python162from scipy.special import logit163from sklearn.linear_model import LogisticRegression164165166def fit_platt(p_yes, y, floor=FLOOR):167 x = logit(np.clip(np.asarray(p_yes, float), floor, 1 - floor)).reshape(-1, 1)168 return LogisticRegression(C=1e6).fit(x, y) # effectively unregularised: two parameters169170171def apply_platt(model, p_yes, floor=FLOOR):172 x = logit(np.clip(np.asarray(p_yes, float), floor, 1 - floor)).reshape(-1, 1)173 return model.predict_proba(x)[:, 1]174```175176Platt's slope also corrects **compression toward 0.5**, which independent work177reports for Jev and which a pure shift cannot fix.178179### Your own scikit-learn classifier180181scikit-learn ≥ 1.8 has `method="temperature"` alongside `"sigmoid"` and182`"isotonic"`. `cv="prefit"` was deprecated in 1.6 and 1.9.1 rejects it with183`InvalidParameterError`; wrap an already-fitted model in `FrozenEstimator`:184185```python186from sklearn.calibration import CalibratedClassifierCV187from sklearn.frozen import FrozenEstimator188189calibrated = CalibratedClassifierCV(FrozenEstimator(clf), method="temperature").fit(X_cal, y_cal)190```191192### What one fit buys193194- **Classic result:** temperature scaling alone fixes most of the195 miscalibration of modern networks (Guo et al., ICML 2017).196- **On Jev:** refitting a Platt intercept on 50 labels cut held-out ECE by197 62% in-domain; the slope did not transfer to new domains.198- **This skill's simulation:** ECE went 0.145 → 0.035 on held-out data.199200Fit **one correction per question**. Never share one across Noul, Choice and201Score, or across fields.202203## 4. Remove option-order bias before trusting a Choice204205Multiple-choice selectors favour positions:206- Zheng et al., *Large Language Models Are Not Robust Multiple Choice207 Selectors* (ICLR 2024).208- Pezeshkpour & Hruschka (2023) measured gaps of 13–75% from reordering alone.209- TypeSafe documents that `jev-1.13` "leans toward the option that comes first".210211**Cyclic permutation** averages over n orders instead of n!. With Jev, all the212orders go into **one request**: questions are independent and share one read of213the state, so the extra orders cost tokens, not a round trip.214215```python216def rotations(criteria, limit=None):217 """Cyclic rotations of a Choice's options (Zheng et al., ICLR 2024): n orders, not n!."""218 items = list(criteria.items())219 n = len(items)220 count = n if limit is None else min(limit, n)221 shifts = sorted({round(j * n / count) % n for j in range(count)}) # evenly spread, first order kept222 return [dict(items[i:] + items[:i]) for i in shifts]223224225def order_checked_choice(client, state, instructions, criteria, limit=None):226 """Ask the same Choice under several option orders in ONE request and average.227228 Questions in a request are independent and share one read of the state, so229 the extra orders cost only their question tokens, not another round trip.230 """231 from typesafe_sdk import Choice232233 orders = rotations(criteria, limit)234 questions = {f"order_{i}": Choice(instructions=instructions, criteria=c) for i, c in enumerate(orders)}235 result = client.system_one(state, questions)236 answers = [result.choices[key] for key in questions]237 averaged = {o: sum(a.probabilities[o] for a in answers) / len(answers) for o in criteria}238 winner = max(averaged, key=averaged.get)239 stable = all(a.choice == winner for a in answers)240 return winner, averaged, stable241```242243- **Cost:** n orders cost ~n× the question tokens. All of them must fit in the244 64k request budget.245- **Many options:** set `limit` (e.g. 3–4 evenly spaced rotations).246- **How to use it:**247 - Run it **offline over the corpus** first, to measure how often the answer248 flips.249 - Add it in production only for decisions whose `stable=False` rate justifies250 the tokens.251 - Calibrate the *averaged* probabilities, not the single-order ones.252- **Option names matter too.** Renaming labels moved AUC from 0.81 to 0.58 on253 hosted Jev (arXiv 2609.26758). Once a wording is tuned, freeze option names254 like an API.255- **Contextual calibration** (Zhao et al., *Calibrate Before Use*, ICML 2021)256 is the complementary fix for a label prior. Score a content-free input such257 as "N/A", then divide out the bias it reveals.258259## 5. Choose thresholds from cost, then check coverage260261```python262def risk_coverage(confidence, correct):263 """For each candidate bar: the share of items kept and the error rate among them."""264 confidence = np.asarray(confidence, float)265 correct = np.asarray(correct, bool)266 rows = []267 for bar in np.unique(confidence):268 kept = confidence >= bar269 rows.append((bar, kept.mean(), 1 - correct[kept].mean()))270 return rows271272273def lowest_bar_for(target_error, confidence, correct, min_kept=30):274 """Lowest bar whose kept items err at most target_error, with at least min_kept items."""275 for bar, coverage, error in risk_coverage(confidence, correct):276 if error <= target_error and coverage * len(confidence) >= min_kept:277 return bar, coverage, error278 return None279```280281- **Ask for each direction's cost separately.** For a Noul, the false-positive282 and false-negative costs set where the bar sits. TypeSafe's own advice: raise283 it when acting on a false yes is expensive, lower it when missing a true yes284 is.285- **Read coverage alongside error.** A bar that hands 80% of traffic to an LLM286 costs more than no decision model at all; the hand-off rate is the number287 that shows it.288- **Bars are ranges, not points.** Jev's probabilities move by a few hundredths289 between identical calls, so leave margin.290- **For a guarantee rather than an estimate**, use selective classification291 with a risk bound (Geifman & El-Yaniv, NeurIPS 2017). It picks the bar so292 that the target error holds with high probability.293- **Re-tune whenever any of these change:** model version, option wording,294 option set, or traffic mix.295296## 6. Conformal sets: "one of these, with 90% coverage"297298When acting needs a guarantee and a single label is too strong, return a299**set**. Use split conformal with the LAC score (Kumar et al. 2023), on300calibrated probabilities:301302```python303def conformal_qhat(p_true_label, alpha):304 """p_true_label: calibrated probability each calibration item gave its *true* label."""305 scores = np.sort(1.0 - np.asarray(p_true_label, float))306 n = len(scores)307 k = int(np.ceil((n + 1) * (1 - alpha)))308 return 1.0 if k > n else scores[k - 1] # too few items: the set must be everything309310311def prediction_set(probabilities, qhat):312 return [option for option, p in probabilities.items() if 1.0 - p <= qhat]313```314315- **What it guarantees:** the true label is in the set at least 1 − α of the316 time, provided traffic is exchangeable with the calibration data. In317 simulation, α = 0.1 gave 91.7% coverage.318- **How to act on it:**319 - singleton → act automatically;320 - two or more options → ask the user or a human;321 - empty → treat as out of distribution.322- **Variants:** APS (Romano et al. 2020) and RAPS (Angelopoulos et al., ICLR323 2021) give adaptive or smaller sets.324- **When the guarantee breaks:** it does not survive a shift in traffic.325 Re-calibrate when the input mix changes.326327## 7. Which providers give you probabilities at all (2026-10-03)328329| Provider | Class probabilities | Notes |330|---|---|---|331| **TypeSafe Jev** | yes, native | `probabilities` / `noul`, rounded to 0.01 |332| **Anthropic (Claude)** | **no** | Messages API has no logprobs; OpenAI-compat `logprobs`/`top_logprobs` are "Ignored", response field "Always empty". Structured outputs give a typed enum, not a distribution |333| **OpenAI** | yes, restricted | `logprobs` + `top_logprobs` 0–20. On GPT-6, with reasoning effort other than `none` these must be removed — no logprobs from a reasoning model that is reasoning |334| **Google Gemini** | documented, **not on 3.x** | `responseLogprobs: true`, `logprobs` 0–20; `text/x.enum` for enums. A Google staff member stated on the developer forum (2026-08-05) that "logprobs are no longer returned for 3.X models"; Vertex users report 2.5 losing them too. Test the exact model |335| **vLLM** | yes | `logprobs` (cap `max_logprobs`, default 20); structured `choice` output. Default `logprobs_mode` is `raw_logprobs` — **before** logit processors, so a constraint is not reflected |336| **llama.cpp server** | yes | `n_probs`; `post_sampling_probs` for after the sampling chain; `grammar` / `json_schema` constraints |337338With logprobs, constrain the label to a **single token**. For a single-token339enum, a grammar's renormalisation is exactly the conditional class posterior.340For multi-token labels it is not.341342**Without logprobs (Claude), each option costs more than one call:**343- **Sample k times** and use label frequency.344- **Verbalized confidence.** It is better calibrated than token probabilities345 for RLHF models (Tian et al., EMNLP 2023), but over-confident (Xiong et al.,346 ICLR 2024).347- **A panel of prompts that vote.**348349Post-training makes this worse: GPT-4's MMLU ECE went from 0.007 pre-trained350to 0.074 after RLHF (GPT-4 Technical Report, Fig. 8). Calibrate whatever you351end up with.352353## Checklist before a threshold goes to production354355- [ ] Labelled corpus from production traffic, in the production language, split cal/test356- [ ] Accuracy with CI, ECE with noise floor, Brier — per question, on the test half357- [ ] Option-order flip rate measured; averaging adopted where it matters358- [ ] One temperature (Choice/Score) or Platt (Noul) fit per question, floor = half the rounding quantum359- [ ] Threshold chosen from asymmetric costs; coverage / hand-off rate recorded360- [ ] Model version pinned and logged; re-tune trigger defined361- [ ] Destructive actions still gated by approval, not by a probability alone