Open-source, self-hostable toxic comment moderation API + Chrome extension.
Multi-label toxicity detection with anti-evasion. Drop-in Perspective API replacement.
No paid SaaS, no data leaving your servers.
Google is sunsetting the Perspective API, leaving developers without a reliable, privacy-focused way to moderate text. CommentGuard is a fast, 1:1 drop-in replacement built from the ground up. It uses a custom anti-evasion engine and a Deep Learning Transformer model to locally detect 6 categories of toxicity. 100% open-source, and your data never leaves your servers.
- Features
- Performance & Benchmarks
- Quick Start
- Developer SDK & Integrations
- Live Dashboard
- Chrome Extension
- Perspective API Migration
- API Reference
- π·οΈ Multi-label classification β 6 toxicity categories:
toxic,severe_toxic,obscene,threat,insult,identity_hate - β‘ FastAPI backend β
POST /moderateclassifies text in < 50ms (classical) or ~150ms (transformer) - π‘οΈ Anti-evasion β defeats leetspeak (
h4t3), Unicode tricks, zero-width chars, separator evasion (k.i.l.l) - π Perspective API compatible β drop-in replacement endpoint (
POST /v1/comments:analyze) - π¦ Batch API β moderate up to 100 texts in a single request
- π§ Swappable models β TF-IDF + Logistic Regression or
unitary/toxic-bertviaMODEL_TYPEenv var - π Live Dashboard β beautiful React/Vite analytics dashboard to visualize the moderation stream
- π§© Chrome extension β live-filters 9 sites: YouTube, Reddit, HN, Twitter/X, Discord, Twitch, Facebook, Instagram
- π Live analytics β
/statsendpoint with per-category toxicity breakdown - π Feedback loop β users can report false positives; data is logged for retraining
- π Drop-in integration β Node.js, Django, Laravel, Next.js examples included
- π³ Docker-ready β
docker compose upand you're live - π Privacy-first β runs 100% on your own infrastructure
To ensure zero bias, we tested a random sample of 500 comments from the Kaggle Toxic Comment Classification dataset (comments the model has never seen).
| Metric | CommentGuard v3.0 | Google Perspective (Published) |
|---|---|---|
| Accuracy | 94.6% | ~92.1% |
| Recall (Catch Rate) | 93.3% | ~87.2% |
| F1 Score | 75.7% | ~88.3% |
| Avg Latency | 50ms | ~200-400ms (Cloud Roundtrip) |
| Privacy | β 100% Local | β Sends data to Google |
In addition to the random benchmark, we performed a hand-picked "Stress Test" on 40 tricky comments (leetspeak, Unicode obfuscation, and subtle slang) to verify our Anti-Evasion engine.
- SAMPLES.md: View the results of our hand-picked 40-item Stress Test.
- KAGGLE_SAMPLES.md: View the first 50 comments from the Unbiased 500-comment Benchmark.
- benchmark.py: The script used to calculate these metrics.
CommentGuard is tuned to be highly protective by default. You can adjust the sensitivity in your .env file to match your community's needs:
| Use Case | Threshold | Philosophy | Result |
|---|---|---|---|
| The Shield | 0.50 (Default) |
Catch everything. Safety first. | Max Recall (93%). Highest security. |
| The Balanced | 0.65 |
Best overall balance. | Optimal F1 Score (80%). Fewer false flags. |
| The Minimalist | 0.85 |
Stay out of the way. | Highest Precision. Only blocks extreme toxicity. |
graph TD
A[Browser Extension] -->|POST /moderate| B(FastAPI Backend)
C[Node.js SDK Apps] -->|POST /moderate| B
D[Legacy Perspective Apps] -->|POST /v1/comments:analyze| B
B --> E{Anti-Evasion Preprocessor}
E --> F[Transformer Neural Net]
F -->|6-Category Scores| B
B -->|Logs & Stats| G[(In-Memory Analytics)]
H[React Dashboard] -->|GET /stats| G
Before running the project, make sure you have the following installed on your machine:
- Python 3.10+ (For the AI Backend)
- Node.js & npm (For the React Dashboard and SDK)
We wrote a startup script that automatically boots up both the AI Backend and the React Dashboard for you.
# Clone the repository
git clone https://github.com/init-krish/commentguard
cd commentguard
# On Mac/Linux:
./start.sh
# On Windows:
start.batBoth the API (localhost:8000) and the Dashboard (localhost:3000) will instantly go live.
-d '{"text": "I hate you so much"}'
### Option B β Docker
```bash
cd commentguard/backend
cp .env.example .env
docker compose up -d
```bash
curl http://localhost:8000/health
CommentGuard comes with a beautiful, real-time React dashboard to monitor toxicity rates and view live moderation logs.
cd dashboard
npm install
npm run devNavigate to http://localhost:3000 to see your AI in action.
Integrating CommentGuard into your application is incredibly simple. We offer an official Node.js SDK:
npm install commentguard-sdkFor full copy-paste examples in Node.js, Vanilla JS, Python, and PHP, see our Integration Guide.
Google's Perspective API is shutting down on Dec 31, 2026. CommentGuard acts as a 1:1 drop-in replacement. See our Perspective Migration Guide for instructions on how to switch by changing just one line of code.
CommentGuard runs with the Deep Learning Transformer by default. If you want to use the ultra-fast classical model (TF-IDF + Logistic Regression), you need to train it first.
- Download Dataset: Get the Jigsaw Toxic Comment Dataset from Kaggle.
- Train: Run
python model/train.pyon your local machine or in a Kaggle Notebook. - Move Files: The script will output three files. You must move them into the backend directory:
- Move
vectorizer.joblibβ‘οΈbackend/app/ml/vectorizer.joblib - Move
models.joblibβ‘οΈbackend/app/ml/models.joblib - Move
model_meta.jsonβ‘οΈbackend/app/ml/model_meta.json
- Move
- Configure: Open your
backend/.envfile and setMODEL_TYPE=classical. - Restart: Restart the backend or Docker container.
| Metric | Score |
|---|---|
| ROC-AUC | ~0.97 |
| Precision (toxic) | ~0.82 |
| Recall (toxic) | ~0.76 |
| F1 (toxic) | ~0.79 |
For full model documentation, see
model/MODEL_CARD.md
| Method | Endpoint | Description |
|---|---|---|
POST |
/moderate |
Multi-label moderation β returns scores for 6 toxicity categories |
POST |
/moderate/batch |
Batch moderation β up to 100 texts in one request |
POST |
/v1/comments:analyze |
Perspective API compatible β drop-in replacement |
POST |
/predict |
Alias for /moderate (Chrome extension backwards compat) |
GET |
/health |
Health check β model type, version, features, categories |
GET |
/stats |
Live analytics β per-category breakdown, recent log |
POST |
/feedback |
Submit false positive/negative reports for retraining |
GET |
/docs |
Interactive Swagger UI (auto-generated by FastAPI) |
curl -X POST http://localhost:8000/moderate \
-H "Content-Type: application/json" \
-d '{"text": "You are terrible", "threshold": 0.5}'{
"label": "toxic",
"toxic_prob": 0.87,
"decision": "block",
"categories": ["toxic", "insult"],
"scores": {
"toxic": 0.87,
"severe_toxic": 0.12,
"obscene": 0.34,
"threat": 0.08,
"insult": 0.82,
"identity_hate": 0.05
},
"flagged": true
}Decision logic:
blockβtoxic_prob >= thresholdreviewβtoxic_prob >= threshold Γ 0.6(borderline)allowβ below review threshold
|
|
Set via .env file or environment variables:
| Variable | Default | Options | Description |
|---|---|---|---|
MODEL_TYPE |
classical |
classical, transformer |
Model backend to use |
THRESHOLD |
0.5 |
0.0 β 1.0 |
Default block threshold |
ENV |
development |
development, production |
Environment label |
See docs/INTEGRATIONS.md for copy-paste examples in:
- Node.js / Express
- Python / Django
- PHP / Laravel
- Next.js (API routes)
Pattern: Call POST /moderate before saving any user comment to your database. Use the decision field to allow, review, or block.
cd backend
pip install -r requirements.txt # includes pytest
pytest tests/ -vThe test suite covers:
- Health check endpoint
- Toxic & clean comment classification
- Empty/missing text validation (422)
- Custom threshold overrides
- Feedback recording
- Edge cases (Unicode, long text, special characters)
- Multi-label classification (insult / threat / hate / obscene)
- Hindi + Hinglish support
- Dashboard web UI for analytics
- Persistent feedback logging (SQLite)
- Firefox extension
- npm package:
commentguard-client - Rate limiting middleware
- Batch moderation endpoint (
POST /moderate/batch)
Contributions are welcome! See CONTRIBUTING.md for guidelines.
Licensed under the Apache License 2.0 β see LICENSE for details.
Free to use, modify, and deploy commercially with attribution.
