pub struct PatternDetector { /* private fields */ }Expand description
Detection heuristics for each pattern
Implementations§
Source§impl PatternDetector
impl PatternDetector
Sourcepub fn critical_only() -> Self
pub fn critical_only() -> Self
Create detector with only P0 (critical) patterns
Sourcepub fn check_fallback_consistency(
&self,
primary_output: &str,
fallback_output: &str,
) -> bool
pub fn check_fallback_consistency( &self, primary_output: &str, fallback_output: &str, ) -> bool
Check for SilentFallbackWrongResource pattern
Detection: Compare output from primary resource vs fallback resource. If outputs differ significantly, fallback used wrong resource.
Sourcepub fn check_tensor_validity(&self, values: &[f32]) -> TensorValidityResult
pub fn check_tensor_validity(&self, values: &[f32]) -> TensorValidityResult
Check for MissingPostTransformValidation pattern
Detection: Look for NaN, Inf, or extreme values in transformed data.
Sourcepub fn check_companion_files(
&self,
primary_path: &Path,
required_companions: &[&str],
) -> CompanionCheckResult
pub fn check_companion_files( &self, primary_path: &Path, required_companions: &[&str], ) -> CompanionCheckResult
Check for MissingCompanionData pattern
Detection: Verify expected companion files exist alongside primary file.
Sourcepub fn check_path_safety(&self, path: &str) -> PathSafetyResult
pub fn check_path_safety(&self, path: &str) -> PathSafetyResult
Check for PathTraversal pattern
Detection: Reject paths containing traversal sequences.
Sourcepub fn check_prompt_safety(&self, prompt: &str) -> PromptSafetyResult
pub fn check_prompt_safety(&self, prompt: &str) -> PromptSafetyResult
Check for PromptInjection pattern
Detection: Look for unescaped special tokens in user input.
Sourcepub fn check_attention_entropy(
&self,
attention_weights: &[f32],
) -> NumericalStabilityResult
pub fn check_attention_entropy( &self, attention_weights: &[f32], ) -> NumericalStabilityResult
Check attention entropy (F-NUM-001)
Attention should not collapse (entropy ≈ 0) or explode (uniform). Valid range: 0.1 < entropy < 0.9 * max_entropy
Sourcepub fn check_layernorm_output(&self, values: &[f32]) -> NumericalStabilityResult
pub fn check_layernorm_output(&self, values: &[f32]) -> NumericalStabilityResult
Check LayerNorm output (F-NUM-002)
LayerNorm output should have mean ≈ 0 and std ≈ 1
Sourcepub fn check_softmax_sum(
&self,
probabilities: &[f32],
) -> NumericalStabilityResult
pub fn check_softmax_sum( &self, probabilities: &[f32], ) -> NumericalStabilityResult
Check softmax output (F-NUM-003)
Softmax output must sum to 1.0 ± 1e-6
Sourcepub fn check_probability_range(
&self,
probabilities: &[f32],
) -> NumericalStabilityResult
pub fn check_probability_range( &self, probabilities: &[f32], ) -> NumericalStabilityResult
Check token probabilities (F-NUM-004)
All probabilities must be in range [0, 1]
Sourcepub fn check_dos_protection(
&self,
input: &str,
config: &DosProtectionConfig,
) -> DosCheckResult
pub fn check_dos_protection( &self, input: &str, config: &DosProtectionConfig, ) -> DosCheckResult
Check input for DoS attack patterns (F-SEC-003)
Detects: zip bombs, token floods, excessive repetition, oversized inputs
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PatternDetector
impl RefUnwindSafe for PatternDetector
impl Send for PatternDetector
impl Sync for PatternDetector
impl Unpin for PatternDetector
impl UnwindSafe for PatternDetector
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
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more