← Blog

Claude API Content Moderation Workflow Guide

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

If you're searching for a Claude API content moderation workflow, you're probably trying to decide between building a classifier prompt yourself or wiring up something more structured — and you want to know how to handle edge cases without either over-blocking legitimate content or letting harmful content through. This article walks through a practical setup: a moderation prompt that returns structured JSON, a tiered escalation system, and how to wire it into a production pipeline with retries and logging.

Claude isn't a purpose-built moderation classifier like some dedicated APIs, but it's very good at nuanced judgment calls — sarcasm, context-dependent harassment, borderline self-harm language, mixed-language content — where keyword filters and small classifiers fail. The right workflow uses Claude for the judgment calls that need reasoning, and keeps cheap deterministic checks (regex, block lists) for the obvious cases, so you're not paying for a model call on every single message.

Why a single prompt isn't enough

A lot of "Claude moderation" code you'll find online is a single prompt asking "is this content safe, yes or no?" That works for demos and breaks in production for three reasons:

The fix is a structured moderation workflow with three layers: pre-filter, classification, and escalation.

Step 1: Pre-filter with cheap checks

Before calling the API at all, run deterministic checks: block lists, regex for known spam patterns, length limits. This cuts your API volume significantly — most user-generated content is fine and doesn't need an LLM call. Only content that passes the pre-filter (or trips a soft flag) goes to Claude.

Step 2: Classification prompt with structured output

Ask Claude to return a fixed JSON schema, not free text. This is the core of the workflow:

You are a content moderation classifier. Analyze the input and
respond with ONLY valid JSON matching this schema:

{
  "flagged": boolean,
  "categories": {
    "harassment": number,   // 0-1 confidence
    "violence": number,
    "self_harm": number,
    "sexual_content": number,
    "spam": number
  },
  "severity": "none" | "low" | "medium" | "high",
  "reasoning": string      // one sentence, for human reviewers
}

Content to analyze:
"""
{{user_content}}
"""

Calling it against the Claude API directly:

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 300,
    "messages": [{"role": "user", "content": "<moderation prompt here>"}]
  }'

The per-sentence reasoning field matters more than it looks. When a human reviewer eventually audits flagged content, a one-line explanation cuts review time dramatically compared to re-reading the raw content and guessing why the model flagged it.

Step 3: Severity-based routing

Once you have structured output, route based on severity and flagged:

| Severity | Action | |---|---| | none | Allow, log nothing extra | | low | Allow, log for trend analysis | | medium | Soft block + queue for human review | | high | Hard block + immediate escalation |

This tiering avoids the two failure modes that make moderation systems unpopular with users: blocking everything borderline (kills engagement) or blocking nothing until it's egregious (creates liability and trust problems).

Step 4: Handle parsing failures and retries

LLM output occasionally doesn't parse as valid JSON, especially under load or with unusual input. Your workflow needs a fallback:

async function classifyContent(text) {
  const response = await callClaude(moderationPrompt(text));
  try {
    return JSON.parse(response);
  } catch {
    // retry once with a stricter instruction, then fail-safe to "medium"
    const retry = await callClaude(moderationPrompt(text, { strict: true }));
    try {
      return JSON.parse(retry);
    } catch {
      return { flagged: true, severity: "medium", reasoning: "parse failure, needs manual review" };
    }
  }
}

Failing safe (flag for review rather than silently allow) on parse errors is the right default for moderation — the cost of an unnecessary human review is much lower than the cost of a missed violation.

Running this at scale

If you're building this inside a product — a marketplace, a community platform, a chat app — you'll want separate API keys per environment (staging vs. production), visibility into how many moderation calls you're burning through, and the ability to add teammates to a shared dashboard without passing around a single shared key. This is exactly the kind of workflow SubToAPI is built for: it turns your existing Claude access into an HTTPS API with application-scoped keys (sub_live_...), so your moderation service, your main app, and your internal admin tools each get their own key with their own usage metadata, under one account. You can see request volume per key, which is useful for catching a moderation loop or a sudden spike in flagged content before it becomes a billing surprise.

Set up a dedicated key just for the moderation pipeline:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 300,
    "messages": [{"role": "user", "content": "<moderation prompt here>"}]
  }'

Get started at /signup, check plan details at /pricing, and see request/response formats at /docs/messages.

Logging and audit trail

Whatever you flag, log the full structured output — not just the boolean — alongside the original content and a timestamp. This is what lets you retune the prompt later ("we're over-flagging sarcasm in the gaming community") and what you'll need if a moderation decision is ever disputed.

Questions

Does Claude replace a dedicated moderation API? Not entirely. Use cheap deterministic filters for obvious cases, and Claude for nuanced judgment calls where context and intent matter — that combination is more cost-effective than sending every message to an LLM.

How do I keep moderation output consistent across requests? Force structured JSON output with a fixed schema, give the model a confidence score per category rather than a single verdict, and always have a fail-safe default (like "medium severity") for parse failures.

Can I run moderation and my main app through the same API key? You can, but separate keys per service make usage tracking and incident response much easier — if the moderation pipeline spikes, you can see it immediately without digging through mixed logs. See /docs/quickstart for setting up multiple keys.

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 →