DEV Community

Cover image for How to Add Profanity Filtering to Your OpenClaw | Moltbot Clawdbot Agent
GDS K S
GDS K S

Posted on • Originally published at github.com

How to Add Profanity Filtering to Your OpenClaw | Moltbot Clawdbot Agent

Building an AI agent with OpenClaw (formerly Moltbot or Clawdbot)? Your users will send all kinds of messages—and some will contain profanity. You need to handle it before it reaches your AI and before it costs you money.

In this OpenClaw profanity filter tutorial, I'll show you how to integrate openclaw-profanity—a free, open-source content moderation plugin built specifically for OpenClaw, Moltbot, and Clawdbot agents. Works with WhatsApp bots, Telegram bots, Discord bots, and Slack bots.

TL;DR: Install with npm install openclaw-profanity, add one hook, and every message is filtered. No API costs. No latency. Skip to Quick Start

npm install openclaw-profanity
Enter fullscreen mode Exit fullscreen mode

Table of Contents


The Problem: AI-Based Profanity Checking Is Expensive

Your agent already uses GPT, Claude, or Gemini. Why not ask the AI to check for profanity?

Here's what that costs:

Messages/Day Monthly Cost (AI-only) With openclaw-profanity
500 $5-15 $0
1,000 $10-30 $0
5,000 $50-150 $0
10,000 $100-300 $0

That's just for profanity checking. Before your agent does anything useful.

The other problems with AI-only moderation:

Issue AI-Only openclaw-profanity
Latency 200-500ms per check < 1ms
Rate limits Traffic spikes fail No limits
Downtime API outage = bot down Always available
Consistency Results vary Deterministic
Cost scaling Linear increase Zero cost

Why openclaw-profanity?

We built openclaw-profanity because every other solution either:

  • Fails basic evasion tactics (leetspeak, Unicode tricks)
  • Requires expensive API calls
  • Lacks proper OpenClaw integration
  • Only supports English

What makes openclaw-profanity different:

1. Catches What Others Miss

Most profanity filters fail against basic evasion tactics. Users type f*ck or sh1t and walk right through.

Evasion Method Example Other Filters openclaw-profanity
Leetspeak f4ck, sh1t, @ss
Unicode substitution fսck (Cyrillic у)
Character spacing f u c k
Symbols f*ck, f@ck, $hit
Mixed case FuCk, sHiT
Repeated chars fuuuuck, shiiit

2. True Multilingual Support

24 languages built-in: English, Spanish, French, German, Portuguese, Italian, Dutch, Russian, Chinese, Japanese, Korean, Arabic, Hindi, Turkish, Polish, Vietnamese, Thai, Swedish, Norwegian, Danish, Finnish, Czech, Hungarian, Greek

Not just word lists—actual linguistic patterns for each language.

3. Native OpenClaw Integration

Built FOR OpenClaw, not adapted to it. First-class support for:

  • Hooks - Automatic message filtering
  • Skills - Callable actions for your agent
  • Direct API - Full control when you need it

4. Zero Dependencies (Almost)

One dependency: glin-profanity (our core library). No network calls. No external services. Everything runs locally on your server.


Integration Guide for OpenClaw

Option 1: Profanity Guard Hook (Recommended)

The simplest integration. Add one hook and every message is automatically filtered.

import { OpenClawAgent } from "openclaw";
import { profanityGuardHook } from "openclaw-profanity/hooks";

const agent = new OpenClawAgent({
  // your config
});

// Add the profanity guard - that's it!
agent.useHook(profanityGuardHook({
  action: "censor",           // "censor" or "block"
  languages: ["en", "es"],    // languages to check
  replacement: "***",         // censorship character
  onViolation: (msg, result) => {
    console.log(`Filtered: ${result.profaneWords.join(", ")}`);
  }
}));

agent.start();
Enter fullscreen mode Exit fullscreen mode

Actions:

  • action: "censor" - Replaces profanity with *** and continues processing
  • action: "block" - Stops the message entirely, sends warning to user

That's 3 lines of code for complete profanity protection.

Option 2: Custom Skill

Create a reusable skill your agent can call programmatically.

import { defineSkill } from "openclaw";
import { checkProfanity, censorText } from "openclaw-profanity/skills";

