Skip to main content

PerplexityGuard

Struct PerplexityGuard 

Source
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

Source

pub fn new(name: impl Into<String>) -> Self

Create a new perplexity guard with default settings

Source

pub fn with_analyzer_config( name: impl Into<String>, config: PerplexityConfig, ) -> Self

Create with custom analyzer configuration

Source

pub fn with_max_perplexity(self, max: f32) -> Self

Set the maximum perplexity threshold

Source

pub fn with_min_perplexity(self, min: f32) -> Self

Set the minimum perplexity threshold

Source

pub fn with_min_entropy(self, min: f32) -> Self

Set the minimum entropy threshold

Source

pub fn with_suffix_ratio(self, ratio: f32) -> Self

Set the suffix analysis ratio

Source

pub fn analyze_full_text(self, enabled: bool) -> Self

Enable/disable full text analysis

Source

pub fn analyze_suffix(self, enabled: bool) -> Self

Enable/disable suffix-focused analysis

Source

pub fn with_action(self, action: GuardAction) -> Self

Set the action to take

Source

pub fn with_severity(self, severity: Severity) -> Self

Set the severity for matches

Source

pub fn config(&self) -> &PerplexityGuardConfig

Get the current configuration

Trait Implementations§

Source§

impl Guard for PerplexityGuard

Source§

fn name(&self) -> &str

Get the guard name
Source§

fn check(&self, content: &str) -> GuardCheckResult

Check content against this guard
Source§

fn action(&self) -> GuardAction

Get the action this guard takes on failure
Source§

fn severity_threshold(&self) -> Severity

Get the minimum severity that triggers this guard

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<G> InstrumentGuard for G
where G: Guard,

Source§

fn instrumented(self) -> InstrumentedGuard<Self>

Wrap this guard with metrics instrumentation
Source§

fn instrumented_with( self, collector: Arc<GuardMetricsCollector>, ) -> InstrumentedGuard<Self>

Wrap this guard with a specific collector
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more