Guide

Profanity Filter vs Content Moderation API: When a Word List Stops Working

·10 min read

If you searched npm for "bad words" or "profanity filter", you probably need to stop users posting something. A word list is the obvious first tool. It is free, it runs locally, and it takes ten minutes to add.

For some inputs it is the right tool. For open text it breaks in ways that are easy to predict and annoying to discover in production. This article shows both sides, with live scores from the Vettly API for the cases where a list fails, and a hybrid pattern that keeps the list where it still helps.

When a word list is fine

A word list works well when the input is short and the vocabulary is narrow:

  • Usernames and display names. You want to stop a handful of slurs and obvious obscenities in a 20-character field. Context barely exists.
  • Product or channel names you control. You are checking against a known set of strings, not judging intent.
  • Terms that only matter to you. Competitor names, internal codenames, a scam domain that keeps showing up. No general model knows these are a problem for your app.
  • Prototypes. You need something in place before launch, and you will revisit it.

A minimal version looks like this:

word-filter.tsTypeScript
const BANNED = ['badword1', 'badword2', 'slur1'];
// Word boundaries avoid matching inside longer words
const pattern = new RegExp('\\b(' + BANNED.join('|') + ')\\b', 'i');
export function containsBannedWord(text: string): boolean {
return pattern.test(text);
}

Note the word boundaries. Many quick implementations use text.toLowerCase().includes(word) instead, and that is where the first problem comes from.

Where word lists break

The Scunthorpe problem

Substring matching flags innocent words that contain a banned string. The classic example is the English town of Scunthorpe, but ordinary words do it too: "assassin", "cocktail", "class", "Sussex". A football fan posting a match result, or a gamer posting a review, gets blocked.

Word-boundary regexes fix the substring case. They do not fix the next four.

Obfuscation

Users who want to get past a filter will. "f*cking", "1d10t", "stup1d", spaces between letters, Cyrillic look-alike characters, emoji in place of letters. Each workaround needs a new list entry or a normalisation rule, and each normalisation rule creates new false positives. You end up maintaining a growing list of regexes that nobody wants to touch.

No context

A list treats every match the same. "This update is fucking amazing" and a profane insult aimed at another user both contain the same word. In most communities the first is fine and the second is the one you care about. A list cannot tell them apart, so you either block praise or allow abuse.

Harmful content with no profanity

This is the biggest gap. Much of the content that actually hurts users contains no swear words at all:

  • Harassment: "nobody here wants you, just leave" is clean vocabulary.
  • Scams: a phishing message is polite by design. It thanks you for your understanding.
  • Grooming: messages that try to isolate a child ("this can be our secret") are friendly in tone.
  • Threats are often written in plain words.

A profanity filter passes all of these, because there is nothing for it to match.

Other languages

A list in English catches nothing in Portuguese, Russian, or Arabizi. Each language needs its own list, its own spelling variants, and someone who speaks it. We covered this in detail in Multilingual Content Moderation.

Live scores for the cases a list gets wrong

We sent the strings below to Vettly's POST /v1/check/fast endpoint on 2026-11-23, using the demo policy the playground uses for signed-out visitors. Scores come from the response's signals field, rounded to two decimals. Each row is a single call.

The demo policy only has rules for hate speech, harassment, violence, self-harm, and sexual content. It has no profanity or scam rule, which is why some rows show allow despite a high score. The next section shows a policy that acts on those signals.

MessageWhat a word list doesVettly signalsDemo action
Scunthorpe United drew 1-1 at home on Saturday.Substring match: false positiveall signals 0.02 or lowerallow
Just finished my Assassin's Creed review, the cocktail of stealth and parkour still works.Substring match: false positive (twice)all signals 0.04 or lowerallow
This update is fucking amazing, best patch all year.Blocks praiseprofanity 0.91, harassment 0.02allow (no profanity rule)
you are a stup1d f*cking 1d10tMisses unless every variant is listedprofanity 0.94, harassment 0.90flag
Hi! I'm from the support team. Your account will be suspended today unless you verify your payment details at the link below. Thank you for your understanding.Passes: no profanityscam 0.98, harassment 0.51, spam 0.27allow (no scam rule)
you seem really mature for your age. this can be our little secret, don't tell your parents ok?Passes: no profanityminor_context 0.86, sexual_solicitation 0.21, harassment 0.15allow

