diff --git a/lib/crewai/src/crewai/llm.py b/lib/crewai/src/crewai/llm.py index c18c08025..18a96c136 100644 --- a/lib/crewai/src/crewai/llm.py +++ b/lib/crewai/src/crewai/llm.py @@ -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: diff --git a/lib/crewai/src/crewai/llms/providers/anthropic/completion.py b/lib/crewai/src/crewai/llms/providers/anthropic/completion.py index 986e90a4c..cbd95df69 100644 --- a/lib/crewai/src/crewai/llms/providers/anthropic/completion.py +++ b/lib/crewai/src/crewai/llms/providers/anthropic/completion.py @@ -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: diff --git a/lib/crewai/tests/agents/test_claude_opus_4_7_support.py b/lib/crewai/tests/agents/test_claude_opus_4_7_support.py index c2d67f23a..6068d49db 100644 --- a/lib/crewai/tests/agents/test_claude_opus_4_7_support.py +++ b/lib/crewai/tests/agents/test_claude_opus_4_7_support.py @@ -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