# Discourse AI - Spam detection

**URL:** https://meta.discourse.org/t/discourse-ai-spam-detection/343541
**Category:** Site Management
**Tags:** moderation, how-to, ai, spam
**Created:** [December 20, 2024, 4:46am UTC](https://meta.discourse.org/t/discourse-ai-spam-detection/343541 "2024-12-20T04:46:26Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 20, 2024, 4:46am UTC](https://meta.discourse.org/t/discourse-ai-spam-detection/343541/1 "2024-12-20T04:46:26Z")

</div>

> 🔖 This guide explains how to configure and use Discourse AI’s spam detection feature, including the setup process, scanning criteria, classification logic, customizations, and contrasts with AI triage.
> 
> 🙋 Required user level: Administrator

> 📣 This is now default turned on for [Starter and Pro customers](https://meta.discourse.org/t/discourse-ai-spam-detection-replaces-akismet-plugin/354602), as well as our legacy Basic, Open Source, Creator, and Business customers.

Discourse AI provides an efficient spam detection feature that identifies and flags spam posts with minimal configuration. While designed for simplicity, it complements the more versatile AI triage system, which supports broader workflows and larger use cases.

## Summary

In this guide, you will learn:

- How AI spam detection works and what content is scanned
- The classification logic and context used by the AI
- Steps to configure spam detection through `/admin/plugins/discourse-ai/ai-spam`
- Guidelines for Large Language Model (LLM) selection
- Key differences between spam detection and AI triage
- How to manage flagged and missed posts

* * *

## How AI spam detection works

### What content gets scanned?

AI spam detection evaluates posts based on these criteria:

1. **User trust level** :

2. **Post type** :

3. **Post edits** :

4. **Post frequency** :

5. **Review queue** :

### The classification process

Posts that meet the criteria are sent to an AI agent for analysis. The agent evaluates whether the post is spam or not spam and provides a reason for its classification, using structured JSON output. The evaluation is based on:

- **Context** : Includes post content, topic title, category, user account data (e.g., username, email, account age, total posts, and trust level), and IP-based geo-location information.
- **Image analysis** : Up to **3 image uploads** attached to a post are included for analysis.
- **Reply context** : For reply posts, the parent post content (up to 500 characters) is included.
- **Site information** : The site name, URL, description, and top 10 categories are provided to the AI.
- **Custom instructions** : Admin-defined rules for reinforced or adapted scanning criteria.
- **Automated detection** :
  - Flags irrelevant or promotional content (e.g., ads or commercial materials).
  - Identifies automated or bot-like behaviors.
  - Assesses content relevance to the discussion.

### Default prompt and context

The AI uses a default system prompt to guide spam detection. The built-in spam detection agent prompt covers:

```plaintext
You are a spam detection system. Analyze the following post content and context.

Consider the post type carefully:
- For REPLY posts: Check if the response is relevant and topical to the thread
- For NEW TOPIC posts: Check if it's a legitimate topic or spam promotion

A post is spam if it matches any of these criteria:
- Contains unsolicited commercial content or promotions
- Has suspicious or unrelated external links
- Shows patterns of automated/bot posting
- Contains irrelevant content or advertisements
- For replies: Completely unrelated to the discussion thread
- Uses excessive keywords or repetitive text patterns
- Shows suspicious formatting or character usage

Be especially strict with:
- Replies that ignore the previous conversation
- Posts containing multiple unrelated external links
- Generic responses that could be posted anywhere

Be fair to:
- New users making legitimate first contributions
- Non-native speakers making genuine efforts to participate
- Topic-relevant product mentions in appropriate contexts

```

The scanner also compiles a **context package** , including:

- Post type (NEW TOPIC or REPLY) with category and topic metadata.
- For replies: the parent post content and topic author.
- Author data (username, email, account age, total posts, trust level, and IP-based location).
- Post text truncated to **5000 characters** for processing.
- Up to **3 image uploads** attached to the post.

* * *

## Configure AI spam detection

### Configuration guide

 ![A screenshot displaying the settings for spam handling in an AI module, indicating that 132 posts were scanned with 15 detected as spam in the last 7 days. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/3/7/1/371f15edb98be5e6bbf7101ee7b60b662da1d4be.png)

1. **Access settings** :  
Navigate to `/admin/plugins/discourse-ai/ai-spam`.

2. **Select an LLM** :

> ℹ **If your site is hosted by Discourse**
> 
> You can select our CDCK Hosted Small LLM from the LLM list.

- Choose a language model suited to your forum’s needs. See the [Large Language Model (LLM) settings page](https://meta.discourse.org/t/discourse-ai-large-language-model-llm-settings-page/319903) for configuring LLMs.
- Access `/admin/plugins/discourse-ai/ai-llms` for LLM configurations.

1. **Activate spam detection** :  
Enable spam detection by toggling the feature on.

> ℹ Note: A connected LLM is mandatory.

1. **Add customized instructions** :

2. **Adjust scanning thresholds** (optional):

* * *

## Differences from AI triage

While spam detection is designed specifically for identifying spam, **AI triage** supports broader post management tasks.

| Feature | AI Spam Detection | AI Triage |
| --- | --- | --- |
| **Complexity** | Streamlined, opinionated setup | Highly customizable and flexible |
| **Primary use case** | Detecting spam with minimal overhead | Advanced workflows for categorization, tagging, replies, spam detection, nsfw detection |
| **Actions** | Flags spam, hides posts, silences users | Tags, categorizes, hides posts, adds replies, flags posts, silences users |
| **Recommendation** | Easy setup and effective for most situations | Use for rich highly customizable workflows |

For more details, see [Discourse AI - AI triage](https://meta.discourse.org/t/discourse-ai-ai-triage/281227).

* * *

## LLM selection recommendations

The performance of spam detection depends on the chosen LLM.

Most low-cost LLMs work effectively, such as:

- GPT-4o-mini
- Claude 3.5 Haiku
- Gemini 2.0 Flash

Experiment with different models to find the best fit. Configure your models via `/admin/plugins/discourse-ai/ai-llms`.

* * *

## Testing spam scanner behavior

You can test spam detection rules directly from the configuration page.

 ![The image is a spam detection result for a post in the meta Discourse forum, indicating that the post is sam. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/8/f/c/8fc5ea9530c5536e49e3561a811c51a68f298b4f.png)

- Paste a **post URL or ID** into the test field.
- Review the classification result and the AI’s reasoning for its decision.
- Unsaved changes are applied during testing, enabling experimentation without risk.

* * *

## Managing flagged and missed posts

### Handling flagged posts

When a post is detected as spam, the system:

- **Flags** the post as spam and adds it to the review queue.
- **Silences** the posting user.
- **Hides** the post from public view.
- **Makes the topic invisible** if the spam post was the first post in the topic.

Flagged posts appear in the moderation queue. Admins can:

- Approve legitimate posts wrongly classified as spam.
- Reject spam topics to keep the system accurate.

> ⚠ **Important** : Reject spam flags for incorrectly classified posts. Users remain silenced until the flag is resolved.

### Handling missed spam

Missed spam refers to posts bypassing detection but flagged by the community. Moderators can manage these as necessary.

* * *

## Best practices

- Monitor flagged and missed spam regularly to refine system accuracy. Clickable metrics simplify this process.
- Use test cases to evaluate custom instructions against edge cases.
- Review and adjust LLM settings when needed.
- Use the `ai_spam_detection_max_trust_level` and `ai_spam_detection_max_post_count` site settings to tune which users are scanned based on your community’s needs.

* * *

## Additional resources

- [Discourse AI - AI triage](https://meta.discourse.org/t/discourse-ai-ai-triage/281227)
- [Discourse AI - Large Language Model (LLM) settings page](https://meta.discourse.org/t/discourse-ai-large-language-model-llm-settings-page/319903)

* * *

> 📣 Configuring AI spam detection effectively reduces manual moderation efforts, ensuring a clean, spam-free community.

---

_[View the full topic](https://meta.discourse.org/t/discourse-ai-spam-detection/343541)._
