186186)
187187_BENIGN_AR_SCHEMA_FIELD_PATTERN = re .compile (
188188 r"""
189- \b(?:warnings?|disclaimers?|caveats?)\b(?:\[\])?\s+
190- (?:field|key|property|array|list|entry)\b
189+ ^\s*(?:\[\])?\s+(?:field|key|property|array|list|entry)\b
190+ |
191+ ^\s*(?:\[\])?\s+(?:in|of)\s+(?:the\s+)?(?:json(?:\s+output)?|output|response)\s+schema\b
191192 |
192- \b (?:warnings?|disclaimers?|caveats?)\b(?:\[\])?\s+
193- (?:in|of)\s+(?:the\s+)?(?:json(?:\s+output)?|output|response)\s+schema \b
193+ ^\s*(?:\[\])?\s+(?:in|of)\s+(?:the\s+)? (?:warnings?|disclaimers?|caveats?)\b(?:\[\])?\s+
194+ (?:field|key|property|array|list|entry) \b
194195 |
195- \b (?:warnings?|disclaimers?|caveats?)\b[^.\n]{0,80}\b(?:schema \s+field|schema \s+key|errors?\ [\]\s+array) \b
196+ ^\s* (?:\[\])? \s+in \s+(?:the\s+)?errors\ [\]\s+array\b
196197 """ ,
197198 re .IGNORECASE | re .VERBOSE ,
198199)
212213 re .IGNORECASE ,
213214)
214215_CLAUSE_BOUNDARY_PATTERN = re .compile (r"[.;!?]" )
215- _LIVE_RESPONSE_OBJECT_PATTERN = re .compile (
216- r"\b(?:answer|response|reply|assistant|user)\b" ,
217- re .IGNORECASE ,
218- )
219216_DEFENSIVE_AR_CONTEXT_PATTERN = re .compile (
220217 r"(?:^\s*(?:warning|note)\s*:|\b(?:malicious|example|attack|defensive)\s+"
221218 r"(?:phrase|payload|string|text|snippet|content|example)\b)" ,
222219 re .IGNORECASE ,
223220)
224221_RETROSPECTIVE_AR_NARRATIVE_PATTERNS = (
225222 re .compile (
226- r"\b(?:the|this|that)\s+(?:old|previous|prior)?\s* "
223+ r"\b(?:the|this|that)\s+(?:old|previous|prior)\s+ "
227224 r"(?:agent|model|system|implementation|version|behavior)\s+would\b" ,
228225 re .IGNORECASE ,
229226 ),
233230 ),
234231 re .compile (r"\bpreviously\s+would\b" , re .IGNORECASE ),
235232 re .compile (r"\bpreviously\s+used\s+to\b" , re .IGNORECASE ),
233+ re .compile (
234+ r"\bpreviously\s*,?\s+(?:the|this|that)\s+"
235+ r"(?:agent|model|system|implementation|version|behavior)\s+would\b" ,
236+ re .IGNORECASE ,
237+ ),
238+ re .compile (
239+ r"\b(?:fixed|resolved|addressed|corrected)\s+(?:a|the)\s+"
240+ r"(?:bug|issue|problem)\s+where\s+(?:the|this|that)\s+"
241+ r"(?:agent|model|system|implementation|version|behavior)\s+would\b" ,
242+ re .IGNORECASE ,
243+ ),
244+ re .compile (
245+ r"\b(?:the|this|that)\s+(?:agent|model|system|implementation|version|behavior)\s+"
246+ r"no\s+longer\s+(?:would|used\s+to)\b" ,
247+ re .IGNORECASE ,
248+ ),
249+ re .compile (
250+ r"\b(?:the|this|that)\s+(?:agent|model|system|implementation|version|behavior)\s+"
251+ r"would\s+no\s+longer\b" ,
252+ re .IGNORECASE ,
253+ ),
236254)
237- _SECOND_PERSON_NARRATIVE_PATTERN = re .compile (r"\byou\s+would\b" , re .IGNORECASE )
238255
239256
240257def _is_directly_instructive (context : str , matched_text : str ) -> bool :
@@ -338,21 +355,23 @@ def _is_match_local_narrative_clause(
338355) -> bool :
339356 """Return True when the current match is part of a narrative clause, not a directive."""
340357 prefix = match_clause [:clause_match_start ]
341- if _SECOND_PERSON_NARRATIVE_PATTERN .search (prefix ):
342- return False
343- return any (pattern .search (prefix ) for pattern in _RETROSPECTIVE_AR_NARRATIVE_PATTERNS )
358+ prefix_end = len (prefix .rstrip ())
359+ return any (
360+ (match := pattern .search (prefix )) is not None and match .end () == prefix_end
361+ for pattern in _RETROSPECTIVE_AR_NARRATIVE_PATTERNS
362+ )
344363
345364
346365def _is_schema_field_clause (
347366 match_clause : str ,
348367 matched_text : str ,
368+ clause_match_end : int ,
349369) -> bool :
350370 """Return True when an AR2 warning-suppression phrase targets schema fields."""
351371 if not _AR2_LIVE_SUPPRESSION_PATTERN .search (matched_text ):
352372 return False
353- if not _BENIGN_AR_SCHEMA_FIELD_PATTERN .search (match_clause ):
354- return False
355- return not _LIVE_RESPONSE_OBJECT_PATTERN .search (match_clause )
373+ continuation = match_clause [clause_match_end :]
374+ return bool (_BENIGN_AR_SCHEMA_FIELD_PATTERN .search (continuation ))
356375
357376
358377def _is_benign_ar_context (
@@ -363,14 +382,14 @@ def _is_benign_ar_context(
363382 previous_line : str | None = None ,
364383) -> bool :
365384 """Return True for high-confidence non-malicious prose patterns around one match span."""
366- match_clause , clause_match_start , _ = _match_clause (
385+ match_clause , clause_match_start , clause_match_end = _match_clause (
367386 match_line ,
368387 line_match_start ,
369388 line_match_end ,
370389 )
371390 if _is_match_local_narrative_clause (match_clause , clause_match_start ):
372391 return True
373- if _is_schema_field_clause (match_clause , match .lower ()):
392+ if _is_schema_field_clause (match_clause , match .lower (), clause_match_end ):
374393 return True
375394 return _is_quoted_match (match_line , match ) and _has_explicit_defensive_context (
376395 match_line ,
0 commit comments