-
Notifications
You must be signed in to change notification settings - Fork 477
feat: add RailException support and improve error handling #1178
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
Conversation
- Add TypedDict for structured return values - implement RailException for injection detection (a must have for checks) - improve error handling for malformed YARA rules
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.
Pull Request Overview
This pull request enhances the injection detection system by introducing structured return values using a new TypedDict and improving error handling for malformed YARA rules.
- Introduced InjectionDetectionResult for structured detection output
- Updated injection detection functions (_omit_injection, _sanitize_injection, _reject_injection) to return tuples for consistency
- Improved error handling in _load_rules to log YARA compilation errors gracefully and updated tests accordingly
Reviewed Changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
tests/test_injection_detection.py | Updated tests to match new injection detection return types and added cases for RailException handling and graceful failure for malformed YARA rules. |
nemoguardrails/library/injection_detection/actions.py | Added InjectionDetectionResult TypedDict, updated injection detection functions to return tuples, and improved error messaging in _load_rules. |
Files not reviewed (2)
- nemoguardrails/library/injection_detection/flows.co: Language not supported
- nemoguardrails/library/injection_detection/flows.v1.co: Language not supported
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1178 +/- ##
===========================================
+ Coverage 68.24% 68.44% +0.19%
===========================================
Files 161 161
Lines 15938 15948 +10
===========================================
+ Hits 10877 10915 +38
+ Misses 5061 5033 -28
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
This looks good to me, thanks!
Summary by GH Copilot
This pull request enhances the injection detection system by introducing a structured return type, improving error handling, and adding new tests for edge cases. The changes aim to make the system more robust and easier to integrate into workflows.
Code Enhancements
TypedDict
namedInjectionDetectionResult
to standardize the return type for injection detection functions, containingis_injection
,text
, anddetections
fields. (nemoguardrails/library/injection_detection/actions.py
, nemoguardrails/library/injection_detection/actions.pyR52-R57)_omit_injection
,_sanitize_injection
, and_reject_injection
functions to return structured tuples or lists for better clarity and integration. (nemoguardrails/library/injection_detection/actions.py
, [1] [2] [3]Improved Error Handling
nemoguardrails/library/injection_detection/actions.py
, nemoguardrails/library/injection_detection/actions.pyL200-R212)tests/test_injection_detection.py
, tests/test_injection_detection.pyR623-R768)Flow Updates
.co
files to use the newInjectionDetectionResult
format, improving clarity and handling of different actions (reject
,omit
,sanitize
). (nemoguardrails/library/injection_detection/flows.co
, [1];nemoguardrails/library/injection_detection/flows.v1.co
, [2]Testing Improvements
tests/test_injection_detection.py
, tests/test_injection_detection.pyR623-R768)tests/test_injection_detection.py
, [1] [2]