The first two rows are the Scunthorpe cases. The model scored both as clean, because it reads the sentence rather than scanning for substrings.

Rows three and four use the same swear word. The praise scored 0.02 on harassment, and the insult scored 0.90. Profanity scored high in both (0.91 and 0.94), which is accurate: both contain strong language. The difference that matters is in the harassment signal, which a word list does not have. The obfuscated spelling in row four did not hide anything.

Row five is the polite phishing message. It scored 0.98 on scam. It also scored 0.51 on harassment, which is a misfiled co-signal: the message is a scam, not harassment. Your policy should key on scam here, not on harassment.

Row six is the hardest case, and the honest result is that no category crossed a threshold. The model's minor_context signal was high (0.86), but sexual_solicitation was only 0.21 and sexual was 0.09. A clean grooming opener like this one is hard for any text-only check, and minor context alone is not enough to act on (a benign message about school scored 0.77 in our multilingual tests). For apps used by minors, treat this kind of message as a reason for conversation-level review and user reporting, not something a single message check will reliably catch.

Profanity is one signal, not the whole policy

Every Vettly text check scores eleven signals: nine categories (hate_speech, harassment, violence, self_harm, sexual, spam, profanity, scam, illegal) plus two context signals (minor_context, sexual_solicitation). The profanity score is there if you want it. The point is that you no longer have to use it as a stand-in for "is this harmful".

A policy decides what each signal means for your app. For a gaming chat that tolerates swearing but not abuse:

gaming-chat.yamlYAML
name: gaming-chat
version: "1"
rules:
- category: harassment
threshold: 0.85
provider: jev
action: block
bands:
- gte: 0.6
action: flag
- category: profanity
threshold: 0.8
provider: jev
action: warn
- category: scam
threshold: 0.9
provider: jev
action: block
- category: hate_speech
threshold: 0.6
provider: jev
action: block

We replayed the captured signals from the table through this policy with the dry-run endpoint:

  • "This update is fucking amazing" returned warn (profanity 0.91, nothing else triggered).
  • "you are a stup1d f*cking 1d10t" returned block (harassment 0.90 above 0.85).
  • The polite phishing message returned block (scam 0.98 above 0.9).

warn is useful for profanity. You can show the message with a blur, or let the community setting decide, instead of deleting a compliment. A kids' app would instead set profanity to block at a lower threshold. Same signals, different policy.

You can test a policy like this without saving it. Run a message through check once to capture its signals, then dryRun evaluates inline YAML against those signals without another model call:

try-policy.tsTypeScript
import { readFileSync } from 'node:fs';
import { createClient } from '@vettly/sdk';
const vettly = createClient(process.env.VETTLY_API_KEY!);
const yaml = readFileSync('./policies/gaming-chat.yaml', 'utf8');
const live = await vettly.check({
content: 'This update is fucking amazing, best patch all year.',
contentType: 'text',
policyId: 'demo',
});
const replay = await vettly.dryRun('gaming-chat', undefined, live.signals, yaml);
console.log(replay.evaluation.action); // 'warn'

The REST reference documents the same mockSignals and policy fields for other languages.

The hybrid: a local list first, the API for the rest

You do not have to choose. The pattern we recommend keeps a small local list for the terms that only your app cares about, and sends everything else to the API.

Vettly policies are built from the scored signals and do not take a custom word list, so the list lives in your code. That is also the cheapest place for it: an exact match costs nothing and needs no network call.

moderate.tsTypeScript
import { createClient, VettlyError } from '@vettly/sdk';
const vettly = createClient(process.env.VETTLY_API_KEY!, { timeout: 2000 });
// Terms only your app cares about. Keep it short.
const LOCAL_BLOCK = [
/\bcompetitor-app\.example\b/i, // spam domain that keeps appearing
/\bproject-falcon\b/i, // internal codename
];
type Verdict = { action: 'allow' | 'warn' | 'flag' | 'block'; source: 'local' | 'vettly' | 'error' };
export async function moderate(text: string): Promise<Verdict> {
// 1. Cheap local check: no network, no quota
if (LOCAL_BLOCK.some((re) => re.test(text))) {
return { action: 'block', source: 'local' };
}
// 2. Everything else: context, obfuscation, scams, other languages
try {
const result = await vettly.checkFast({
content: text,
contentType: 'text',
policyId: 'gaming-chat',
});
return { action: result.action, source: 'vettly' };
} catch (err) {
if (err instanceof VettlyError) {
console.error('moderation failed', err.code, err.statusCode);
}
// Decide deliberately: queue for review rather than silently publish
return { action: 'flag', source: 'error' };
}
}

