The main path's questions first, in lab order, with short answers and pointers to the code. A few questions on the
optional labs are at the end. Run stories and smaller details are in FAQ-more.md: read it only when a
lab sends you there.
Not on its own. It is the model's guess and clusters around 0.9 to 0.95.
We use it only to hold the clearly unsure ones (MIN_CONFIDENCE in ai/moderation.py).
To set a threshold, price each outcome (a held review, an honest one rejected, a bad one published) in evals/costs.py and pick the cheapest policy on a saved eval run. The business sets the prices, not the engineer.
When the model is down, slow or returns junk, the review is HELD for a human, never APPROVED.
Transient errors are retried with backoff by the job queue; when retries run out, hold_on_failure() holds the review.
A valid answer that makes no sense (REJECT without a reason, a quote that isn't in the review) is held at once: retrying at temperature 0 gives the same answer.
Every verdict call has an output cap, so a model that never stops writing ends in HELD too, not a stuck worker.
04_fail_closed.py shows each case, and how one except: approve line publishes abuse.
Looking at 8 outputs is a guess. A fix that helps those 8 can break 20 others you didn't look at.
With a score you get before/after numbers, e.g. "honest reviews rejected: 40% → 3%", that you can show anyone.
The same score becomes the gate for every later change: prompt, model, thinking on or off.
Why is "honest reviews rejected" the first number, not accuracy?¶
The two mistakes cost different things: an honest review rejected silences a buyer; a bad one published harms everyone who reads it.
A model that rejects everything publishes 0% bad reviews. Only the honest-rejected number shows it is useless.
Accuracy mixes both mistakes into one number and hides which one you are making.
Question it answers
Bad when
Precision for ABUSIVE
When we reject a review as abusive, how often is it really abusive?
Low: honest buyers are being called abusive
Recall for ABUSIVE
Of all the abusive reviews, how many did we catch?
Low: abuse is getting through or being held
How big should the golden set be, and what are the hard cases?¶
50 stratified reviews (3+ of every scenario) is a smoke test for every change: one review moves a number by 2 points. Confirm on all 500 before you switch the product to a new prompt.
20 hand-written hard cases (evals/hard_cases.jsonl) hold every failure you found, so it can't come back unnoticed. They include polite controls, so a prompt that approves everything fails.
Never put the hard-case texts in a prompt: that is tuning on the test (a test checks it).
What is an LLM judge, and how do I know it works?¶
A second model call that grades an output against a rubric: here, "is this claim backed by its evidence?" (ai/judge.py).
Use it only where no exact answer exists. Moderation has golden labels: count them. Summary sentences and RAG answers don't.
Calibrate it first (lab 13): code takes true claims and breaks one thing (a number, the sentiment, "every", the citation), so the right answers are known.
Report Cohen's kappa, agreement beyond chance (kappa() in evals/judge_eval.py). A judge that always says SUPPORTED gets 50% accuracy on half-true claims and kappa 0. Rough guide: under 0.4 don't use it, 0.6-0.8 for trends, 0.8+ to gate a release.
The same model judging its own output tends to rate it higher. Calibration measures how much; in production, use a different or bigger judge.
llm.py is the meter: it logs every call. The gateway (ai/gateway.py) is the policy: may this call happen (budget, rate limit), and what to do when it fails (retry, fallback model).
Limits are per feature, so one backlog can't use up another feature's budget.
Retry what can succeed next time (timeouts, 429, 5xx), with backoff. Don't retry a bad answer at temperature 0: it comes back the same.
Should we use LiteLLM instead of our own gateway?¶
For many teams and providers, yes: budgets, keys per team, fallbacks and a price list as config (lab 11 --litellm).
It sits in front of every prompt and key, so treat it as critical infrastructure: pin exact versions and review upgrades.
Its calls bypass llm_calls and our traces unless you add its callbacks.
A cascade inside one model: the cheap pass (thinking off) answers everyone; only held or ABUSIVE answers get a second pass with thinking (should_escalate() in ai/moderation.py).
Thinking is output tokens: you pay for them and wait for them. Escalation pays only on the few reviews that need it.
Why does the model give pos/neg and a quote, but never a score (labs 07-08)?¶
"The LLM extracts, code calculates." Reading Hinglish is a language task; averaging is arithmetic.
A model asked for "rust: 7/10" invents precision and can't be checked. A label plus a quote can.
Scores rank with a Bayesian average and the Wilson lower bound (ai/scoring.py), so two 5★ reviews don't beat eighty at 4.6.
Stuff, map-reduce or grounded summaries (lab 12)?¶
Retrieval gives the model 5 reviews. "How many complain about cracking?" needs all 24. The model would count 5 and sound sure.
A rule routes counting questions to SQL (is_count_question()); open ones go to cited RAG, which refuses when nothing relevant is close enough or the answer cites what it wasn't given.