pub struct PerplexityGuard { /* private fields */ }Expand description
Guard for detecting adversarial patterns using perplexity analysis
This guard is particularly effective at detecting:
- GCG-style adversarial suffixes (random gibberish)
- AutoDAN-style generated attacks
- Repetitive padding attacks
- Unusual character distributions
Implementations§
Source§impl PerplexityGuard
impl PerplexityGuard
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new perplexity guard with default settings
Sourcepub fn with_analyzer_config(
name: impl Into<String>,
config: PerplexityConfig,
) -> Self
pub fn with_analyzer_config( name: impl Into<String>, config: PerplexityConfig, ) -> Self
Create with custom analyzer configuration
Sourcepub fn with_max_perplexity(self, max: f32) -> Self
pub fn with_max_perplexity(self, max: f32) -> Self
Set the maximum perplexity threshold
Sourcepub fn with_min_perplexity(self, min: f32) -> Self
pub fn with_min_perplexity(self, min: f32) -> Self
Set the minimum perplexity threshold
Sourcepub fn with_min_entropy(self, min: f32) -> Self
pub fn with_min_entropy(self, min: f32) -> Self
Set the minimum entropy threshold
Sourcepub fn with_suffix_ratio(self, ratio: f32) -> Self
pub fn with_suffix_ratio(self, ratio: f32) -> Self
Set the suffix analysis ratio
Sourcepub fn analyze_full_text(self, enabled: bool) -> Self
pub fn analyze_full_text(self, enabled: bool) -> Self
Enable/disable full text analysis
Sourcepub fn analyze_suffix(self, enabled: bool) -> Self
pub fn analyze_suffix(self, enabled: bool) -> Self
Enable/disable suffix-focused analysis
Sourcepub fn with_action(self, action: GuardAction) -> Self
pub fn with_action(self, action: GuardAction) -> Self
Set the action to take
Sourcepub fn with_severity(self, severity: Severity) -> Self
pub fn with_severity(self, severity: Severity) -> Self
Set the severity for matches
Sourcepub fn config(&self) -> &PerplexityGuardConfig
pub fn config(&self) -> &PerplexityGuardConfig
Get the current configuration
Trait Implementations§
Source§impl Guard for PerplexityGuard
impl Guard for PerplexityGuard
Source§fn check(&self, content: &str) -> GuardCheckResult
fn check(&self, content: &str) -> GuardCheckResult
Check content against this guard
Source§fn action(&self) -> GuardAction
fn action(&self) -> GuardAction
Get the action this guard takes on failure
Source§fn severity_threshold(&self) -> Severity
fn severity_threshold(&self) -> Severity
Get the minimum severity that triggers this guard
Auto Trait Implementations§
impl Freeze for PerplexityGuard
impl RefUnwindSafe for PerplexityGuard
impl Send for PerplexityGuard
impl Sync for PerplexityGuard
impl Unpin for PerplexityGuard
impl UnwindSafe for PerplexityGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<G> InstrumentGuard for Gwhere
G: Guard,
impl<G> InstrumentGuard for Gwhere
G: Guard,
Source§fn instrumented(self) -> InstrumentedGuard<Self>
fn instrumented(self) -> InstrumentedGuard<Self>
Wrap this guard with metrics instrumentation
Source§fn instrumented_with(
self,
collector: Arc<GuardMetricsCollector>,
) -> InstrumentedGuard<Self>
fn instrumented_with( self, collector: Arc<GuardMetricsCollector>, ) -> InstrumentedGuard<Self>
Wrap this guard with a specific collector