Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 115/ 160
06. AI Security

Content Moderation

Classify and block disallowed content in inputs and outputs per policy.

BeginnerModeration APIs · Categories3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

Content moderation checks what people write and what the AI replies, blocks things that break the rules and lets humans review the tricky cases.

Think of it like…

A newsroom's editorial desk: most pieces go straight through, borderline ones are flagged for an editor, a few are rejected with a reason, and writers can appeal; the standards differ between a children's magazine and an investigative outlet.

Where you’ve seen it

A chat product handles 1,000,000 messages a day. A moderation classifier flags 0.8% (8,000) at the blocking threshold, and the policy defines per-category actions: hate and harassment blocked with an explanation, sexual content restricted by age setting, self-harm routed to a supportive response with resources instead of a refusal, and violence in clearly fictional or news contexts allowed with a content warning. Precision at the strict threshold is 85% versus 40% at a lenient one, which changes the human-review load: reviewing all 8,000 at 20 seconds each is 44.4 hours a day, so only borderline scores (about 2,000 a day) go to humans while high-confidence blocks are automatic. Users appeal 1.5% of blocks (120 a day) and reviewers overturn 22% (about 26 a day), a lower bound on the false-positive rate that feeds threshold tuning. Evaluation per language shows recall of 94% in English but 81% in Hindi, so the team adds labelled data and a multilingual classifier, and tracks over-blocking on a benign-but-sensitive test set (medical, security education, fiction).

Words you’ll hear

Policy categories
The defined classes of disallowed or restricted content and their severity.
Threshold
The score above which a category triggers an action.
Safe completion
A helpful, safe response that addresses a sensitive request without harmful detail.
Appeal / overturn rate
Users contesting a block and how often reviewers reverse it.

Visual diagram

Loading interactive diagram

Theory & deep dive

Policy, classifiers and actions

Start with a written policy: categories, definitions, severity levels, examples of allowed and disallowed content, and context rules (education, news, fiction, medical, security research). Different audiences and jurisdictions need different settings, so make thresholds configurable per product and age band. Technically, use moderation APIs (OpenAI, Azure AI Content Safety, Google, Perspective-style services), open safety classifiers you can host and adapt, or custom classifiers fine-tuned on your data; combine with rules for hard constraints (banned terms in specific contexts, link and contact-detail patterns) and with PII detection. Moderate both directions: user inputs (to catch abuse and jailbreak attempts) and model outputs (to catch harmful generations), and consider images, audio and file contents for multimodal products.

Map scores to actions per category: allow, allow with warning or label, restrict (age-gated, reduced detail), safe completion or redirect (for self-harm: empathetic response and crisis resources), block with a clear message, throttle or suspend accounts for repeat violations, and escalate to a human. Use two thresholds: a high one for automatic action and a lower one for human review, so the review queue contains the uncertain band rather than everything flagged. Log the category, score, action and policy version for each decision to support audits and appeals.

Review load maths

8,000 flagged/day × 20 s = 160,000 s = 44.4 h/day if all were reviewed. Routing only the ~2,000 borderline items to humans costs 2,000 × 20 s = 11.1 h/day; the high-confidence blocks (about 6,000) are automatic, with appeals as the safety net.

Key takeaway: Write the policy first, moderate inputs and outputs, and use graded actions with two-threshold routing to humans.

Evaluation, fairness and operations

Evaluate against labelled data from your traffic: per-category precision and recall, performance by language, dialect and topic, and an over-blocking test set of legitimate sensitive content (health information, harm-reduction, security education, historical or fictional violence). Recall of 94% in English but 81% in Hindi means unequal protection and unequal over-blocking, which is both a safety and a fairness issue; add multilingual data and tune per language. Watch adversarial evasion (leetspeak, spacing, images with embedded text, code words) and context failures (quoting abusive text to report it, reclaimed slurs, satire). Track operational metrics: flag rate, human review time, overturn rate on appeal, time to action and complaint volumes.

