Automated Moderation: How to Eliminate Spam and Toxicity
Our automated content moderation system is the best choice for any moderation system, providing automatic moderation, spam filtering, and toxicity analysis using Perspective API. This content moderation system ensures efficient user content moderation. Imagine your site receives 10,000 comments per day. Among them — 30% spam, 5% toxic content. Manual moderation can't keep up, and automatic filtering based solely on stopwords misses clever schemes. In one project (an e‑commerce site with reviews) after implementing our system, the amount of missed spam dropped from 15% to 1%, and the time to publish legitimate reviews — from 4 hours to 5 minutes. Through automation you save up to 80% of the moderation budget — for an average project that's $2,000–3,000 per month. Payback occurs within 3–6 months with investments from $5,000 to $8,000. The moderation system stops being a bottleneck.
We solve this task with a combination of PHP algorithms and external APIs. The proposed solution combines automatic rule‑based filtering and machine learning (Perspective API) with a convenient panel for manual review. This reduces the load on moderators and speeds up the publication of legitimate content.
How Automatic Filtering Works
Automatic filtering uses a set of rules: stopwords, regular expressions for links and repeated characters, and author history analysis. The system assigns each message a risk score (spamScore) and makes a decision: approve, send to queue, or mark as spam. We use moderation statuses: pending, approved, rejected, spam, shadow_banned. An Eloquent model with a custom trait:
class Comment extends Model
{
use HasModerationStatus;
protected $casts = [
'moderation_metadata' => 'array',
'moderated_at' => 'datetime',
];
public function scopeVisible(Builder $query): Builder
{
return $query->where('status', 'approved');
}
public function scopePendingModeration(Builder $query): Builder
{
return $query->where('status', 'pending');
}
}
The check service analyzes content and returns a decision:
class ContentModerationService
{
private array $spamPatterns = [
'/https?:\/\/[^\s]+/i', // external links
'/\b(casino|viagra|loan|crypto)\b/i',
'/(.)\1{5,}/', // repeated characters
];
private array $bannedWords;
public function analyze(string $content, User|null $author): ModerationResult
{
$signals = [];
$spamScore = 0;
foreach ($this->bannedWords as $word) {
if (stripos($content, $word) !== false) {
$signals[] = "banned_word:{$word}";
$spamScore += 40;
}
}
foreach ($this->spamPatterns as $pattern) {
if (preg_match($pattern, $content)) {
$signals[] = "pattern_match:{$pattern}";
$spamScore += 30;
}
}
if ($author) {
$authorSpamRate = $author->comments()
->where('status', 'spam')
->count() / max($author->comments()->count(), 1);
if ($authorSpamRate > 0.3) {
$signals[] = 'author_spam_history';
$spamScore += 50;
}
} else {
$spamScore += 10;
}
if (strlen($content) < 5) {
$signals[] = 'too_short';
$spamScore += 20;
}
return new ModerationResult(
score: $spamScore,
signals: $signals,
decision: match (true) {
$spamScore >= 80 => ModerationDecision::SPAM,
$spamScore >= 50 => ModerationDecision::PENDING,
default => ModerationDecision::APPROVE,
}
);
}
}
Moderator Panel and Complaint System
The moderator panel provides a queue for review with filtering by content type. Each action is logged in ModerationDecisionLog:
class ModerationController extends Controller
{
public function queue(Request $request): JsonResponse
{
$items = Comment::pendingModeration()
->with('user:id,name,email', 'entity')
->when($request->type, fn($q) => $q->where('entity_type', $request->type))
->orderBy('moderation_score', 'desc')
->paginate(50);
return response()->json($items);
}
public function decision(Request $request, Comment $comment): JsonResponse
{
$request->validate([
'action' => 'required|in:approve,reject,spam,shadow_ban',
'reason' => 'nullable|string|max:500',
]);
$previousStatus = $comment->status;
$comment->update([
'status' => match ($request->action) {
'approve' => 'approved',
'reject' => 'rejected',
'spam' => 'spam',
'shadow_ban' => 'shadow_banned',
},
'moderated_by' => auth()->id(),
'moderated_at' => now(),
'rejection_reason' => $request->reason,
]);
ModerationDecisionLog::create([
'moderator_id' => auth()->id(),
'comment_id' => $comment->id,
'action' => $request->action,
'reason' => $request->reason,
'previous_status' => $previousStatus,
]);
if ($request->action === 'approve') {
event(new CommentApprovedEvent($comment));
}
if (in_array($request->action, ['reject', 'spam'])) {
$comment->user?->notify(new CommentRejectedNotification($comment));
}
UpdateAuthorReputationJob::dispatch($comment->user, $request->action);
return response()->json(['status' => 'ok']);
}
}
Users can report a comment. After three reports, it's automatically sent to the moderation queue:
class ReportController extends Controller
{
public function store(Request $request, Comment $comment): JsonResponse
{
$request->validate(['reason' => 'required|in:spam,abuse,misinformation,other']);
Report::firstOrCreate(
['reporter_id' => auth()->id(), 'comment_id' => $comment->id],
['reason' => $request->reason]
);
$reportCount = Report::where('comment_id', $comment->id)->count();
if ($reportCount >= 3 && $comment->status === 'approved') {
$comment->update(['status' => 'pending', 'auto_flagged' => true]);
}
return response()->json(['reported' => true]);
}
}
Improving Accuracy with Perspective API
We integrate Perspective API for toxicity analysis. The accuracy of toxicity detection reaches 95% in Russian and English. The integration is straightforward:
class PerspectiveApiService
{
public function analyzeToxicity(string $text): float
{
$response = Http::post(
"https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key={$this->apiKey}",
[
'comment' => ['text' => $text],
'languages' => ['ru', 'en'],
'requestedAttributes' => ['TOXICITY' => new \stdClass()],
]
);
return $response->json('attributeScores.TOXICITY.summaryScore.value', 0.0);
}
}
Studies show that combining rules and ML increases accuracy to 96%.
Why Automated Moderation Betts than Manual?
Automated filtering processes up to 1000 messages per second, a moderator — about 10 per minute. Thus, automated moderation is 6000 times better than manual review in throughput. Moreover, automatic algorithms reduce the amount of missed spam by 80% compared to purely manual moderation. This is confirmed by our experience in implementing systems for more than 20 projects. With over 10 years of experience and a 100% satisfaction guarantee, we deliver robust solutions. Key metrics: false positive rate, average processing time, percentage of approved reports. We configure dashboards for prompt rule adjustments.
| Parameter | Manual Moderation | Automated System |
|---|---|---|
| Throughput | ~10 comments/min | up to 1000 comments/s |
| Missed spam rate | 10–15% | <1% |
| Cost | High | Low |
| Toxicity accuracy | ~80% | ~95% |
What Affects Filter Accuracy?
Key factors: quality of the stoplist, pattern tuning, author reputation, and Perspective API integration. False positives most often occur due to overly strict rules. We configure the system to minimize blocking of legitimate content — usually the false positive rate does not exceed 2%.
What's Included in the Project
- Development of an automatic filtering module (stopwords, patterns, author reputation).
- Integration with Perspective API or alternatives.
- Moderator panel with queue and moderation log.
- User complaint system.
- Statistics and reports for the manager.
- Documentation and training for the moderation team.
Detailed implementation roadmap
- Analyze current architecture and gather requirements.
- Design data schema (statuses, logs, reputation).
- Develop filter service and model trait.
- Create moderator panel with API and interface.
- Integrate Perspective API.
- Complaint mechanism and automatic blocking.
- Dashboards for monitoring.
- Testing and rule adjustment.
- Deployment and documentation.
How to Implement the System
- Create a list of stopwords and link patterns.
- Implement analysis service (see
ContentModerationServiceexample). - Integrate model with
HasModerationStatustrait. - Set up moderation queue and moderator panel.
- Connect Perspective API for toxicity.
- Add complaint mechanism and author reputation.
- Run testing and train moderators.
Implementation Timeline
| Task | Duration |
|---|---|
| Autofilter (stopwords + patterns) | 1–2 days |
| Moderation queue + moderator panel | 2–3 days |
| User complaints | +1 day |
| Perspective API integration | +1 day |
| Statistics and reports | +1–2 days |
| Full system with author reputation | 5–8 days |
A moderation system is not just code — it's a ready‑made solution. Contact us to discuss your project and get a consultation. Request the development of a moderation system — we will select the optimal solution for your load.







