fix: match stop_reason (underscore) variant in sensitive detection regex

The regex only matched 'stop reason' (space) but some error text uses the canonical key form 'stop_reason' (underscore). Use [_ ] character class to match both.
This commit is contained in:
MoerAI 2026-03-17 20:02:46 +09:00
parent 484d8bbe79
commit 4fea80126d

View File

@ -109,7 +109,7 @@ const ANTHROPIC_MAGIC_STRING_REPLACEMENT = "ANTHROPIC MAGIC STRING TRIGGER REFUS
// Detect model safety-filter rejections (stop_reason: sensitive).
// This is NOT a timeout — it is a content policy block that requires a user-facing message.
const SENSITIVE_STOP_REASON_RE =
/\bunhandled\s+stop reason:\s*sensitive\b|\bstop reason:\s*sensitive\b|\breason:\s*sensitive\b/i;
/\bunhandled\s+stop[_ ]reason:\s*sensitive\b|\bstop[_ ]reason:\s*sensitive\b|\breason:\s*sensitive\b/i;
function scrubAnthropicRefusalMagic(prompt: string): string {
if (!prompt.includes(ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL)) {