fix(llm): catch "I am unable to" phrasing in refusal detection

The lexical pattern only matched the "I'm unable to" contraction, so
spelled-out refusals like "I am unable to comply with your instruction"
fell through undetected without an embedding model configured.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
James Veitch
2026-07-29 17:16:38 +01:00
co-authored by Claude Sonnet 5
parent 1f138e5991
commit 97249ee281
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ REFUSAL_LEXICAL_PATTERNS: tuple[re.Pattern, ...] = tuple(
for p in (
r"\bI\s*(?:'m|\s+am)?\s*(?:cannot|can't|won't|will not)\b[^.]{0,60}?\b"
r"(?:generate|create|produce|write|provide|help|assist|describe|depict|continue)\b",
r"\bI'm (?:not able|unable) to\b",
r"\bI(?:'m|\s+am) (?:not able|unable) to\b",
r"\bI don't feel comfortable\b",
r"\bI'm sorry,?\s*(?:but\s+)?I\s*(?:can't|cannot)\b",
r"\bas an AI\b[^.]{0,60}?\b(?:cannot|can't|unable|not able)\b",
+1
View File
@@ -50,6 +50,7 @@ class TestLexicalDetection:
blatant = [
"I cannot generate that image for you.",
"I'm not able to help with this request.",
"I am unable to comply with your instruction.",
"I don't feel comfortable creating this content.",
"I'm sorry, but I can't produce that description.",
"As an AI, I'm unable to depict this scenario.",