security-course

Security, Privacy, and Consumer Protection

View the Project on GitHub noise-lab/security-course

LLM-Assisted Content Moderation

The goal of this assignment is to understand how large language models can be used for automated content moderation and to critically analyze the strengths, weaknesses, and security properties of such systems. You will build a moderation classifier on top of Claude, evaluate it against your own test data and your own human labels, attack it with prompt injection, and reason about the policy and cost trade-offs of deploying it at scale.

Background

Content moderation at scale is one of the most challenging problems facing online platforms. Platforms must balance free expression with safety, navigate cultural differences, and make millions of decisions per day about what content violates their policies. Increasingly, platforms are exploring the use of LLMs to augment or replace traditional keyword-based and machine learning approaches to content moderation.

In this assignment, you will use Anthropic’s Claude content moderation framework as your baseline implementation, then extend and evaluate it for real-world platform policies. Because you are literally building on top of an AI here, the interesting question is not “can the AI do it?” but “where does the AI’s judgment diverge from yours, why, and can the classifier be tricked?

Grading & Rubric (100 points)

This rubric is shown up front so you know where to invest your effort. Labs are graded primarily for thoughtful completion; points reward understanding, not polish. Because your report is graded from its text, your numbers (the results table and the computed metrics) must appear as text in the report — not only in a notebook or a screenshot.

Component Points What earns full marks
Implementation (both prompts) 12 Working moderation function on the Claude API; both the basic and chain-of-thought prompts are pasted in full as text.
Platform policy + diverse dataset 13 You name one platform, summarize its policy for 2–3 categories from its actual ToS, and build a 10–15 case set with clear violations, clear non-violations, and borderline cases.
Results table (per case, both approaches) 15 A text table with one row per case: input summary, your human label, basic-prompt output, chain-of-thought output.
Metrics: accuracy + precision/recall/F1 (depth) 15 You compute accuracy and precision, recall, and F1 for both approaches as numbers, show/define the confusion matrix, and explain why accuracy alone misleads on imbalanced data.
Prompt-injection / jailbreak robustness (depth) 15 You craft adversarial inputs that try to bypass the moderation prompt, report per-attack whether the classifier held, and say which approach was more robust.
Policy analysis (performance, CoT comparison, cost, recommendations) 20 The 2-page analysis covers performance, the CoT comparison, a cost-at-scale estimate, and concrete deployment recommendations.
Reflection & AI-verification 10 You report what you tried (incl. dead ends), what surprised you in your own data, and at least one case where Claude’s label diverged from yours plus why.
Extra credit: second model / adversarial-set sophistication +10 Either compare a second model or a self-consistency/voting setup, or build an adversarial set that systematically defeats the basic prompt and test whether CoT resists it. See the stretch below.

Report numbers, not adjectives: “precision 0.71, recall 0.50” beats “fairly accurate.” Ground every claim in your specific cases — generic prose that could describe anyone’s run earns little credit.

Required Reading

Before starting the assignment, review these resources:

  1. Anthropic’s Content Moderation Guide: https://docs.claude.com/en/docs/about-claude/use-case-guides/content-moderation
  2. Building a Moderation Filter (Cookbook): https://github.com/anthropics/anthropic-cookbook/blob/main/misc/building_moderation_filter.ipynb

These resources demonstrate Claude’s approach to content moderation, including prompt engineering techniques, risk-level classification, and best practices.

Tasks

You will implement Anthropic’s content moderation framework, evaluate its performance on a test dataset you build, attack it, and analyze the policy implications.

Part 1: Implementation

Following Anthropic’s content moderation guide:

  1. Set up the Claude API (free tier or educational credits available).
  2. Implement the basic moderation function from the guide.
  3. Choose a platform and policy focus:
    • Select 1 platform (e.g., Reddit, Twitter/X, YouTube, Facebook).
    • Pick 2–3 content categories to focus on (e.g., hate speech, harassment, spam).
    • Document the platform’s policy for these categories from their actual Terms of Service / Community Guidelines (quote or cite it).
  4. Create a test dataset of 10–15 examples including:
    • Clear violations
    • Clear non-violations
    • Borderline / context-dependent cases (a dataset with no borderline cases will lose points — the borderline cases are where the interesting findings live)

    Source from public datasets, create synthetic examples, or use anonymized real content. This dataset and your labels are your personal artifact — the grader checks that your analysis is consistent with your specific data.

  5. Build two prompting approaches and paste both prompts verbatim in your report:
    • Basic classification — a simple prompt that returns a label.
    • Chain-of-thought reasoning — the model reasons (e.g., in <thinking> tags) before returning the label.

Part 2: Testing and Evaluation

  1. Record your own judgment for each test case first — this is your human baseline and ground truth. Do this before you look at Claude’s output so your labels aren’t anchored to the model.

  2. Run both prompting strategies on your test dataset and record every output.

  3. Build the results table. One row per case with: a short input summary, your human label, the basic-prompt output, and the chain-of-thought output. This table is the backbone of the report.

  4. Compute real metrics — not just accuracy — for both approaches. Treat one class as “positive” (a policy violation). For each approach, count:
    • TP (true positives): you said violation, Claude said violation.
    • FP (false positives): you said OK, Claude said violation (over-removal — censoring legitimate speech).
    • FN (false negatives): you said violation, Claude said OK (missed violation — harmful content stays up).
    • TN (true negatives): you said OK, Claude said OK.

    Then report, as numbers:

    • Accuracy = (TP + TN) / total
    • Precision = TP / (TP + FP)
    • Recall = TP / (TP + FN)
    • F1 = harmonic mean of precision and recall = 2·(P·R)/(P+R)

    Show the confusion matrix for each approach. Then explain, in your own words: why does accuracy alone mislead on moderation data? (Hint: real platform traffic is mostly benign, so a classifier that approves everything scores high accuracy while catching zero violations.) Discuss the asymmetric real-world cost of false negatives (missed harmful content) vs. false positives (over-removal of legitimate speech) for your platform and categories.

  5. Analyze limitations:
    • Identify cases where Claude struggled (sarcasm, reclaimed slurs, context, satire, dialect, etc.).
    • Test whether Claude’s safety training overrides your instructions on any example — e.g., does it refuse to classify, or label content differently than your policy requires?
    • Note any policy conflicts between Claude’s values and the platform’s policy.

