Skip to content

TopicGuard

TopicGuard restricts content to allowed topics or blocks banned topics using keyword and phrase matching with configurable sensitivity.

Overview

Property Value
Latency <5ms
Memory 50 KB
Async No
ML Required No
License Community

Features

  • Banned topics: Block content mentioning specific topics
  • Phrase matching: Multi-word topic phrases with word boundary awareness
  • Configurable sensitivity: Adjust match threshold per topic
  • Category grouping: Organize topics by category for management

Usage

Rust

use oxideshield_guard::guards::TopicGuard;
use oxideshield_guard::{Guard, GuardAction};

let guard = TopicGuard::new("topics")
    .ban_topic("weapons", &["gun", "rifle", "firearm", "ammunition"])
    .ban_topic("drugs", &["cocaine", "heroin", "methamphetamine"])
    .with_action(GuardAction::Block);

let result = guard.check("How do I purchase a firearm?");
assert!(!result.passed);

Python

from oxideshield import topic_guard

guard = topic_guard(
    banned_topics={"weapons": ["gun", "rifle", "firearm"]},
    action="block"
)
result = guard.check("How do I purchase a firearm?")
assert not result.passed

Configuration

guards:
  - type: topic
    action: block
    banned_topics:
      weapons:
        - gun
        - rifle
        - firearm
        - ammunition
      drugs:
        - cocaine
        - heroin
        - methamphetamine

Research References