A Python CLI tool that reads user comments from a CSV or JSON file, uses a Generative AI model via OpenRouter to detect offensive or inappropriate content, and generates a clean report with visual insights.
Uses reliable and open-source
nvidia/llama-3.1-nemotron-nano-8b-v1:freemodel from OpenRouter.
- 🧠 LLM-powered moderation using OpenRouter
- 📁 Supports
.csvand.jsoninput - 🚫 Fully LLM-based (no profanity filter)
- 🧹 Auto-fixes messy JSON responses
- 📝 Generates a detailed summary report
- 📊 Produces a pie chart of offense types
- 🧃 CLI support for flexible input/output
git clone https://github.com/tars-06/commentMOD.git
cd comment-moderation
pip install -r requirements.txtrequests
matplotlib
python-dotenv
-
Create a
.envfile in the project root:OPENROUTER_API_KEY=sk-your-openrouter-api-key -
Enable prompt training on your OpenRouter account:
👉 https://openrouter.ai/settings/privacy
comment_id,username,comment_text
1,alice,"I love the way you explained it!"
2,bob,"You're so dumb it's painful."
...[
{
"comment_id": 1,
"username": "alice",
"comment_text": "I love the way you explained it!"
},
...
]python moderate_comments.py comments.csvpython moderate_comments.py comments.jsonpython moderate_comments.py comments.csv --output_dir outputs/| File | Description |
|---|---|
moderated_comments.csv |
All comments + moderation results |
moderation_report.txt |
Summary report + top 5 most offensive comments |
offense_type_pie_chart.png |
Pie chart of offensive comment types |
Each comment is enriched with the following fields:
{
"comment_id": 42,
"is_offensive": true,
"offense_type": "harassment",
"explanation": "Contains threatening and derogatory language."
}-
401 Unauthorized
→ Check if your API key is valid and loaded via.env -
404 from OpenRouter
→ Go to https://openrouter.ai/settings/privacy and enable "Allow prompt training" -
JSONDecodeError
→ Script automatically sanitizes bad output or skips malformed batches.
- Uses batch prompting (10 comments per API call)
- Automatically handles smart quotes, bad punctuation, and broken JSON
- Purely LLM-driven — no keyword-based filtering
MIT © Aaditya Saraf