From a0f391f212f89943052043d7746b6323db665df1 Mon Sep 17 00:00:00 2001 From: James Veitch <1722315+darth-veitcher@users.noreply.github.com> Date: Wed, 29 Jul 2026 17:34:41 +0100 Subject: [PATCH] fix(llm): catch bare "cannot generate" phrasing without a leading "I" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lexical refusal pattern required an "I" before cannot/can't/won't so a refusal fragment like "Cannot generate this image due to the content" (no leading pronoun — the shape it takes as a JSON string value or a mid-sentence fragment) went undetected. Made the "I" prefix optional; the cannot/can't/won't-plus-nearby-generate/create/ etc. shape is specific enough that dropping the pronoun requirement doesn't pick up ordinary content (verified against the existing "ordinary content" regression cases). Co-Authored-By: Claude Sonnet 5 --- src/comfydv/_llm/retry.py | 2 +- tests/test_llm_retry.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/comfydv/_llm/retry.py b/src/comfydv/_llm/retry.py index 6c7ffad..fb60dcb 100644 --- a/src/comfydv/_llm/retry.py +++ b/src/comfydv/_llm/retry.py @@ -60,7 +60,7 @@ def next_seed(options: dict | None, attempt: int) -> int: REFUSAL_LEXICAL_PATTERNS: tuple[re.Pattern, ...] = tuple( re.compile(p, re.IGNORECASE) for p in ( - r"\bI\s*(?:'m|\s+am)?\s*(?:cannot|can't|won't|will not)\b[^.]{0,60}?\b" + r"\b(?:I\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|\s+am) (?:not able|unable) to\b", r"\bI don't feel comfortable\b", diff --git a/tests/test_llm_retry.py b/tests/test_llm_retry.py index f3ddee1..6ce6220 100644 --- a/tests/test_llm_retry.py +++ b/tests/test_llm_retry.py @@ -51,6 +51,8 @@ class TestLexicalDetection: "I cannot generate that image for you.", "I'm not able to help with this request.", "I am unable to comply with your instruction.", + "Cannot generate this image due to the sensitive content.", + '{"error": "cannot generate this content"}', "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.",