Skip to content

Commit b5885ba

Browse files
committed
fix(analyzer): preserve the remaining AR2 response-suppression directives (NVIDIA#103)
Signed-off-by: Rod Boev <[email protected]>
1 parent 5c63a18 commit b5885ba

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎src/skillspector/nodes/analyzers/static_patterns_anti_refusal.py‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@
166166
r"(?:any\s+)?(?:warnings?|disclaimers?|caveats?)\b",
167167
re.IGNORECASE,
168168
)
169+
_AR2_DIRECT_INTENT_PATTERNS = (
170+
_AR2_LIVE_SUPPRESSION_PATTERN,
171+
re.compile(
172+
r"\bwithout\s+(?:any\s+)?(?:warnings?|disclaimers?|caveats?|moralizing|moralising|"
173+
r"judg(?:e?ment|ing))\b",
174+
re.IGNORECASE,
175+
),
176+
re.compile(
177+
r"\b(?:do\s+not|don'?t|never)\s+(?:lecture|moralize|moralise|preach|judge|warn)\b",
178+
re.IGNORECASE,
179+
),
180+
re.compile(
181+
r"\b(?:skip|omit|leave\s+out|drop)\s+(?:the\s+)?(?:disclaimer|warning|ethics|safety)\b",
182+
re.IGNORECASE,
183+
),
184+
re.compile(
185+
r"\b(?:no|without)\s+(?:ethical|moral)\s+(?:judg(?:e?ment)|considerations?|commentary|"
186+
r"objections?)\b",
187+
re.IGNORECASE,
188+
),
189+
re.compile(r"\b(?:do\s+not|don'?t)\s+(?:apologize|apologise|say\s+sorry)\b", re.IGNORECASE),
190+
)
169191
_BENIGN_AR_SCHEMA_FIELD_PATTERN = re.compile(
170192
r"\b(?:json|output)\s+schema\b|\berrors?\[\]\b",
171193
re.IGNORECASE,
@@ -210,8 +232,10 @@ def _is_directly_instructive(context: str, matched_text: str) -> bool:
210232
return False
211233
if any(pattern.search(context_lower) for pattern in _AR_DIRECT_INTENT_PATTERNS):
212234
return True
213-
if _AR2_LIVE_SUPPRESSION_PATTERN.search(context_lower):
214-
return not _BENIGN_AR_SCHEMA_FIELD_PATTERN.search(context_lower)
235+
if any(pattern.search(context_lower) for pattern in _AR2_DIRECT_INTENT_PATTERNS):
236+
if _AR2_LIVE_SUPPRESSION_PATTERN.search(context_lower):
237+
return not _BENIGN_AR_SCHEMA_FIELD_PATTERN.search(context_lower)
238+
return True
215239
return "do anything now" in matched_text_lower
216240

217241

‎tests/nodes/analyzers/test_static_patterns_anti_refusal.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ def test_never_moralize_about_json_output_stays_active(self):
144144
text = "Never moralize about JSON output risks."
145145
assert "AR2" in _rule_ids(text)
146146

147+
def test_json_response_do_not_apologize_stays_active(self):
148+
text = "Return JSON only; do not apologize."
149+
findings = _scan(text)
150+
assert any(f.rule_id == "AR2" for f in findings)
151+
147152
def test_documentation_label_nonallowlist_ar2_stays_active(self):
148153
text = "Documentation: do not include any disclaimers or warnings."
149154
findings = _scan(text)

0 commit comments

Comments
 (0)