Lesson 63.1 · 1 of 4 · 5 min read · Reviewed 24 Nov 2026
Confidence scoring
By the end, you can
- Use confidence signals to route uncertain outputs.
- Calibrate thresholds with real data.
Not every output deserves the same trust. Route the uncertain ones to extra checks or a person.
Signals you can use
| Signal | How |
|---|---|
| Self-reported confidence | Ask for "confidence": "high" / "medium" / "low" with a reason |
| Evidence | Require a quote from the source; no quote, low confidence |
| Validation | Schema and business-rule checks (14.4) |
| Agreement | Run twice, or with two prompts; disagreement means low confidence |
Calibrate
Models’ confidence isn’t automatically accurate. Take a labelled sample and check: of the items marked “high”, how many were right? Set thresholds from that, per field if needed, and re-check as prompts and models change.
Route
- High confidence and passing checks: automatic.
- Medium: spot-check a sample.
- Low, or failed checks: human review queue.
Key points
- Ask for a confidence level or evidence with each output, and route low-confidence items to review.
- Self-reported confidence is a rough signal; calibrate it against labelled data.
- Better signals: agreement between runs, validation checks and whether evidence was found.
Set a confidence threshold from labels
Choose an auto-approve threshold from labelled data instead of trusting self-reported confidence.
You will have: A precision table by threshold and the chosen threshold, with the share of items it auto-approves.
Steps
- Run the starter to load 400 seeded, labelled items.
- Write precision_above() to return the precision and count above a threshold.
- Scan thresholds from 0.50 to 0.95 and pick the lowest that reaches 95% precision on at least 20 items.
- Print how many items that threshold sends to automatic handling and how many to review.
Done when
- The table shows precision rising with the threshold.
- A threshold is chosen and the auto-approve share is printed.
- Re-running gives the same answer, because the data is seeded.
Open in the Playground No API key needed.
Starter code (Python)
import random
# 400 labelled extractions: (self-reported confidence 0..1, was it actually correct?)
rnd = random.Random(7)
SAMPLE = []
for _ in range(400):
c = round(rnd.random(), 2)
p_right = min(1.0, 0.35 + 0.7 * c) # higher confidence is right more often, but not always
SAMPLE.append((c, rnd.random() < p_right))
def precision_above(threshold):
# TODO: of the items with confidence >= threshold, what share were correct? Also return how many there were.
return 0.0, 0
TARGET = 0.95
# TODO: try thresholds 0.50, 0.55, ... 0.95 and pick the lowest one whose precision meets TARGET
best = None
print("chosen threshold:", best)
Show a solution
import random
# 400 labelled extractions: (self-reported confidence 0..1, was it actually correct?)
rnd = random.Random(7)
SAMPLE = []
for _ in range(400):
c = round(rnd.random(), 2)
p_right = min(1.0, 0.35 + 0.7 * c) # higher confidence is right more often, but not always
SAMPLE.append((c, rnd.random() < p_right))
def precision_above(threshold):
items = [ok for c, ok in SAMPLE if c >= threshold]
if not items:
return 0.0, 0
return sum(items) / len(items), len(items)
TARGET = 0.95
best = None
for t in [x / 100 for x in range(50, 100, 5)]:
p, n = precision_above(t)
print(f"threshold {t:.2f}: precision {p:.1%} on {n} items")
if best is None and p >= TARGET and n >= 20:
best = t
print("chosen threshold:", best)
p, n = precision_above(best)
print(f"auto-approve {n} of {len(SAMPLE)} items ({n / len(SAMPLE):.0%}); the rest go to review")