Slides · GenAI system design
Designing content moderation and guardrail systems
1 / 30
Designing content moderation and guardrail systems
Moderation is a trade, not a switch. This deck designs the system around the trade: layers, thresholds, a human lane, and safe tuning.
By the end you can:
- design layered input and output moderation, and choose serial, windowed or parallel output checks from harm severity and latency,
- work out precision and recall from counts at two thresholds, and explain why the threshold per category is a business decision,
- design escalation, appeals and logging, sizing human review from reviewer capacity,
- tune thresholds with shadow mode and labelled samples, and diagnose and roll back a threshold change that doubled the block rate.
Concept
Two errors, and you can only move them
- Block too little and harmful output reaches users.
- Block too much and honest users are refused, lose trust and leave.
- Neither error can be removed, only moved. The design question is who bears the cost of each mistake, and who decides where the line sits.
- All counts and capacities in this deck are illustrative assumptions, not measurements of any real classifier.
Mental model: airport security with three lanes. Most travellers walk through, a few are clearly stopped, and a middle band gets a manual check. Staffing the manual lane limits how wide that band can be. The detector’s sensitivity is a dial that someone with authority sets.
Diagram
Two thresholds make three lanes
Concept
Requirements for a consumer chatbot
| Aspect | Requirement |
|---|---|
| Policy | A written list of categories (for example self-harm, hate, sexual content involving minors, regulated advice), each with a stated severity |
| Coverage | Screen user input and model output |
| Latency | Moderation adds only a small, stated share of response time; assume 100 ms for the input check |
| Fairness | A blocked user gets a clear message and a way to appeal |
| Auditability | Every decision is logged with enough context to review |
| Out of scope | Prompt-injection defence for agents with tools |
Concept
A harm classifier is not an injection defence
- A moderation classifier scores content against a policy. Llama Guard, for example, uses a safety risk taxonomy to classify user prompts and model responses.
- Jailbreaks and prompt injection are attempts to get a model to disregard the rules its developer or operator set. Anthropic’s documentation treats them as their own problem with their own mitigations (screening, hardened prompts, safe handling of untrusted tool content).
- A message can be harmless by the policy and still try to steer the model. It can also be harmful and carry no steering at all.
- So keep the two designs separate, and do not claim the moderation layer covers injection.
Sources[1] Mitigate jailbreaks and prompt injections[2] Llama Guard: LLM-based Input-Output Safeguard for Human-AI Conversations
Compare
The layers are a menu, not a script
Anthropic’s guidance describes combining several strategies rather than relying on one: a lightweight input screen, input validation, prompt engineering, and monitoring.
| Layer | Catches | Cost and weakness |
|---|---|---|
| Input classifier | Clearly harmful requests before the model runs | Adds latency; false positives refuse honest users |
| System prompt policy | Cheap steering toward policy | It is a request to the model, so it can be talked around |
| Output classifier | Harmful text produced despite earlier layers | Adds latency or buffering; may be wrong |
| Human review | Borderline and disputed cases | Slow and costly; limited capacity |
| Logging and appeals | False positives and new failure patterns | Stores sensitive text, so needs access controls and retention limits |
Each layer catches a different failure. Combine them by risk, not by habit.
Sources[1] Mitigate jailbreaks and prompt injections[2] Llama Guard: LLM-based Input-Output Safeguard for Human-AI Conversations
Compare
Serial, windowed or parallel: choose by harm severity
| Pattern | How it works | Latency | Choose it when |
|---|---|---|---|
| Serial | Generate the whole answer, check it, then show it | Highest: wait for the full generation | Severe harm: even a brief display is unacceptable |
| Windowed streaming | Check the text so far every N tokens; release with a small lag; cancel on violation | Small added lag | Mixed risk: a short lag is acceptable |
| Parallel and retract | Stream at once, check alongside, remove if flagged | Lowest | Low severity: a flagged message shown for a second is tolerable |
- A stream that has already shown text cannot be un-shown, only retracted. Parallel checks are weak where severity is high.
- Check the service you use. OpenAI’s moderation guide notes that for a streamed response the scores are delivered only once generation has finished, not with the partial chunks. That pushes you toward buffering or your own check on partial text.
Source[3] Moderation
Diagram
The three patterns side by side
Worked example
Worked: pick a pattern per category
Illustrative latency for a 400-token answer streamed at 50 tokens per second: the whole answer takes 50400=8 seconds to generate.
| Category (judgment, not data) | Severity | Pattern | First visible text |
|---|---|---|---|
| Instructions for self-harm | Severe | Serial | After about 8 s of generation plus the check |
| Regulated advice claims | Medium | Windowed, N=50 tokens | About 1 s (5050) plus a check, then a steady lag |
| Mild profanity | Low | Parallel and retract | Immediately |
- The input check can also be serial or parallel. Serial saves the cost of a generation you would discard; parallel saves latency and lets you cancel, at the price of some wasted work. For severe categories, serial is the safer choice.
- The product owner and policy team confirm the severities. Engineering supplies the latency numbers.
Check yourself
Check: windowed checks without partial scores
Your moderation provider returns output scores only after the full output exists, but a category needs windowed streaming. What are your options?
Answer
Run your own check on the accumulated text every N tokens, using a classifier you operate or a separate call on the partial text, and release text with a small lag. If that is too costly or too weak for the category, fall back to serial buffering and accept the wait. Read the provider’s current documentation, because behaviour can change.
Source[3] Moderation
Math
Precision and recall from counts
precision=tp+fptprecall=tp+fntpfpr=fp+tnfp| Symbol | Meaning |
|---|---|
| tp | Violations that were blocked (true positives) |
| fp | Benign messages that were blocked (false positives) |
| fn | Violations that were let through (false negatives) |
| tn | Benign messages that were allowed |
| fpr | False-positive rate: the share of benign messages blocked |
scikit-learn’s documentation gives the first two definitions. Precision asks “of what we blocked, how much was a real violation”. Recall asks “of the real violations, how many did we catch”.
Source[4] Metrics and scoring: quantifying the quality of predictions
Worked example
Worked: two thresholds on the same traffic
Assumptions: 1,000,000 messages a day, 0.5% truly violate policy: 5,000 violations and 995,000 benign messages.
| Row | Threshold A (lenient) | Threshold B (strict) |
|---|---|---|
| Recall | 90% | 98% |
| Violations caught | 0.90×5,000=4,500 | 0.98×5,000=4,900 |
| Violations missed | 500 | 100 |
| False-positive rate | 1% | 3% |
| Benign blocked | 0.01×995,000=9,950 | 0.03×995,000=29,850 |
| Precision | 14,4504,500≈31% | 34,7504,900≈14% |
Moving from A to B catches 4,900−4,500=400 more violations and blocks 29,850−9,950=19,900 more honest messages: about 50 honest messages (40019,900=49.75) for each extra violation caught.
Diagram
Where the messages go at threshold A
Concept
Why precision looks low: the base rate
- Violations are 0.5% of traffic. A 1% false-positive rate is higher than that, so benign blocks (9,950) outnumber caught violations (4,500).
- Most blocks are false positives when fpr×(benign messages) exceeds recall×(violations).
- A much lower false-positive rate changes the picture. At 0.1% (illustrative), benign blocked = 0.001×995,000=995, and precision = 4,500+9954,500≈82%.
- So a classifier that looks excellent on a balanced test set can disappoint on real, mostly benign traffic.
Concept
Who decides, and per category
- Is 400 more catches worth about 19,900 more refused honest messages? There is no technical answer. It depends on the harm of one missed violation in this product.
- A children’s education product, a medical-advice assistant and an internal developer tool should sit at different points.
- The product owner and policy team set the threshold. Engineering supplies the counts of both error types.
- Set a threshold per category, not one global number.
| Category type | Threshold | Human lane | Output pattern |
|---|---|---|---|
| Severe harm | Strict | Yes | Serial |
| Medium harm | Moderate | Narrow band | Windowed |
| Tone or style | Lenient | Usually none | Parallel and retract |
The last three columns are an illustrative starting point to adjust with the policy team.
Check yourself
Check: what false-positive rate do you need?
A product sees 800,000 messages a day, 1% of which truly violate policy (8,000). Recall is 85% and the false-positive rate is 0.5%. The policy team asks for at least 80% precision with recall unchanged. What false-positive rate does that require, and how many honest messages would then be blocked per day?
Answer
Caught violations: 0.85×8,000=6,800. For precision 0.8, tp+fptp=0.8, so fp=6,800×0.25=1,700. Benign messages: 792,000, so the false-positive rate must be 792,0001,700≈0.21%. Today’s 0.5% blocks 3,960 honest messages, so the rate must fall by more than half. Recall stays 85%, so the 1,200 misses do not change.
Worked example
Capacity sizes the human lane
Assumptions (illustrative): 2,000 items a day fall in the middle band. A reviewer handles 120 items an hour over an 8-hour shift.
- One reviewer per day: 120×8=960 items.
- Reviewers needed: 9602,000=2.08, so 3, not 2.
- Always round up, because a fraction of a person does not exist.
- If you cannot staff it, narrow the band. An unstaffed queue grows, and “escalate” silently means “ignore”.
Failure signal: queue age. Responses: narrow the band, add staff, or apply a default rule that you chose in advance.
Check yourself
Check: what happens to an understaffed queue?
Each reviewer handles 90 items an hour for 6 productive hours a day. You have 3 reviewers and the borderline band holds 1,900 items a day. What is the largest band the team can clear, and how many items are waiting after 5 days?
Answer
One reviewer clears 90×6=540 items a day, so three clear 1,620. The band of 1,900 leaves 1,900−1,620=280 items unreviewed each day, so after 5 days 5×280=1,400 are waiting. The queue age keeps growing, which is why “escalate” quietly becomes “ignore”. Options: narrow the band to 1,620 or fewer, add a fourth reviewer (2,160 a day), or apply a default rule you chose in advance.
Process
Escalation, appeals and logging
- Clear refusal. Tell the user what happened without leaking the policy’s internals.
- Appeal that reaches a person. Blocked honest users have a path back.
- Log with context. Store blocked content and the decision so false positives can be found and classifiers improved.
- Protect the logs. They hold sensitive text: restrict access, minimise what is stored, set retention limits.
- Label and feed back. Review decisions and appeal outcomes become labelled examples for tuning.
- Repeat offenders. Anthropic’s guidance suggests responding to users who repeatedly try to bypass guardrails, for example by throttling or banning them.
Diagram
Components: the request path
Diagram
Components: the labels and tuning loop
Compare
Failure modes
| Failure | Signal | Response |
|---|---|---|
| Classifier service down | Timeouts, error rate | Decided in advance: fail closed for severe categories; fail open with logging for low-severity ones |
| Block rate spikes | Alarm per category | Compare versions and traffic; roll back the threshold or model |
| New attack phrasing | User reports, red-team misses | Add examples, retrain, tighten temporarily |
| Review queue backlog | Queue age | Narrow the band, add staff, or use a default rule |
| Multilingual gaps | Higher error rate on non-English slices | Slice metrics by language; add data |
| Logs leak sensitive text | Access audit | Minimise stored text, restrict access, set retention |
Check yourself
Check: the classifier is down for 20 minutes
The product has a severe category (sexual content involving minors) and a low-severity one (off-topic jokes). The classifier times out for 20 minutes. What should each category do, and what must have happened before the outage?
Answer
The severe category fails closed: hold or refuse rather than let unchecked content through. The low-severity category fails open, with logging so the unchecked traffic can be reviewed afterwards. The choice must have been made in advance, in the policy, with the product owner, not improvised during the incident, and an alarm on the error rate should have fired.
Process
Tune with shadow mode
- Run the new threshold or classifier on live traffic and record what it would have done. It acts on nothing.
- Compare its decisions with the current system and with human labels.
- Measure precision by labelling a sample of blocked items and counting false positives.
- Measure recall with care (next slides): misses are rare among passed messages.
- Report per slice: category, language and product surface.
- Put thresholds and classifier versions behind flags so promotion and rollback are config changes.
Worked example
Worked: sampling by score band
Illustrative split of the 985,550 messages that passed at threshold A (500 violations were missed in total, which gives recall 5,0004,500=90%).
| Score band of passed messages | Items | Misses | Miss rate |
|---|---|---|---|
| Just below the threshold | 10,000 | 400 | 4% |
| Far below the threshold | 975,550 | 100 | about 0.01% |
- Label 1,000 items from each band. Near the threshold you expect about 40 misses, enough to estimate the rate. Far below you expect about 0.1, so the sample will probably show none.
- Weight each band by its size. If the far-band sample shows no misses, the estimate is 10,000×4%=400 misses, so recall is 4,500+4004,500≈91.8%, against the true 90%.
- The gap is the far band’s hidden 100 misses. That is why a red-team set with known violations and user reports sit alongside the sample.
Diagram
An alarm fires: let a labelled sample decide
Scenario (illustrative): one category’s block rate goes from 0.8% to 1.6% of messages after a provider model update. No complaints yet.
- If honest users are already complaining, do not wait for the sample: switch the change off behind its flag first, then investigate.
- Rule out a traffic change (a campaign or abuse wave) as well as a version change.
- OpenAI’s guide says its moderation model will keep being upgraded, so thresholds built on its category scores may need re-tuning, and its scores are inputs to your policy rather than a verdict that blocks by itself.
Source[3] Moderation
Concept
Cost and latency
- Each classifier call costs time, and for model-based classifiers, money.
- Run cheap rules first, a small classifier next, and the expensive model only on the middle band.
- Cache decisions for identical inputs if the policy allows.
- Budget the input check at 100 ms (the assumption above), and count windowed output checks against time to first token.
Trade-off: more layers catch more, and each adds latency, cost and its own false positives.
Compare
What strong answers contain
| Weak answer | Strong answer |
|---|---|
| One binary filter | Layers chosen by risk |
| One global threshold | A threshold per category, set with the product owner |
| “Escalate to humans” | A human lane sized from reviewer capacity |
| No path for blocked users | Refusal message, appeal and a stored label |
| Tune on a hunch | Shadow mode, labelled samples and a rollback flag |
Interview note (common industry pattern, no company-specific claim): “design moderation for a chatbot” and “balance safety with annoying legitimate users” are typical prompts, and presenting moderation as a single binary filter is a common mistake.
Summary
Recap
- Layers are a menu: input classifier, policy prompt, output check, human lane, logging and appeals.
- Choose serial, windowed or parallel output checks by harm severity, because streamed text cannot be un-shown.
- Thresholds are per category and set by the business; show the counts of both error types.
- Most blocks are false positives when fpr×(benign messages) exceeds recall×(violations).
- Size the human lane from reviewer capacity, and round up.
- Tune in shadow mode; recall is hard to measure, so sample near the threshold and use red-team sets.
- Keep thresholds behind flags so rollback is a config change.
References
References & Sources
Mitigate jailbreaks and prompt injections (opens in a new tab)
Anthropic2026Documentation
https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/mitigate-jailbreaks
Used for Jailbreaks and injection are a separate problem from harm classification; layered strategies; responding to repeat offenders; monitoring.
Llama Guard: LLM-based Input-Output Safeguard for Human-AI Conversations (opens in a new tab)
Hakan Inan, Kartikeya Upasani, Jianfeng Chi, Rashi Rungta, et al.2023Preprint
DOI 10.48550/arXiv.2312.06674 (opens in a new tab)arXiv 2312.06674 (opens in a new tab)https://arxiv.org/abs/2312.06674
Used for An example of a safety classifier that uses a risk taxonomy to classify both user prompts and model responses.
Moderation (opens in a new tab)
OpenAI2026Documentation
https://developers.openai.com/api/docs/guides/moderation
Used for Moderation scores are signals for your policy; streamed output scores arrive after the full output; the model is upgraded over time so thresholds may need recalibration.
Metrics and scoring: quantifying the quality of predictions (opens in a new tab)
scikit-learn2026Documentation
https://scikit-learn.org/stable/modules/model_evaluation.html
Used for Definitions of precision and recall from true positives, false positives and false negatives.
Keys: ← → move, Home End first and last, F full screen.