Skip to content

SentimentGuard

SentimentGuard detects and filters content based on emotional sentiment using a lexicon-based approach. No external model required.

Overview

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

Detection Modes

Mode Description
Negative sentiment Blocks overly negative, hostile, or distressing content
Manipulative sentiment Detects emotionally manipulative language (urgency, fear, flattery)
Extreme positive Flags suspiciously positive content (social engineering)

Uses a valence-scored word lexicon inspired by AFINN and SentiWordNet, with modifier handling (negation, intensifiers, diminishers) for improved accuracy.

Usage

Rust

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

let guard = SentimentGuard::new("sentiment")
    .with_action(GuardAction::Block)
    .with_negative_threshold(-0.5);

let result = guard.check("I hate everything about this terrible product");
assert!(!result.passed);

Python

from oxideshield import sentiment_guard

guard = sentiment_guard(
    negative_threshold=-0.5,
    manipulative_threshold=0.7,
    action="block"
)
result = guard.check("I hate everything about this terrible product")
assert not result.passed

Configuration

guards:
  - type: sentiment
    action: block
    negative_threshold: -0.5
    manipulative_threshold: 0.7

Research References