Build the human loop: reviewers need clear guidelines, tooling with context (conversation history, prior violations), wellness support for exposure to harmful content and calibration sessions to keep decisions consistent. Provide an appeals process with timely responses; overturned decisions are labelled data (1.5% of 8,000 blocks appealed = 120 a day, 22% overturned = 26 a day, a lower bound on false positives). Keep versioned policies and thresholds, run A/B tests on threshold changes with guardrail metrics, and retrain or adjust regularly as language and abuse patterns evolve. Respect privacy and law: minimise retention of flagged content, restrict access and follow regional rules on reporting certain categories. Finally, remember moderation is a layer, not the whole safety system: pair it with model safety training, tool controls and monitoring.

Appeals as a signal

8,000 blocks/day × 1.5% appealed = 120 appeals; 22% overturned ≈ 26 wrongly blocked per day at minimum (many users never appeal). If most overturns cluster in one category and language, retune that threshold and add training data there.

Key takeaway: Measure precision and recall per category and language, test over-blocking, support human review and appeals, and iterate on versioned policy.

How it works, step by step

Step 1 of 4
Policy + legal + product

1. Write the content policy

Define categories, severity, contexts and actions per audience and region.

hate · harassment · sexual · self-harm · violence
Key numbers at this step
Version
policy and thresholds

When to use it & trade-offs

What it is

Content moderation classifies user inputs and model outputs against a content policy (categories such as hate, harassment, sexual content, self-harm, violence, illegal activity, privacy violations) and decides what to allow, warn, restrict, block or escalate. Implementations combine moderation APIs and classifiers (provider endpoints, open safety models such as Llama Guard-style classifiers), rules and allowlists, per-category thresholds, graded actions (a safe completion or crisis resource instead of a flat refusal for self-harm topics), a human review queue and an appeals path. It must be evaluated for both missed harm (recall) and over-blocking (false positives), across languages and contexts.

Why it matters: Products that generate or relay user content face legal, safety and brand risks, and users expect consistent, explainable decisions. Moderation also has real costs: false positives silence legitimate users (a nurse asking about drug doses, a novelist writing a violent scene), false negatives cause harm, review queues cost money and the policy itself is a product decision that varies by audience (a children's app versus an adult creative tool). Designing the policy, thresholds and escalation deliberately is as important as the classifier.

When to reach for it

  • User-generated content and chat products
  • Filtering model outputs for safety
  • Meeting platform and regulatory expectations

When to avoid or be careful

  • A single global threshold for all categories and audiences
  • Flat refusals for self-harm topics
  • Skipping evaluation across languages

Moderation approaches

Hosted moderation APIs
Best for: Fast start with maintained categories

Strengths: Low effort; regularly updated.

Watch out: Less control; generic policy; data leaves your boundary.

Self-hosted safety classifiers
Best for: Custom policy and data control

Strengths: Adaptable; private; tunable.

Watch out: You maintain training, hosting and evaluation.

Human review
Best for: Borderline cases, appeals and labelling

Strengths: Nuanced judgement.

Watch out: Slow, costly and emotionally taxing.

Interview signals & numbers to know

When this topic comes up

  • “Block hate and harassment”
  • Moderation API
  • Over-blocking
  • Appeals and overturn rate
  • Safe completion

Benchmarks & rules of thumb

8,000 flagged/day -
0.8% of 1,000,000 messages
44.4 h → 11.1 h -
review time for all flags vs borderline only
94% vs 81% -
recall in English vs Hindi in the example

Common mistakes & follow-ups

Common interview mistakes

  • Treating moderation scores as ground truth without measuring precision.
  • Sending every flag to human reviewers.
  • Ignoring legitimate sensitive use cases such as medical or educational content.

Likely interviewer follow-ups

  • How would you moderate both inputs and outputs of a chat assistant?
  • How do you balance missed harm against over-blocking?
  • What role do appeals play?
Interview tip: Quote per-language recall and the appeals overturn rate. They show you monitor fairness and false positives, not just a headline accuracy.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Content Moderation with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Human Approval for Actions
Next topic
Data Poisoning