|
153 | 153 | re.compile(r"\bact\s+as\s+\w+", re.IGNORECASE), |
154 | 154 | re.compile(r"\balways\s+comply\b", re.IGNORECASE), |
155 | 155 | ) |
| 156 | +_AR2_LIVE_SUPPRESSION_PATTERN = re.compile( |
| 157 | + r"\b(?:do\s+not|don'?t|never|no)\s+(?:include|add|give|provide|use|append)?\s*" |
| 158 | + r"(?:any\s+)?(?:warnings?|disclaimers?|caveats?)\b", |
| 159 | + re.IGNORECASE, |
| 160 | +) |
| 161 | +_BENIGN_AR_SCHEMA_FIELD_PATTERN = re.compile( |
| 162 | + r"\b(?:json|output)\s+schema\b|\berrors?\[\]\b", |
| 163 | + re.IGNORECASE, |
| 164 | +) |
156 | 165 |
|
157 | 166 | _BENIGN_AR_VALUE_LABEL_PATTERN = re.compile( |
158 | 167 | r"^\s*(?:[-*]\s*)?(?:warnings?|disclaimers?|description)\s*:\s*", |
|
172 | 181 | r"^\s*(?:deny-?list|tool)\s+declaration\s*:\s*", |
173 | 182 | re.IGNORECASE, |
174 | 183 | ) |
| 184 | +_BENIGN_AR_TOOL_FIELD_PATTERN = re.compile(r"^\s*tool\s*:\s*\S", re.IGNORECASE) |
| 185 | +_BENIGN_AR_DESCRIPTION_FIELD_PATTERN = re.compile(r"^\s*description\s*:\s*", re.IGNORECASE) |
175 | 186 | _BENIGN_AR_FIXTURE_INTRO_PATTERN = re.compile( |
176 | 187 | r"^\s*(?:#\s*)?(?:defensive\s+fixture|unit\s+test|test\s+case)\b", |
177 | 188 | re.IGNORECASE, |
|
185 | 196 | def _is_directly_instructive(context: str, matched_text: str) -> bool: |
186 | 197 | """Return True when the match still looks like an active adversarial instruction.""" |
187 | 198 | context_lower = context.lower() |
| 199 | + matched_text_lower = matched_text.lower() |
188 | 200 | if re.search(r"\bwould\s+always\s+comply\b", context_lower): |
189 | 201 | return False |
190 | 202 | if any(pattern.search(context_lower) for pattern in _AR_DIRECT_INTENT_PATTERNS): |
191 | 203 | return True |
192 | | - return "do anything now" in matched_text.lower() |
| 204 | + if _AR2_LIVE_SUPPRESSION_PATTERN.search(context_lower): |
| 205 | + return not _BENIGN_AR_SCHEMA_FIELD_PATTERN.search(context_lower) |
| 206 | + return "do anything now" in matched_text_lower |
193 | 207 |
|
194 | 208 |
|
195 | 209 | def _is_explicit_example_context(context: str) -> bool: |
@@ -221,11 +235,13 @@ def _is_quoted_or_labeled_benign_match( |
221 | 235 | return True |
222 | 236 | if _BENIGN_AR_DECLARATION_INLINE_PATTERN.search(match_line_lower): |
223 | 237 | return True |
224 | | - if _BENIGN_AR_VALUE_LABEL_PATTERN.search(match_line_lower): |
225 | | - return True |
226 | 238 | if not previous_line: |
227 | 239 | return False |
228 | 240 | previous_line_lower = previous_line.lower() |
| 241 | + if _BENIGN_AR_TOOL_FIELD_PATTERN.search( |
| 242 | + previous_line_lower |
| 243 | + ) and _BENIGN_AR_DESCRIPTION_FIELD_PATTERN.search(match_line_lower): |
| 244 | + return True |
229 | 245 | if _BENIGN_AR_WARNING_INTRO_PATTERN.search(previous_line_lower): |
230 | 246 | return quoted_match |
231 | 247 | if _BENIGN_AR_CONTINUATION_LABEL_PATTERN.search(previous_line_lower): |
@@ -260,6 +276,10 @@ def _is_benign_ar_context( |
260 | 276 | or _BENIGN_AR_CONTINUATION_LABEL_PATTERN.search(previous_line_lower) |
261 | 277 | or _BENIGN_AR_DECLARATION_INTRO_PATTERN.search(previous_line_lower) |
262 | 278 | or _BENIGN_AR_FIXTURE_INTRO_PATTERN.search(previous_line_lower) |
| 279 | + or ( |
| 280 | + _BENIGN_AR_TOOL_FIELD_PATTERN.search(previous_line_lower) |
| 281 | + and _BENIGN_AR_DESCRIPTION_FIELD_PATTERN.search(match_line) |
| 282 | + ) |
263 | 283 | ) |
264 | 284 | if re.search(r"\bwould\s+always\s+comply\b", match_line_lower): |
265 | 285 | return True |
|
0 commit comments