ai_comment_guard
Overview
AI Comment Guard automatically detects and handles abusive,
offensive, or harmful language in Drupal comments using the
Anthropic Claude AI API. Instead of
relying on static word lists or manual moderation queues, it sends each
comment through a large language model that understands context — catching
subtle harassment, coded language, and policy violations that keyword filters
miss entirely.
The Problem
Comment sections on high-traffic Drupal sites attract spam, hate speech, and
abusive content. Manual moderation does not scale, and traditional keyword
blocklists are trivially bypassed. Site administrators need an intelligent,
low-maintenance solution that acts before harmful content ever reaches other
readers.
What This Module Does
Every comment is evaluated by Claude AI before it is published. Based on the
result, the module can take one of three configurable actions:
-
Flag — unpublish the comment silently and place it in the
moderation queue for an administrator to review. -
Replace — keep the comment published but replace harmful
phrases with[removed], preserving the rest of the author's
message. -
Block — replace the entire comment body with a
configurable policy message and unpublish it.
Key Features
- AI-powered moderation using Anthropic Claude — understands context, not just keywords
- Three action modes: Flag, Replace, Block
- Configurable sensitivity levels: Low, Medium, High
- Custom rules field — extend the AI prompt with site-specific policy in plain language
- Bypass permission — trusted roles (editors, admins) skip AI review entirely
- Optional email notification to comment authors when their comment is flagged
- Violation logging to Drupal watchdog with severity level and AI-generated reason
- Status Report integration — warns on the admin dashboard if the API key is missing
- Compatible with Drupal 10, 11, and 12
Requirements
- Drupal core comment module
- An Anthropic API key (paid, usage-based)
- PHP 8.1 or higher
- Outbound HTTPS access from your server to
api.anthropic.com
Installation
Install as you would any contributed Drupal module:
composer require drupal/ai_comment_guard drush en ai_comment_guard drush cr
Then navigate to Administration → Configuration → Content authoring
→ AI Comment Guard and enter your Anthropic API key.
Configuration
All settings are managed through a single admin form. Choose your moderation
mode, set the AI sensitivity level, and optionally write custom rules in
plain English — for example: "Also flag any comments promoting competitor
products" or "Flag comments that include external links." No
code changes are required.
Privacy Consideration
Comment text is sent to Anthropic's API for analysis. Ensure your site's
privacy policy and terms of service reflect this. Do not use this module on
sites where comment content is confidential or subject to data residency
requirements without reviewing
Anthropic's privacy policy.
Similar Modules
If you need AI moderation for node content or other entity types, consider
pairing this module with
Drupal AI, which provides a
provider-agnostic AI abstraction layer for the broader Drupal ecosystem.