Coming Soon

Advanced Rule Builder

The Rule Builder is an advanced moderation feature that automatically takes action against users based on their behavior patterns. Instead of moderating each message individually, the Rule Builder tracks user violations over time and triggers actions when users reach certain thresholds.

How It Works

The Rule Builder monitors user behavior across all your moderation tools and automatically responds when users violate your community guidelines repeatedly. For example:

  • Spam Detection: Ban users who send 5+ spam messages within 1 hour
  • Toxic Behavior: Flag users who post 3+ hate speech messages within 24 hours
  • New User Abuse: Shadow ban new accounts that violate rules within their first day
  • Content Frequency: Flag users who post 50+ messages within 1 hour

Key Benefits

  • Automated Response: No manual intervention needed for common violation patterns
  • Flexible Rules: Create custom rules that match your community’s specific needs
  • Time-Based Tracking: Consider user behavior over time, not just individual messages
  • Multiple Actions: Choose from ban, flag, shadow ban, or other actions
  • Real-Time Processing: Rules are evaluated immediately as users post content

Creating Your First Rule

Dashboard

You can create rules in the dashboard by navigating to Moderation > Policies > [Select a policy] > Rule Builder.

Rule Builder List

Rule Builder

API

You can create rules using UpsertConfig API.

await client.moderation.upsertConfig({
  key: "chat:messaging",
  rule_builder_config: {
    enabled: true,
    rules: [
      {
        id: "spam-detection",
        name: "Spam Detection",
        enabled: true,
        conditions: [
          {
            type: "text_rule",
            text_rule_params: {
              threshold: 5,
              time_window: "1h",
              harm_labels: ["SPAM", "ADS"],
            },
          },
        ],
        logic: "AND",
        action: {
          type: "ban",
          ban_options: {
            duration: 3600,
            reason: "Spam behavior detected",
            shadow_ban: false,
            ip_ban: false,
          },
        },
      },
    ],
  },
});

Basic Rule Structure

Every rule has three main parts:

  1. Conditions: What behavior to watch for
  2. Threshold: How many violations before taking action
  3. Action: What to do when the threshold is reached

Example: Spam Detection Rule

{
  "id": "spam-detection",
  "name": "Spam Detection",
  "enabled": true,
  "conditions": [
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 5,
        "time_window": "1h",
        "harm_labels": ["SCAM", "PLATFORM_BYPASS"]
      }
    },
    {
      "type": "content_count_rule",
      "content_count_rule_params": {
        "threshold": 50,
        "time_window": "1h"
      }
    }
  ],
  "logic": "OR",
  "action": {
    "type": "ban",
    "ban_options": {
      "duration": 3600,
      "reason": "Spam behavior detected",
      "shadow_ban": false,
      "ip_ban": false
    }
  }
}

This rule:

  • Watches for spam and advertising content
  • Triggers when a user posts 5+ spam messages within 1 hour or 50+ messages within 1 hour
  • Bans the user for 1 hour when triggered

Rule Types

Text-Based Rules

Track violations in text content like messages, comments, or posts.

Available Labels:

  • Harassment: SEXUAL_HARASSMENT, MORAL_HARASSMENT, BULLYING
  • Hate Speech: RACISM, HOMOPHOBIA, MISOGYNY, ABLEISM
  • Threats: THREAT, TERRORISM, SELF_HARM
  • Inappropriate Content: SEXUALLY_EXPLICIT, DRUG_EXPLICIT, WEAPON_EXPLICIT
  • Spam: SCAM, ADS, FLOOD

Example:

{
  "type": "text_rule",
  "text_rule_params": {
    "threshold": 3,
    "time_window": "24h",
    "harm_labels": ["HATE_SPEECH", "THREAT"],
    "severity": "HIGH"
  }
}

Image-Based Rules

Track violations in uploaded images.

Available Labels:

  • Explicit Content: Explicit, Non-Explicit Nudity
  • Violence: Violence, Visually Disturbing
  • Inappropriate: Drugs & Tobacco, Alcohol, Rude Gestures
  • Hate Symbols: Hate Symbols

Example:

{
  "type": "image_rule",
  "image_rule_params": {
    "threshold": 1,
    "time_window": "24h",
    "harm_labels": ["Explicit", "Violence"]
  }
}

User-Based Rules

Check user account properties.

Example:

{
  "type": "user_rule",
  "user_rule_params": {
    "max_age": "24h"
  }
}

This condition is true for users who created their account within the last 24 hours.

Content Count Rules

Track how many messages a user posts.

Example:

{
  "type": "content_count_rule",
  "content_count_rule_params": {
    "threshold": 50,
    "time_window": "1h"
  }
}

This triggers when a user posts 50+ messages within 1 hour.