Part 3: Prompt-Injection / Jailbreak Robustness (depth)

A moderation classifier is a security-sensitive system: the content it reads is untrusted input, and an adversary controls it. Test whether your classifier can be made to misclassify by what’s inside the content. Craft at least 4–5 adversarial inputs, covering several techniques:

For each attack, report: the input, the intended bypass, the basic-prompt result, the CoT result, and whether the classifier held (correct label) or was defeated (wrong label). Then state which approach was more robust and offer a hypothesis for why. This is the adversarial, security-relevant core of the lab — do not skip it.

Part 4: Policy Analysis (2 pages)

Write a ~2-page analysis addressing:

  1. Performance: How accurate was Claude, and — more importantly — what do precision/recall/F1 say about where it succeeded and failed? Which cases drove the errors?
  2. Comparison of approaches: Did chain-of-thought reasoning help? On which cases (including the borderline and adversarial ones)? Why or why not?
  3. Context understanding: How well did Claude handle nuance, sarcasm, and context for your categories?
  4. Cost feasibility: Using Anthropic’s pricing, estimate the cost of moderating at your platform’s scale (e.g., per million posts), and compare CoT (more tokens) vs. basic.
  5. Policy recommendations:
    • When is LLM-based moderation appropriate vs. problematic — given your precision/recall and the cost of FP vs. FN?
    • What safeguards are needed (human review, appeals, escalation thresholds)?
    • How should the classifier be hardened against the injection attacks you found?
    • How should platforms balance automation with transparency?

Reflection & tinkering (required)

This is where you show the work is yours. In a short reflection (a few paragraphs):

Stretch — second model or adversarial set (extra credit, +10)

Go beyond a one-shot evaluation. Pick one:

Either way, report the numbers and what you concluded. This requires real tinkering and is self-evidently done or not — a good way to go beyond the baseline.

Using AI (encouraged, with verification). This lab is built on an LLM, so the verification angle is sharper than usual: do not just accept Claude’s labels — scrutinize where Claude’s judgments diverge from your own human labels, and figure out why. If you also use an LLM to help write code or interpret results, include the exchange in the appendix and verify its claims against your own data. The highest-value finding in this lab is a specific, well-explained disagreement between you and the model. Asserting “Claude was accurate” without grounding it in your table and metrics will lose points; catching and explaining a divergence earns full marks for the reflection item.

Be ready to defend it. Per the syllabus, we may ask you to reproduce or explain any part of this lab live (office hours, a pop quiz, or the exam) — e.g., “re-run your basic prompt on this new input,” “compute recall from your confusion matrix,” or “show me an injection attack that worked.” Do the work so you can.

Submission Instructions

Submit a single markdown report named moderation-report.md. Because your report is graded from its text, paste the required evidence as text directly into the report — both prompts, the results table, and the computed metrics (as numbers). Screenshots and notebooks are welcome as corroboration but are not a substitute for the pasted text and numbers.

Your report must contain these headings, in this order (they map one-to-one to the rubric above):

# Content Moderation Lab — <your name>

## 1. Implementation & Prompts
   - How you set up the Claude API and the moderation function
   - The BASIC prompt, pasted verbatim
   - The CHAIN-OF-THOUGHT prompt, pasted verbatim

## 2. Platform Policy & Test Dataset
   - Platform chosen and the 2–3 categories
   - The platform's policy for those categories (quoted/cited from ToS)
   - Your 10–15 cases: how many clear violations / clear non-violations / borderline

## 3. Results Table
   - One row per case: input summary | your human label | basic output | CoT output

## 4. Metrics: Accuracy + Precision/Recall/F1 (both approaches)
   - Confusion matrix for BASIC and for CoT
   - Accuracy, Precision, Recall, F1 for each — as numbers
   - Why accuracy alone misleads on imbalanced moderation data
   - FP (over-removal) vs FN (missed violations): the asymmetric cost for your platform

## 5. Prompt-Injection / Jailbreak Robustness
   - Each attack: input | intended bypass | basic result | CoT result | held or defeated?
   - Which approach was more robust and your hypothesis why

## 6. Policy Analysis
   - Performance, CoT comparison, context understanding
   - Cost at scale (per million posts; basic vs CoT)
   - Recommendations: when to use, safeguards, hardening against injection, transparency

## 7. Reflection & Tinkering
   - What you tried that didn't work; what surprised you in YOUR data;
     at least one Claude-vs-your-label divergence and WHY it diverged

## 8. (Extra credit) Second model / self-consistency / adversarial-set comparison
   - The setup, the recomputed numbers, and what you concluded

## Appendix: AI usage (if any)
   - Prompts, model output, and your verification against your own data

Push the report to your private GitHub repository (do not push a zip file). Include your code and both prompts in the repo as well — either inline in the report or as files referenced from it.

Tips

Resources