cd /news/artificial-intelligence/build-an-ai-moderation-classifier-in… · home topics artificial-intelligence article
[ARTICLE · art-69336] src=dev.to ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

Build an AI Moderation Classifier in Python

A developer built a two-stage AI moderation classifier in Python using Telnyx AI Inference. The pipeline uses embeddings similarity to catch obvious spam and abuse patterns, then falls back to an LLM for nuanced content. The open-source Flask example provides endpoints for blocklisting, moderation, and batch processing.

read2 min views1 publishedJul 22, 2026

Moderation is one of those product features where "just ask an LLM" sounds tempting, but it is not always the best workflow.

Some content is obvious. Known spam, repeated abuse patterns, and common scam text should be caught quickly and consistently.

Other content needs judgment. It may be contextual, vague, sarcastic, or borderline.

I put together a Python Flask example that handles both paths with Telnyx AI Inference:

https://github.com/team-telnyx/telnyx-code-examples/tree/main/moderation-classifier-python

The app uses a two-stage pipeline:

Before moderating content, build the blocklist index:

curl -X POST http://localhost:5000/blocklist/index

That embeds the bundled sample_blocklist.json

entries through:

POST /v2/ai/openai/embeddings

Then you can classify a single piece of content:

curl -X POST http://localhost:5000/moderate \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Great product, really enjoyed using it.",
    "source": "review",
    "author_id": "user-123"
  }'

The app returns structured fields:

{
  "category": "safe",
  "confidence": 1.0,
  "flags": [],
  "blocklist_match": false,
  "recommended_action": "allow",
  "reason": "Benign positive product review with no policy violations."
}

If content matches the blocklist strongly enough, the app skips the LLM and returns the matched category directly.

For anything else, it calls:

POST /v2/ai/chat/completions

The default models are:

AI_MODEL=moonshotai/Kimi-K2.6
EMBEDDING_MODEL=thenlper/gte-large

The example includes:

POST /blocklist/index

POST /moderate

POST /moderate/batch

POST /blocklist

GET /blocklist

GET /moderations

GET /moderations/<id>

GET /stats

GET /health

Batch moderation supports up to 20 items:

curl -X POST http://localhost:5000/moderate/batch \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      {"content": "Great product!", "source": "review"},
      {"content": "Buy cheap followers now!", "source": "message"}
    ]
  }'

The important idea is separating obvious moderation cases from nuanced ones.

Known-bad patterns can be handled with embeddings similarity.

Ambiguous content can go to an LLM for classification and reasoning.

The response is structured enough to plug into product logic:

allow

flag

remove

escalate

For production, I would add persistence, audit logs, human review queues, rate limiting, and a feedback loop so reviewers can tune the blocklist and thresholds over time.

Resources:

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @telnyx 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/build-an-ai-moderati…] indexed:0 read:2min 2026-07-22 ·