export const moderationSkill = defineSkill({
  name: "content-moderation",
  description: "Check and filter profanity from user messages",

  actions: {
    check: {
      description: "Check text for profanity",
      parameters: {
        text: { type: "string", required: true }
      },
      handler: async ({ text }) => {
        const result = checkProfanity(text);
        return {
          containsProfanity: result.containsProfanity,
          profaneWords: result.profaneWords,
          confidence: result.confidence
        };
      }
    },

    censor: {
      description: "Censor profanity in text",
      parameters: {
        text: { type: "string", required: true }
      },
      handler: async ({ text }) => {
        const result = censorText(text);
        return {
          original: result.originalText,
          censored: result.processedText,
          wordsCensored: result.censoredWords
        };
      }
    }
  }
});
Enter fullscreen mode Exit fullscreen mode

Register it:

import { moderationSkill } from "./skills/moderation";

agent.useSkill(moderationSkill);
Enter fullscreen mode Exit fullscreen mode

Option 3: Direct Integration

For full control, use the library directly in your message handler.

import { checkProfanity, censorText } from "openclaw-profanity";

async function handleIncomingMessage(message, context) {
  // Step 1: Check for profanity (< 1ms)
  const check = checkProfanity(message.text, {
    languages: ["en", "es", "fr"],
    detectLeetspeak: true,
    detectUnicode: true
  });

  // Step 2: Handle based on result
  if (check.containsProfanity) {
    if (check.confidence > 0.9) {
      // High confidence - block immediately
      return context.reply(
        "Please keep the conversation respectful."
      );
    }

    // Medium confidence - censor and continue
    const censored = censorText(message.text);
    message.text = censored.processedText;
  }

  // Step 3: Continue to AI processing
  return context.next(message);
}
Enter fullscreen mode Exit fullscreen mode

Platform-Specific Examples

WhatsApp Bot (with OpenClaw)

import { WhatsAppAdapter } from "openclaw/adapters/whatsapp";
import { profanityGuardHook } from "openclaw-profanity/hooks";

const agent = new OpenClawAgent({
  adapter: new WhatsAppAdapter({
    // WhatsApp config
  })
});

agent.useHook(profanityGuardHook({
  action: "censor",
  languages: ["en", "es", "pt"],  // English, Spanish, Portuguese
  onViolation: (msg, result) => {
    // Log for moderation dashboard
    logViolation(msg.from, result);
  }
}));
Enter fullscreen mode Exit fullscreen mode

Telegram Bot

import { TelegramAdapter } from "openclaw/adapters/telegram";
import { profanityGuardHook } from "openclaw-profanity/hooks";

const agent = new OpenClawAgent({
  adapter: new TelegramAdapter({
    token: process.env.TELEGRAM_BOT_TOKEN
  })
});

agent.useHook(profanityGuardHook({
  action: "block",
  warningMessage: "Please keep the chat friendly!"
}));
Enter fullscreen mode Exit fullscreen mode

Discord Bot

import { DiscordAdapter } from "openclaw/adapters/discord";
import { profanityGuardHook } from "openclaw-profanity/hooks";

const agent = new OpenClawAgent({
  adapter: new DiscordAdapter({
    token: process.env.DISCORD_BOT_TOKEN
  })
});

agent.useHook(profanityGuardHook({
  action: "censor",
  // Discord-specific: delete original and repost censored
  onViolation: async (msg, result, context) => {
    await msg.delete();
    await context.reply(`${msg.author}: ${result.censoredText}`);
  }
}));
Enter fullscreen mode Exit fullscreen mode

Slack Bot

import { SlackAdapter } from "openclaw/adapters/slack";
import { profanityGuardHook } from "openclaw-profanity/hooks";

const agent = new OpenClawAgent({
  adapter: new SlackAdapter({
    token: process.env.SLACK_BOT_TOKEN
  })
});

agent.useHook(profanityGuardHook({
  action: "censor",
  onViolation: async (msg, result) => {
    // Notify workspace admins
    await notifyAdmins(msg.channel, result);
  }
}));
Enter fullscreen mode Exit fullscreen mode

Advanced: Hybrid AI + Local Filtering

The smart approach: Use local filtering for speed, escalate edge cases to AI.

import { checkProfanity } from "openclaw-profanity";