Combining Conditions

AND Logic

All conditions must be met for the rule to trigger.

{
  "logic": "AND",
  "conditions": [
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 2,
        "time_window": "24h",
        "harm_labels": ["HATE_SPEECH"]
      }
    },
    {
      "type": "user_rule",
      "user_rule_params": {
        "max_age": "24h"
      }
    }
  ]
}

This rule only triggers for new users (account < 24h old) who also post 2+ hate speech messages.

OR Logic

Any condition can trigger the rule.

{
  "logic": "OR",
  "conditions": [
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 3,
        "time_window": "24h",
        "harm_labels": ["HATE_SPEECH"]
      }
    },
    {
      "type": "image_rule",
      "image_rule_params": {
        "threshold": 1,
        "time_window": "24h",
        "harm_labels": ["Explicit"]
      }
    }
  ]
}

This rule triggers if a user posts 3+ hate speech messages OR 1+ explicit image.

Available Actions

Ban User

Temporarily or permanently ban a user from your platform.

{
  "type": "ban",
  "ban_options": {
    "duration": 86400,
    "reason": "Multiple violations detected",
    "shadow_ban": false,
    "ip_ban": false
  }
}

Options:

  • duration: Ban length in seconds (0 = permanent)
  • reason: Reason shown to moderators
  • shadow_ban: User can post but content is hidden
  • ip_ban: Also ban the user’s IP address

Flag User

Create a review item for manual moderator review.

{
  "type": "flag_user",
  "flag_user_options": {
    "reason": "Suspicious behavior pattern detected"
  }
}

Time Windows

Specify how long to track user behavior:

  • "30m": 30 minutes
  • "1h": 1 hour
  • "24h": 24 hours
  • "7d": 7 days
  • "30d": 30 days

Real-World Examples

Example 1: Toxic User Detection

This rule identifies users who consistently engage in harmful behavior over time, targeting both hate speech and excessive profanity.

{
  "id": "toxic-user",
  "name": "Toxic User Detection",
  "enabled": true,
  "logic": "OR",
  "conditions": [
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 5,
        "time_window": "24h",
        "harm_labels": ["HATE_SPEECH", "HARASSMENT", "THREAT"]
      }
    },
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 50,
        "time_window": "24h",
        "blocklist_match": ["profanity_en_2020_v1"]
      }
    }
  ],
  "action": {
    "type": "ban",
    "ban_options": {
      "duration": 604800,
      "reason": "Toxic behavior detected",
      "shadow_ban": false,
      "ip_ban": true
    }
  }
}

What it does:

  • First condition: Triggers if a user posts 5 or more messages containing hate speech, harassment, or threats within 24 hours
  • Second condition: Triggers if a user posts 50 or more messages that match the profanity blocklist within 24 hours
  • Logic: Uses “OR” logic, meaning either condition can trigger the rule
  • Action: Bans the user for 7 days (604,800 seconds) and also bans their IP address to prevent them from creating new accounts

When to use this rule:

  • Communities with strict content policies
  • Platforms that need to quickly remove toxic users
  • Situations where you want to prevent users from circumventing bans with new accounts

Example 2: New User Spam Protection

This rule specifically targets spam from newly created accounts, which are often used by bots or malicious users.

{
  "id": "new-user-spam",
  "name": "New User Spam Protection",
  "enabled": true,
  "logic": "AND",
  "conditions": [
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 3,
        "time_window": "1h",
        "harm_labels": ["SPAM", "ADS"]
      }
    },
    {
      "type": "user_rule",
      "user_rule_params": {
        "max_age": "24h"
      }
    }
  ],
  "action": {
    "type": "ban",
    "ban_options": {
      "duration": 3600,
      "reason": "New user spam detected",
      "shadow_ban": true,
      "ip_ban": false
    }
  }
}

What it does:

  • First condition: Triggers if a user posts 3 or more spam or advertising messages within 1 hour
  • Second condition: Only applies to users whose accounts are less than 24 hours old
  • Logic: Uses “AND” logic, meaning both conditions must be true for the rule to trigger
  • Action: Shadow bans the user for 1 hour (3,600 seconds), meaning they can still post but their content is hidden from other users

When to use this rule:

  • Platforms with high bot activity
  • Communities that want to give new users a chance but prevent immediate spam
  • Situations where you want to test if a user is legitimate before fully banning them

Example 3: Message Frequency Abuse

This rule catches users who are posting too many messages too quickly, especially when combined with spam content.

