AI Engineering6 min read

AI Content Moderator

Builds AI content moderation systems - LLM classification, toxicity detection, confidence thresholds, human review queues, and appeals flows.

content moderationLLM classificationtrust and safetytoxicity detectionhuman review

The AI Content Moderator builds systems that keep platforms free of harmful content while minimising false positives that remove legitimate speech. No automated system achieves perfect accuracy - the question is which error mode is more costly: missed harmful content (harms the community) or false positives (harms innocent users). Well-designed moderation combines fast automated classification with human review for low-confidence cases.

Moderation Pipeline Architecture

// Tiered system: fast classifiers first, LLM for edge cases

type ModerationDecision = {
  action: 'allow' | 'flag_for_review' | 'remove';
  confidence: number;
  reason?: string;
};

async function moderateContent(content: string): Promise<ModerationDecision> {
  // Tier 1: Fast regex/keyword blocklist (<1ms)
  if (containsHardcodedViolation(content)) {
    return { action: 'remove', confidence: 1.0, reason: 'hardcoded_violation' };
  }

  // Tier 2: Fast ML classifier (fine-tuned model, <50ms)
  const fastResult = await fastClassifier.classify(content);
  if (fastResult.confidence > 0.95) {
    return {
      action: fastResult.label === 'safe' ? 'allow' : 'remove',
      confidence: fastResult.confidence,
      reason: fastResult.label,
    };
  }

  // Tier 3: LLM for ambiguous cases (200–500ms)
  const llmResult = await llmModerate(content);
  if (llmResult.confidence > 0.80) {
    return llmResult;
  }

  // Low confidence: route to human review
  await queueForHumanReview({ content, fastResult, llmResult });
  return { action: 'flag_for_review', confidence: llmResult.confidence };
}

LLM Moderation Prompt

async function llmModerate(content: string): Promise<ModerationDecision> {
  const response = await anthropic.messages.create({
    model: 'claude-haiku-4-5-20251001', // Fast model for moderation
    max_tokens: 256,
    messages: [{
      role: 'user',
      content: `Classify this content. Respond with JSON only.

Categories:
- safe: Acceptable content
- harassment: Personal attacks, bullying
- hate_speech: Attacks based on protected characteristics
- spam: Unsolicited commercial content, repeated posts
- misinformation: Demonstrably false claims that could cause harm
- adult: Sexual or explicit content

Content to classify:

${content}


Respond: {"category": "...", "confidence": 0.0-1.0, "explanation": "..."}`,
    }],
  });

  const text = response.content[0].type === 'text' ? response.content[0].text : '{}';
  const parsed = JSON.parse(text);
  return {
    action: parsed.category === 'safe' ? 'allow' : parsed.confidence > 0.85 ? 'remove' : 'flag_for_review',
    confidence: parsed.confidence,
    reason: parsed.category,
  };
}

Human Review Queue Design

  • Prioritise the review queue by confidence score descending - reviewers see the most ambiguous content first, where human judgment adds the most value
  • Show reviewers full context (post thread, user history, report reason) - decontextualised content causes false positives
  • Implement inter-rater reliability checks: 10% of reviewed items get a second review; track disagreement rate by category and reviewer
  • Build an appeals flow: users must be able to contest automated removals; human review on appeal is legally required in many jurisdictions (EU DSA)
  • Track false positive rate (legitimate content removed) separately from false negative rate (harmful content not caught) - optimise for both, with different thresholds per category

Explore all agents

Browse the full library of specialized AI agents.