Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:A616567126 GPT WEB JAVA Content Moderation

From Leeroopedia
Knowledge Sources
Domains Security, NLP, Content_Safety
Last Updated 2026-10-13 00:00 GMT

Overview

Technique that evaluates user-submitted text against automated content moderation services to block prohibited content before processing.

Description

Content moderation is the process of screening user-generated input (prompts, messages) for prohibited, sensitive, or policy-violating content before forwarding it to AI services. This prevents the generation of harmful, illegal, or inappropriate outputs and protects the platform from abuse.

In this repository, text content moderation is performed using Baidu's Text Censor API (text_censor/v2/user_defined). All AI requests (GPT chat, MJ imagine, SD generation) pass through content moderation before being processed. Additionally, a translation service converts Chinese prompts to English for AI models that work best with English input.

Usage

Use this principle when:

  • Building platforms that accept user text input for AI generation
  • Complying with content safety regulations
  • Preventing prompt injection of prohibited content

Theoretical Basis

Two-Stage Moderation:

# Abstract algorithm (NOT real implementation)
def moderate_content(text):
    # Stage 1: External API moderation
    result = moderation_api.check(text)
    if result.contains("不合规"):  # "non-compliant"
        return False  # Block
    return True  # Allow

def translate_and_moderate(prompt):
    if not moderate_content(prompt):
        raise ContentViolationError()
    if contains_chinese(prompt):
        return translate_to_english(prompt)
    return prompt

Key Properties:

  • Pre-processing gate: Moderation runs before any AI API call
  • External service: Baidu API performs NLP-based classification
  • Access token caching: Baidu access token cached in Redis (29-day TTL)
  • Translation integration: Chinese-to-English translation via Baidu Translate API with MD5 signature verification

Practical Guide

The repository implements this in BaiduServiceImpl:

  1. textToExamine(prompt) — calls Baidu content moderation API, returns false if the response contains "不合规"
  2. translateToEnglish(prompt) — calls Baidu Translate API with MD5 signature, skips if no Chinese characters
  3. Access token is cached in Redis with a 29-day TTL to avoid repeated OAuth calls

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment