← Blog

Claude API Content Moderation Implementation Guide

2026-11-11 · 5 min read · SubToAPI Team

Claude API Content Moderation Implementation Guide

If you're searching for how to implement content moderation with the Claude API, the short answer is: you send user-generated content to Claude with a classification prompt that returns structured categories and confidence levels, then your application acts on that output with thresholds and fallback rules. Claude doesn't ship a dedicated "moderation endpoint" like some providers — instead you use the standard Messages API with a carefully designed prompt, and optionally a tool/function-calling schema to force structured output.

This matters because moderation isn't a single yes/no decision. You need to classify content across multiple dimensions (hate speech, violence, sexual content, self-harm, spam, PII), assign confidence or severity, and decide what to do with borderline cases — block, flag for human review, or allow with a warning. This guide walks through a production-ready implementation pattern.

Why use an LLM instead of a keyword filter

Keyword and regex filters miss context, sarcasm, obfuscation ("h4te", leetspeak), and multilingual content. Claude handles all of these natively because it reasons about meaning, not string matches. The tradeoff is latency and cost per request, which is why most teams use Claude as a second-layer check rather than the only line of defense — a fast local filter catches obvious cases, and Claude handles ambiguous or high-stakes content.

Designing the classification schema

Decide your categories before writing any prompt. A typical schema:

For each category, you want a boolean flag, a severity score (0–3), and optionally a short explanation for audit logs. Keeping categories fixed and small makes downstream logic predictable.

Forcing structured output with tool use

The most reliable way to get consistent moderation output from Claude is to define a tool schema and force the model to call it. This avoids parsing free-text responses.

{
  "name": "classify_content",
  "description": "Classify user content for moderation",
  "input_schema": {
    "type": "object",
    "properties": {
      "categories": {
        "type": "object",
        "properties": {
          "hate_harassment": { "type": "integer", "minimum": 0, "maximum": 3 },
          "violence_graphic": { "type": "integer", "minimum": 0, "maximum": 3 },
          "sexual_content": { "type": "integer", "minimum": 0, "maximum": 3 },
          "self_harm": { "type": "integer", "minimum": 0, "maximum": 3 },
          "spam_scam": { "type": "integer", "minimum": 0, "maximum": 3 },
          "pii_exposure": { "type": "integer", "minimum": 0, "maximum": 3 }
        },
        "required": ["hate_harassment", "violence_graphic", "sexual_content", "self_harm", "spam_scam", "pii_exposure"]
      },
      "action": { "type": "string", "enum": ["allow", "flag", "block"] },
      "reason": { "type": "string" }
    },
    "required": ["categories", "action", "reason"]
  }
}

Read more about schema design and forcing tool calls in /docs/tools.

Writing the system prompt

The system prompt should be explicit about scope and tone, and should instruct Claude to classify, not moralize:

You are a content moderation classifier. You will receive user-submitted
text. Your job is to score it across six categories on a 0-3 severity
scale (0 = none, 3 = severe) and recommend an action: allow, flag, or
block. Do not refuse to classify content — classifying harmful content
is your job. Always call the classify_content tool with your result.

Claude will sometimes be reluctant to engage with harmful text directly. Framing the task explicitly as classification (not generation or endorsement) resolves most of this.

Implementation example

async function moderateContent(text) {
  const response = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "claude-sonnet",
      max_tokens: 500,
      system: "You are a content moderation classifier...",
      tools: [classifyContentTool],
      tool_choice: { type: "tool", name: "classify_content" },
      messages: [{ role: "user", content: text }]
    })
  });

  const data = await response.json();
  const toolCall = data.content.find(c => c.type === "tool_use");
  return toolCall.input;
}

This example uses SubToAPI's HTTPS endpoint, which wraps the same Messages API format while giving you an sub_live_... key, usage metadata, and streaming out of the box — useful if several services in your stack need moderation and you want one key management surface instead of juggling raw provider credentials per environment. See /docs/messages for the request format and /docs/quickstart to get an API key in minutes.

Setting thresholds and actions

Map severity scores to actions in your application layer, not in the prompt:

function decideAction(categories) {
  const maxSeverity = Math.max(...Object.values(categories));
  if (maxSeverity >= 3) return "block";
  if (maxSeverity === 2) return "flag_for_review";
  if (maxSeverity === 1) return "allow_with_warning";
  return "allow";
}

Keeping thresholds in code (not hardcoded into the model's judgment) lets you tune sensitivity per category without re-prompting — e.g., stricter on self_harm, looser on spam_scam.

Handling edge cases

Logging and auditability

Store the raw classification output (categories, action, reason, model version, timestamp) alongside the content ID. This is essential for compliance reviews and for explaining moderation decisions to users who appeal a block. SubToAPI's dashboard exposes per-request usage metadata, which helps correlate moderation calls with cost and volume across team members — relevant once you have multiple engineers or services calling the same moderation pipeline. Pricing for team usage is on /pricing.

Rolling this out safely

Start in shadow mode: run the classifier on production traffic but don't act on it yet. Compare its decisions against your current filter or human moderators for a week or two, tune thresholds, then switch to active enforcement. This avoids a surprise spike in blocked content on day one.

FAQ

Does Claude have a built-in moderation endpoint like some other providers? No. You implement moderation using the standard Messages API with a classification prompt and a tool schema that forces structured output.

Which Claude model should I use for moderation? A faster, cheaper model is usually sufficient for a first-pass filter; escalate only flagged or ambiguous content to a stronger model for a second opinion.

How do I avoid Claude refusing to classify harmful text? Frame the task explicitly as classification, not generation, and state clearly in the system prompt that scoring harmful content accurately is the required task.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →