-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix: Minor logging uplift for debugging of prompt injection mitigation #7195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ struct DetailedScanResult { | |
| confidence: f32, | ||
| pattern_matches: Vec<PatternMatch>, | ||
| ml_confidence: Option<f32>, | ||
| used_pattern_detection: bool, | ||
| } | ||
|
|
||
| pub struct PromptInjectionScanner { | ||
|
|
@@ -160,9 +161,9 @@ impl PromptInjectionScanner { | |
| tool_confidence = %tool_result.confidence, | ||
| context_confidence = ?context_result.ml_confidence, | ||
| final_confidence = %final_confidence, | ||
| has_command_ml = tool_result.ml_confidence.is_some(), | ||
| has_prompt_ml = context_result.ml_confidence.is_some(), | ||
| has_patterns = !tool_result.pattern_matches.is_empty(), | ||
| used_command_ml = tool_result.ml_confidence.is_some(), | ||
| used_prompt_ml = context_result.ml_confidence.is_some(), | ||
| used_pattern_detection = tool_result.used_pattern_detection, | ||
| threshold = %threshold, | ||
| malicious = final_confidence >= threshold, | ||
| "Security analysis complete" | ||
|
|
@@ -172,6 +173,7 @@ impl PromptInjectionScanner { | |
| confidence: final_confidence, | ||
| pattern_matches: tool_result.pattern_matches, | ||
| ml_confidence: tool_result.ml_confidence, | ||
| used_pattern_detection: tool_result.used_pattern_detection, | ||
| }; | ||
|
|
||
| Ok(ScanResult { | ||
|
|
@@ -191,6 +193,7 @@ impl PromptInjectionScanner { | |
| confidence: ml_confidence, | ||
| pattern_matches: Vec::new(), | ||
| ml_confidence: Some(ml_confidence), | ||
| used_pattern_detection: false, | ||
| }); | ||
| } | ||
| } | ||
|
|
@@ -200,6 +203,7 @@ impl PromptInjectionScanner { | |
| confidence: pattern_confidence, | ||
| pattern_matches, | ||
| ml_confidence: None, | ||
| used_pattern_detection: true, | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -211,6 +215,7 @@ impl PromptInjectionScanner { | |
| confidence: 0.0, | ||
| pattern_matches: Vec::new(), | ||
| ml_confidence: None, | ||
| used_pattern_detection: false, | ||
| }); | ||
| }; | ||
|
|
||
|
|
@@ -219,6 +224,7 @@ impl PromptInjectionScanner { | |
| confidence: 0.0, | ||
| pattern_matches: Vec::new(), | ||
| ml_confidence: None, | ||
| used_pattern_detection: false, | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -237,6 +243,7 @@ impl PromptInjectionScanner { | |
| confidence: max_confidence, | ||
| pattern_matches: Vec::new(), | ||
| ml_confidence: Some(max_confidence), | ||
| used_pattern_detection: false, | ||
| }) | ||
|
Comment on lines
243
to
247
|
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
monotonic_counter.* = if enabled { 1 } else { 0 }is likely to produce confusing metrics (a counter with value 0 is typically a no-op and the name suggests a gauge); consider logging the booleans as normal fields (e.g.command_classifier_enabled = ...) and emitting a separatemonotonic_countermetric with value1(or separate enabled/disabled counters) so disabled configurations are still observable.