A few notes on this pattern:

  • Keep the local list for exact strings. Domains, usernames, codenames. If you find yourself adding spelling variants of insults to it, that work belongs to the API.
  • Do not put general profanity in the local list. If you do, you are back to blocking "Scunthorpe United" and "fucking amazing" before the API ever sees them.
  • Decide what happens when the API fails. The example flags the message for review. A live chat might prefer to allow and re-check later. Either is fine, as long as it is a choice. The SDK throws typed errors (VettlyAuthError, VettlyRateLimitError, VettlyQuotaError, all extending VettlyError) so you can tell an expired key from a quota limit.
  • Store the decision ID. Check responses include a decisionId that links to the policy version and scores behind the action, which helps when a user appeals.

Migrating from a bad-words package without surprises

If you already run a word list in production, do not swap it out in one deploy. Run both side by side for a week and look at where they disagree.

  1. Keep your current filter as the decision. Nothing changes for users yet.
  2. Call the API in the background on the same messages and log the action next to your filter's result. Use the policy you plan to ship, not the demo one.
  3. Sort the disagreements into two piles. Messages your list blocked and the API allowed are usually Scunthorpe cases and harmless swearing. Messages your list allowed and the API flagged or blocked are usually the harassment, scams, and obfuscated insults the list was missing.
  4. Read a sample of each pile. If the API is wrong on a pattern that matters to you, adjust the threshold for that category, or add a band so that range goes to review. Replay the logged signals through dryRun to check the change before you deploy it.
  5. Switch the decision over, and shrink the local list to the app-specific terms described above.

Expect two things from this exercise. Many of the false positives users complain about will be substring matches and swearing used as praise. And the list is likely letting through more than you thought, mostly abuse and scams written in clean vocabulary.

On latency: the server-reported latency for the fast-path checks in the table above was between 33 and 58 ms per message. That is fast enough to run before a chat message is shown, but it is still a network call, which is another reason to keep exact-match terms local.

Choosing between them

Use only a word list when the field is short, the vocabulary is narrow, and a false positive costs little: usernames, team names, tags.

Use a moderation API when users write freely to each other: chat, comments, DMs, reviews, listings. That is where harassment without swear words, scams, obfuscation, and other languages show up, and where blocking praise annoys your best users.

Use both when you have app-specific terms the API cannot know about. The local list handles those in microseconds, and the API handles everything that needs reading.

Where to go next

  • Paste any of the strings above into the playground to see the action and category scores for yourself. Signed-out visitors get the same demo policy used here.
  • Read the policy guide for thresholds, bands, and compound conditions.
  • Start with the getting started guide and the SDK reference.
  • Weighing a build-it-yourself filter against an API? See Vettly vs in-house moderation.
  • The free tier includes 15,000 text checks a month with no credit card. See pricing.

Frequently asked questions

Is a profanity filter enough for user-generated content?

It can be for narrow inputs such as usernames or display names where you control the vocabulary. For open text like chat, comments, or DMs, a word list misses obfuscated insults, harassment without swear words, scams, and other languages, and it blocks innocent words that contain a listed string.

What is the Scunthorpe problem?

It is the false positive you get when a filter matches a banned string inside an innocent word, such as the town of Scunthorpe or words like cocktail and assassin. Word-boundary matching fixes the substring case but not obfuscation or context.

Does Vettly have a profanity score?

Yes. profanity is one of the eleven signals scored on every text check, alongside harassment, hate_speech, scam, and the others. Your policy decides what to do with it, so you can warn on profanity while blocking harassment.

Can I add my own banned words to a Vettly policy?

Vettly policies are built from the scored signals and do not take a word list. For terms only your app cares about, such as competitor names or banned usernames, keep a small local list and check it before calling the API, as shown in the hybrid pattern in this article.

How much does it cost to try?

The free tier includes 15,000 text checks per month with no credit card required. Paid plans add volume and are listed on the pricing page.