async function smartModeration(message, agent) {
  // Fast local check (< 1ms)
  const localCheck = checkProfanity(message.text);

  if (!localCheck.containsProfanity) {
    // Clean - proceed immediately
    return { action: "allow" };
  }

  if (localCheck.confidence > 0.95) {
    // Definitely profane - block without AI call
    return { action: "block" };
  }

  // Uncertain - ask AI for context analysis (rare)
  const aiAnalysis = await agent.analyze({
    prompt: `Is this message inappropriate? Consider context and intent: "${message.text}"`,
    format: "json"
  });

  return aiAnalysis.inappropriate
    ? { action: "block" }
    : { action: "allow" };
}
Enter fullscreen mode Exit fullscreen mode

Result:

  • 95% of messages handled instantly (free, <1ms)
  • 5% escalated to AI (only when genuinely ambiguous)
  • 90%+ cost reduction vs AI-only approach

This is how production systems should work—fast local decisions, AI only when necessary.


Configuration Options

import { Filter } from "openclaw-profanity";

const filter = new Filter({
  // Languages to check (default: all 24)
  languages: ["en", "es", "fr"],

  // Detection options
  detectLeetspeak: true,      // f4ck, sh1t
  detectUnicode: true,        // Cyrillic/Greek substitutions
  detectSpacing: true,        // f u c k

  // Censorship options
  replaceWith: "*",           // Replacement character
  preserveLength: true,       // **** vs ***

  // Whitelist (words to ignore)
  whitelist: ["assistant", "class"],

  // Custom words to add
  customWords: ["badword1", "badword2"]
});
Enter fullscreen mode Exit fullscreen mode

Quick Start

1. Install:

npm install openclaw-profanity
Enter fullscreen mode Exit fullscreen mode

2. Add hook to your agent:

import { profanityGuardHook } from "openclaw-profanity/hooks";

agent.useHook(profanityGuardHook({
  action: "censor"
}));
Enter fullscreen mode Exit fullscreen mode

3. Done. Every message is now filtered.

Total setup time: Under 2 minutes.


FAQ

Does this replace my AI moderation completely?

It can, but we recommend the hybrid approach. Use openclaw-profanity for the 95% of cases that are clear-cut, and let your AI handle the ambiguous 5% that need context understanding.

Will it slow down my bot?

No. Response time is under 1 millisecond. That's 200-500x faster than an API call.

What about false positives?

The library includes smart word boundaries and context detection. "Scunthorpe" won't be flagged. You can also add whitelists for domain-specific terms.

Can I add custom words?

Yes. Add any custom words to your filter configuration. They'll inherit all the evasion detection (leetspeak, Unicode, etc.) automatically.

Does it work with Moltbot/Clawdbot?

Yes! OpenClaw is the current name for the framework formerly known as Moltbot and Clawdbot. The integration works the same way.

Is it production-ready?

Yes. The core library (glin-profanity) is battle-tested and handles edge cases like Unicode normalization, boundary detection, and performance optimization.


Why Developers Choose openclaw-profanity

  • Zero cost - No API fees, runs entirely local
  • Sub-millisecond - Faster than any cloud solution
  • 24 languages - True multilingual support
  • Evasion-proof - Catches leetspeak, Unicode tricks, and more
  • Native OpenClaw - Built for your stack
  • MIT licensed - Use it anywhere, modify as needed

Links & Resources


Part of the glin-profanity Ecosystem

openclaw-profanity is built on glin-profanity, which also powers:

Same core engine. Same detection quality. Different integrations for different needs.


Get Started Now

npm install openclaw-profanity
Enter fullscreen mode Exit fullscreen mode

Your bot deserves better than paying $100+/month for profanity checking. Add one line of code and solve it forever.

Questions? Drop a comment below or open an issue on GitHub.

What messaging platform are you building for? I'd love to hear about your use case!


Summary

openclaw-profanity is a free, open-source profanity filter plugin for OpenClaw, Moltbot, and Clawdbot AI agents. Key features:

  • Zero cost - No API calls, runs locally
  • Sub-millisecond performance - 200-500x faster than AI moderation
  • 24 languages - Full multilingual support
  • Evasion detection - Catches leetspeak, Unicode tricks, character spacing
  • Easy integration - Hooks, Skills, or Direct API
  • Platform support - WhatsApp, Telegram, Discord, Slack

Install now: npm install openclaw-profanity


Keywords: openclaw profanity filter, moltbot content moderation, clawdbot profanity detection, whatsapp bot profanity filter nodejs, telegram bot content moderation, discord bot profanity filter, ai agent content safety, best profanity filter npm 2026, chatbot moderation javascript, openclaw plugin, moltbot skill, clawdbot skill

Top comments (0)