fix: prevent date-stamped model names from false no-prefill detection

The regex now limits the minor version capture to 1-2 digits so
names like claude-opus-4-20250514 are not misclassified as 4.20250514.
Added tests for date-stamped and Bedrock-style model IDs.

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2026-05-14 12:46:27 +00:00
parent 7c68e0e3f9
commit 6c26461cd4
3 changed files with 13 additions and 2 deletions

View File

@@ -2295,7 +2295,7 @@ class LLM(BaseLLM):
# Fallback heuristic for model names not in the litellm registry
model_lower = (self.model or "").lower()
if "claude" in model_lower:
match = re.search(r"claude.*?(\d+)[.-](\d+)", model_lower)
match = re.search(r"claude.*?(\d+)[.-](\d{1,2})(?!\d)", model_lower)
if match:
major, minor = int(match.group(1)), int(match.group(2))
if (major == 4 and minor >= 6) or major >= 5:

View File

@@ -1838,7 +1838,7 @@ class AnthropicCompletion(BaseLLM):
assistant prefill.
"""
model_lower = self.model.lower()
match = re.search(r"claude.*?(\d+)[.-](\d+)", model_lower)
match = re.search(r"claude.*?(\d+)[.-](\d{1,2})(?!\d)", model_lower)
if match:
major, minor = int(match.group(1)), int(match.group(2))
if (major == 4 and minor >= 6) or major >= 5:

View File

@@ -73,6 +73,17 @@ class TestAnthropicPrefillDetection:
llm = self._make_anthropic_llm("claude-5-0-opus")
assert llm.supports_assistant_prefill() is False
def test_date_stamped_claude_4_not_falsely_flagged(self):
"""claude-opus-4-20250514 should NOT be treated as 4.20250514."""
llm = self._make_anthropic_llm("claude-opus-4-20250514")
assert llm.supports_assistant_prefill() is True
def test_bedrock_date_stamped_model(self):
"""Bedrock-style IDs like claude-opus-4-20250514-v1:0 must not
be misclassified."""
llm = self._make_anthropic_llm("claude-opus-4-20250514-v1:0")
assert llm.supports_assistant_prefill() is True
# ---------------------------------------------------------------------------
# AnthropicCompletion temperature dropping