Update middleware to use FunctionGroup.SEPARATOR for function matching#1448
Conversation
WalkthroughConfiguration files, middleware logic, and test files are updated to replace dot-based function group naming with double-underscore separation using Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
mnajafian-nv
left a comment
There was a problem hiding this comment.
LGTM, I have 2 questions, otherwise this is good to go.
-
Fix: The retail agent README still has the old separator format in multiple places. Users will copy these examples and get broken configs: e.g. find
retail_tools.get_product_infond replace withretail_tools__get_product_infoin examples/safety_and_security/retail_agent/README.md -
Question: What's the deal with
eval_dataset.jsonbeing added? It's not mentioned in the PR description and seems unrelated. Can you please add a quick note explaining why it's here (or remove if it snuck in accidentally).
willkill07
left a comment
There was a problem hiding this comment.
If the existing tests failed to detect that functions weren't being intercepted, then we need to have an appropriate e2e test that does actually verify interception.
I also don't see any new test adequately ensuring that interception is occurring.
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tests/nat/middleware/test_defense_middleware.py`:
- Around line 612-615: The test contains a duplicated assertion asserting
middleware._last_field_info is None; remove the redundant line so only one
assert middleware._last_field_info is None remains (keep the surrounding
assertions for middleware._last_extracted_content and the single
_last_field_info check) to eliminate the duplicate check.
Signed-off-by: Eric Evans <194135482+ericevans-nv@users.noreply.github.com>
…s to the new seperator Signed-off-by: Eric Evans <194135482+ericevans-nv@users.noreply.github.com>
6209078 to
1beeedb
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/nat/middleware/defense/defense_middleware.py (1)
74-78: Docstring examples use outdated separator format.The
target_function_or_groupfield docstring still shows examples with the old.separator ('my_calculator.divide','llm_agent.generate'), but the middleware now usesFunctionGroup.SEPARATOR(__). Update the examples to reflect the new format.📝 Suggested fix
target_function_or_group: str | None = Field( default=None, description="Optional function or function group to target. " "If None, defense applies to all functions. " - "Examples: 'my_calculator', 'my_calculator.divide', 'llm_agent.generate'") + "Examples: 'my_calculator', 'my_calculator__divide', 'llm_agent__generate'")
mnajafian-nv
left a comment
There was a problem hiding this comment.
LGTM! Thanks for addressing the comments :)
|
I removed dep-approvers because they own no files on this PR |
|
/merge |
Description
This PR updates the function separator used in red teaming and defense middleware from
.to__to align withFunctionGroup.SEPARATOR. This fixes a bug introduced when the function group separator was changed, which caused middleware to no longer match registered function names. This broke red teaming and defense middleware functionality since they could not intercept the target functions. Updated the middleware matching logic to useFunctionGroup.SEPARATORand updated the example configuration files and tests to use the new separator format.By Submitting this PR I confirm:
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.