{
  "id": "message-flood",
  "name": "Message Frequency Abuse",
  "enabled": true,
  "logic": "AND",
  "conditions": [
    {
      "type": "content_count_rule",
      "content_count_rule_params": {
        "threshold": 50,
        "time_window": "1h"
      }
    },
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 5,
        "time_window": "1h",
        "harm_labels": ["SCAM", "PLATFORM_BYPASS"],
        "contains_url": true
      }
    }
  ],
  "action": {
    "type": "flag_user",
    "flag_user_options": {
      "reason": "Excessive messaging with spam content"
    }
  }
}

What it does:

  • First condition: Triggers if a user posts 50 or more messages within 1 hour (regardless of content)
  • Second condition: Triggers if a user posts 5 or more messages classified as spam or flood content within 1 hour
  • Logic: Uses “AND” logic, meaning both conditions must be true for the rule to trigger
  • Action: Flags the user for manual review by moderators instead of automatically banning them

When to use this rule:

  • Communities where legitimate users might post frequently (like gaming chats)
  • Situations where you want human oversight before taking action
  • Platforms that want to distinguish between active users and spam bots

Example 4: Severe Content Violation

This rule provides immediate action for the most serious violations, such as terrorism-related content.

{
  "id": "severe-violation",
  "name": "Severe Content Violation",
  "enabled": true,
  "logic": "OR",
  "conditions": [
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 1,
        "time_window": "24h",
        "harm_labels": ["TERRORISM"]
      }
    },
    {
      "type": "image_rule",
      "image_rule_params": {
        "threshold": 1,
        "time_window": "24h",
        "harm_labels": ["Violence", "Hate Symbols"]
      }
    }
  ],
  "action": {
    "type": "ban",
    "ban_options": {
      "duration": 0,
      "reason": "Severe content violation",
      "shadow_ban": false,
      "ip_ban": true
    }
  }
}

What it does:

  • First condition: Triggers if a user posts even 1 message containing terrorism-related content within 24 hours
  • Second condition: Triggers if a user uploads even 1 image containing violence or hate symbols within 24 hours
  • Logic: Uses “OR” logic, meaning either condition can trigger the rule
  • Action: Permanently bans the user (duration: 0 seconds) and bans their IP address

When to use this rule:

  • Platforms with zero-tolerance policies for certain content
  • Communities that need to comply with legal requirements
  • Situations where immediate and permanent removal is necessary

Example 5: Coordinated Behavior Detection

This rule identifies patterns that suggest coordinated abuse or bot activity.

{
  "id": "coordinated-behavior",
  "name": "Coordinated Behavior Detection",
  "enabled": true,
  "logic": "AND",
  "conditions": [
    {
      "type": "content_count_rule",
      "content_count_rule_params": {
        "threshold": 100,
        "time_window": "24h"
      }
    },
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 10,
        "time_window": "24h",
        "harm_labels": ["SPAM", "ADS", "SCAM"]
      }
    },
    {
      "type": "text_rule",
      "text_rule_params": {
        "threshold": 5,
        "time_window": "24h",
        "contains_url": true
      }
    }
  ],
  "action": {
    "type": "flag_user",
    "flag_user_options": {
      "reason": "Potential coordinated spam or bot activity"
    }
  }
}

What it does:

  • First condition: Triggers if a user posts 100 or more messages within 24 hours
  • Second condition: Triggers if a user posts 10 or more spam, advertising, or scam messages within 24 hours
  • Third condition: Triggers if a user posts 5 or more messages containing URLs within 24 hours
  • Logic: Uses “AND” logic, meaning all three conditions must be true for the rule to trigger
  • Action: Flags the user for manual review by moderators

When to use this rule:

  • Platforms experiencing coordinated spam attacks
  • Communities that want to identify potential bot networks
  • Situations where you need to investigate before taking action

Best Practices

Start Simple

Begin with basic rules and gradually add complexity as you understand your community’s needs.

Set Reasonable Thresholds

  • Too low: May catch legitimate users
  • Too high: May miss problematic behavior
  • Start conservative and adjust based on results

Use Appropriate Time Windows

  • Short windows (1-6 hours): Catch immediate abuse
  • Medium windows (24-48 hours): Catch persistent violators
  • Long windows (7-30 days): Catch chronic offenders

Test Your Rules

Use the test mode to verify your rules work as expected before enabling them in production.

Monitor Performance

Watch for rules that trigger too frequently or not enough, and adjust accordingly.

Common Use Cases

Gaming Communities

  • Detect toxic players who harass others repeatedly
  • Identify spam bots posting promotional content
  • Flag users who post inappropriate content in chat

Social Platforms

  • Prevent harassment campaigns against specific users
  • Detect coordinated spam or bot activity
  • Flag users who post explicit content

Business Applications

  • Protect customer support channels from spam
  • Detect fake accounts created for abuse
  • Maintain professional communication standards
© Getstream.io, Inc. All Rights Reserved.