pub struct PromptValidator;Expand description
Validates prompts against configurable rules and detects injection attacks.
Implementations§
Source§impl PromptValidator
impl PromptValidator
Sourcepub fn validate(
&self,
prompt: &str,
rules: &[ValidationRule],
) -> ValidationReport
pub fn validate( &self, prompt: &str, rules: &[ValidationRule], ) -> ValidationReport
Validate prompt against each rule, returning a ValidationReport.
Sourcepub fn detect_injection(prompt: &str) -> Vec<(InjectionPattern, f64)>
pub fn detect_injection(prompt: &str) -> Vec<(InjectionPattern, f64)>
Detect injection patterns in prompt, returning (pattern, confidence) pairs.
Sourcepub fn estimate_tokens(text: &str) -> usize
pub fn estimate_tokens(text: &str) -> usize
Estimate token count using the ~4 chars/token heuristic.
Sourcepub fn check_repetition(text: &str) -> f64
pub fn check_repetition(text: &str) -> f64
Compute the fraction of repeated 3-grams (words) in text. Returns 0.0–1.0.
Sourcepub fn check_language(text: &str, expected: &str) -> bool
pub fn check_language(text: &str, expected: &str) -> bool
Simple language heuristic using character frequency analysis.
For expected = "en" it checks for a high ratio of ASCII letters.
For any other value it always returns true (not implemented).
Sourcepub fn safety_score(issues: &[PromptIssue]) -> f64
pub fn safety_score(issues: &[PromptIssue]) -> f64
Compute a safety score from 1.0 (no issues) down to 0.0 using weighted penalties.
Sourcepub fn suggest_fixes(issues: &[PromptIssue]) -> Vec<String>
pub fn suggest_fixes(issues: &[PromptIssue]) -> Vec<String>
Generate actionable fix suggestions for a list of issues.
Sourcepub fn sanitize(prompt: &str) -> String
pub fn sanitize(prompt: &str) -> String
Remove detected injection patterns from prompt, returning a sanitised copy.
Sourcepub fn batch_validate(
&self,
prompts: &[&str],
rules: &[ValidationRule],
) -> Vec<ValidationReport>
pub fn batch_validate( &self, prompts: &[&str], rules: &[ValidationRule], ) -> Vec<ValidationReport>
Validate a batch of prompts against the same rules.
Trait Implementations§
Source§impl Clone for PromptValidator
impl Clone for PromptValidator
Source§fn clone(&self) -> PromptValidator
fn clone(&self) -> PromptValidator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PromptValidator
impl Debug for PromptValidator
Source§impl Default for PromptValidator
impl Default for PromptValidator
Source§fn default() -> PromptValidator
fn default() -> PromptValidator
Auto Trait Implementations§
impl Freeze for PromptValidator
impl RefUnwindSafe for PromptValidator
impl Send for PromptValidator
impl Sync for PromptValidator
impl Unpin for PromptValidator
impl UnsafeUnpin for PromptValidator
impl UnwindSafe for PromptValidator
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request