Profanity Filter API: The Complete Guide

Need to keep user-generated content clean? This guide covers everything you need to know about profanity filtering via API, including detection modes, censoring options, and implementation examples.

What is a Profanity Filter?

A profanity filter is a content moderation tool that detects and handles inappropriate language in text. It can identify profane words, slurs, and offensive content, then either flag, censor, or block the content based on your requirements.

Modern filters handle common obfuscation attempts like "sh1t" or "f u c k" and work across multiple languages.

Filter Modes

Profanity filters typically offer several operation modes:

Mode Description Output Example
DetectCheck if profanity existstrue/false
CensorReplace with asterisks"What the ****!"
ReplaceReplace with safe word"What the heck!"
HighlightMark profane words"What the [damn]!"
Pro Tip: Configure your filter strictness based on context. A children's app needs stricter filtering than an adult community.

Using the Profanity Filter API

TinyFn provides an endpoint to filter profanity:

API Request
POST https://api.tinyfn.io/v1/filter/profanity
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "text": "This is some text that might contain bad words.",
  "mode": "censor",
  "censor_char": "*"
}
Response
{
  "original": "This is some text that might contain bad words.",
  "filtered": "This is some text that might contain *** words.",
  "contains_profanity": true,
  "profanity_count": 1,
  "matches": [
    {"word": "bad", "start": 38, "end": 41, "severity": "mild"}
  ]
}

Parameters

Parameter Type Description
text string Text to filter (required)
mode string Operation mode: detect, censor, replace (default: detect)
censor_char string Character for censoring (default: *)
strictness string Filter level: mild, moderate, strict (default: moderate)

Code Examples

JavaScript / Node.js

const response = await fetch('https://api.tinyfn.io/v1/filter/profanity', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your-api-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    text: userComment,
    mode: 'censor',
    strictness: 'moderate'
  })
});
const data = await response.json();

if (data.contains_profanity) {
  // Use censored version
  displayComment(data.filtered);
} else {
  displayComment(data.original);
}

Python

import requests

def filter_profanity(text, mode='censor'):
    response = requests.post(
        'https://api.tinyfn.io/v1/filter/profanity',
        json={'text': text, 'mode': mode},
        headers={'X-API-Key': 'your-api-key'}
    )
    return response.json()

# Check user submission
result = filter_profanity(user_input)
if result['contains_profanity']:
    print("Content flagged for review")
else:
    save_content(user_input)

cURL

curl -X POST "https://api.tinyfn.io/v1/filter/profanity" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "Check this text", "mode": "detect"}'

Common Use Cases

  • User Comments: Filter profanity in blog comments and forums
  • Chat Applications: Real-time filtering in messaging apps
  • User Profiles: Clean usernames and bios
  • Reviews: Moderate product and service reviews
  • Gaming: Filter in-game chat and player names

Best Practices

  1. Adjust strictness: Match filter strictness to your audience
  2. Allow appeals: Provide a way to contest false positives
  3. Log matches: Keep records for review and improvement
  4. Consider context: Some words are profane only in certain contexts

Try the Profanity Filter API

Get your free API key and start filtering content in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key