Skip to content

RnR FAQ

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.

Data and design (lab 00)

Why generate synthetic data from a spec?

  • The label (decision, reasons, aspects) is decided first, so the golden set is right by construction.
  • Text written first and labelled later needs a human (or a model) to label it, and those labels have errors.
  • You can plant problems on purpose (a late seller, a defect batch, a fake burst) and check that the AI finds them.
  • See build_specs() in data/reviews.py.

Why does every model call go through generate()?

  • One place to enforce the output schema and validate it, and to cap the output.
  • One place to log feature, prompt version, tokens, latency and errors in llm_calls.
  • Cost reports, the ops page and eval comparisons by prompt version all read that table.
  • A call that bypasses it is invisible to cost and quality tracking. See ai/llm.py.

Why moderate in the background instead of during the request?

  • A local model takes seconds per review; the buyer should not wait.
  • The API stores the review as PENDING, queues a job and replies 202. The worker moderates it.
  • If the model is down, reviews wait or go to a human; nothing is published unchecked. See api/repo.py create_review().

Guardrails (labs 02-04)

Why a few rules first, and why not an abuse keyword list?

  • Rules are free and instant, and the ones we keep are almost never wrong.
  • They only cover patterns that are never legitimate in a review: links, known injection phrases, copy-paste bursts.
  • Abuse vs anger is a judgement call. "Cheaters" in an honest complaint, new slang, Hinglish: a keyword list gets both wrong.

Why redact PII instead of rejecting the review?

  • A buyer who adds a phone number still wrote a genuine review; rejecting it loses a real opinion.
  • Mask it before the model sees it, and publish the masked text (redact_pii() in ai/guardrails.py).
  • A HELD review keeps the masked text, so a human who approves it later publishes the safe version.

How do we defend against prompt injection in review text?

  • Rules catch the copy-paste attacks for free (detect_injection()).
  • The prompt fences the text in <review> tags, strips < and > so it can't close the tag, and says "data, not instructions" before and after it.
  • The verdict is checked in code, so a "decision=APPROVE" typed into the review is just text.
  • None is perfect alone; 03_injection_and_pii.py shows what each layer adds.

Can we trust the model's confidence score?

  • 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.

What does "fail closed" mean here?

  • 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.

Evals (labs 05, 13)

Why build the eval before fixing the prompt?

  • 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).

Offline or online evals?

Offline (golden set) Online (production)
When Before a change ships Every day after
Needs labels Yes, decided in advance No: humans' actions are the signal
Misses Anything the test set never contained Mistakes nobody happened to check
Where Lab 05 Ops page (online_signals() in api/repo.py)

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.

Tracing (lab 06)

What are a trace and a span?

  • A span is one step: a name, start and end time, status and attributes (review id, tokens, decision).
  • A trace is all the spans of one piece of work (one review), tied by one trace_id; parent_id makes them a tree.
  • obs/tracing.py: with span("llm.generate", kind="LLM") as s: ... s.set(prompt_tokens=610).

Logs, metrics or traces: which one do I need?

Answers Example here
Logs What did one process say at one moment? "job 12 failed, now queued"
Metrics How is the system doing overall, over time? p95 of llm.generate, error count
Traces What happened to this request, step by step? RV00064: rules passed, model said ABUSIVE, net held it

All three; traces first for AI features, because the steps and the decision are what people ask about.

Should prompts and model answers go into traces?

  • They make debugging fast, and they make the trace store a second copy of your data.
  • Here the model only sees masked text, so spans hold [PHONE], never the number (a test checks this). RNR_TRACE_CONTENT=0 keeps only sizes and tokens.
  • Rule: never put anything in a span you wouldn't put in the product database.

Phoenix, Langfuse, LangSmith or our own APM?

  • All accept OpenTelemetry, so the instrumentation stays the same; only the exporter changes.
  • Pick by where your engineers already look, data residency, and cost at your volume.

Cost and the gateway (labs 09, 11)

Ollama tokens are free. What does the rupee figure mean?

  • Two "what ifs", side by side: what a hosted API would charge for the same tokens, and what your own GPU would cost for the same seconds (ai/cost.py).
  • Both are dated assumptions in ai/rate_card.json. Tokens and seconds in llm_calls are facts; rupees are facts × assumptions.

What does an AI gateway add to llm.py?

  • 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.

Optional labs

What is escalation (lab 10)?

  • 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)?

Strategy Fits when Watch out for
stuff (all reviews, one call) Few, short reviews; a one-off Numbers are the model's counting
map-reduce (batches → notes → merge) Long text with no structure Each batch counts on its own, so totals drift
grounded (facts from code → words) You already extract structure Says only what the facts hold

Why do counting questions skip RAG (lab 14)?

  • 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.