fix: support anthropic-- prefix in model name filtering#6356
fix: support anthropic-- prefix in model name filtering#6356C1-BA-B1-F3 wants to merge 1 commit into
Conversation
The _matches_provider_pattern method only recognized 'claude-' and 'anthropic.' prefixes for Anthropic models, causing self-hosted deployments using naming conventions like 'anthropic--claude-...' to be incorrectly rejected or routed to the wrong provider. Changes: - Add 'anthropic--' to the prefix list in _matches_provider_pattern - Add pattern-based fallback in _infer_provider_from_model for non-standard anthropic prefixes (claude-, anthropic., anthropic--) - Add tests for all three methods Fixes crewAIInc#5893
There was a problem hiding this comment.
Summary: This PR updates LLM provider detection to recognize an additional Anthropic model-name prefix and adds tests for that behavior.
Risk: Low risk. The changes do not introduce new authentication, authorization, file handling, subprocess execution, public endpoints, or user-controlled network targets, and no exploitable security vulnerabilities were identified.
📝 WalkthroughWalkthrough
ChangesAnthropic prefix handling
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/crewai/src/crewai/llm.py (1)
701-712: 📐 Maintainability & Code Quality | 🟡 MinorExtend
_is_anthropic_modelto match broadened Anthropic patterns.
_matches_provider_patternand_infer_provider_from_modelrecognizeanthropic--andanthropic.as Anthropic identifiers, but_is_anthropic_modelonly checks("anthropic/", "claude-", "claude/"). This causes models likeanthropic--my-deploy(withoutclaude) to incorrectly returnFalse, blocking the litellm fallback's Anthropic-specific "first message must be user" handling.Update
lib/crewai/src/crewai/llm.pylines 701‑712:✅ Suggested fix
- anthropic_prefixes = ("anthropic/", "claude-", "claude/") + anthropic_prefixes = ("anthropic/", "anthropic--", "anthropic.", "claude-", "claude/")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/crewai/src/crewai/llm.py` around lines 701 - 712, The _is_anthropic_model helper in crewai.llm currently misses the broader Anthropic naming variants already handled elsewhere, so models like anthropic--my-deploy and anthropic.my-deploy return false. Update the prefix check in _is_anthropic_model to align with _matches_provider_pattern and _infer_provider_from_model by recognizing the Anthropic-specific forms, while keeping the existing claude-based matches. This will ensure litellm fallback logic in the LLM path correctly applies Anthropic-only handling for first-message validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@lib/crewai/src/crewai/llm.py`:
- Around line 701-712: The _is_anthropic_model helper in crewai.llm currently
misses the broader Anthropic naming variants already handled elsewhere, so
models like anthropic--my-deploy and anthropic.my-deploy return false. Update
the prefix check in _is_anthropic_model to align with _matches_provider_pattern
and _infer_provider_from_model by recognizing the Anthropic-specific forms,
while keeping the existing claude-based matches. This will ensure litellm
fallback logic in the LLM path correctly applies Anthropic-only handling for
first-message validation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fdcfa8e5-9f55-4292-b2fb-0f547b2d6be0
📒 Files selected for processing (2)
lib/crewai/src/crewai/llm.pylib/crewai/tests/test_llm.py
Problem
The
_matches_provider_patternmethod only recognizesclaude-andanthropic.prefixes for Anthropic models. Self-hosted deployments using naming conventions likeanthropic--claude-...are incorrectly rejected or routed to the wrong provider.Fixes #5893
Changes
lib/crewai/src/crewai/llm.py(2 changes):_matches_provider_pattern: Added"anthropic--"to the Anthropic prefix list so models likeanthropic--claude-3-5-sonnetpass validation._infer_provider_from_model: Added a pattern-based fallback after the constants check, so unprefixed models with non-standard Anthropic naming conventions (e.g.anthropic--claude-3-5-sonnet) are correctly inferred as Anthropic instead of defaulting to OpenAI.lib/crewai/tests/test_llm.py(3 new tests):test_anthropic_double_dash_prefix_uses_native_sdk— end-to-end routing testtest_infer_provider_from_model_anthropic_prefixes— provider inference testtest_validate_model_in_constantswithanthropic--prefix assertionsTesting
All 3 new tests pass, plus all existing anthropic-related tests remain green.
Summary by CodeRabbit
Bug Fixes
Tests