Skip to content

fix: add 'anthropic/' prefix to model pattern matching#6049

Open
xlyoung wants to merge 1 commit into
crewAIInc:mainfrom
xlyoung:fix/anthropic-model-prefix-flexibility
Open

fix: add 'anthropic/' prefix to model pattern matching#6049
xlyoung wants to merge 1 commit into
crewAIInc:mainfrom
xlyoung:fix/anthropic-model-prefix-flexibility

Conversation

@xlyoung
Copy link
Copy Markdown

@xlyoung xlyoung commented Jun 5, 2026

Problem

Users with self-deployed Anthropic models use naming conventions like anthropic/claude-... (the standard LiteLLM routing format). The existing _matches_provider_pattern only recognized claude- and anthropic. prefixes, causing these models to be incorrectly filtered out when explicitly setting provider='anthropic'.

Fixes #5893

Fix

Added anthropic/ to the recognized prefix list for the anthropic provider in _matches_provider_pattern:

# Before
["claude-", "anthropic."]

# After
["claude-", "anthropic.", "anthropic/"]

This is backwards-compatible and handles the common LiteLLM model naming convention.

Summary by CodeRabbit

  • Bug Fixes
    • Anthropic model provider detection now supports the anthropic/ model name prefix format, in addition to existing naming patterns.

Users with self-deployed Anthropic models often use naming conventions
like 'anthropic/claude-...' (LiteLLM routing format). The existing
pattern matching only recognized 'claude-' and 'anthropic.' prefixes,
causing these models to be incorrectly filtered out.

Fixes crewAIInc#5893
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Extended the Anthropic provider pattern matching in LLM._matches_provider_pattern to recognize models prefixed with anthropic/, in addition to the existing claude- and anthropic. prefixes. This enables CrewAI to correctly identify custom-deployed Anthropic models using the anthropic/ naming convention.

Changes

Anthropic Provider Pattern Matching

Layer / File(s) Summary
Anthropic provider pattern matching extension
lib/crewai/src/crewai/llm.py
Updated _matches_provider_pattern method to recognize the anthropic/ prefix when identifying models as belonging to the Anthropic provider, expanding support beyond the prior claude- and anthropic. patterns.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A model by any prefix to roam,
Whether claude-, anthropic., or anthropic/ home,
CrewAI now sees them all,
No more models left behind in the hall,
Provider patterns dance, wide and free! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding the 'anthropic/' prefix to model pattern matching in the LLM provider matching logic.
Linked Issues check ✅ Passed The PR directly addresses issue #5893 by adding 'anthropic/' to the recognized prefix list for Anthropic models, solving the reported filtering issue.
Out of Scope Changes check ✅ Passed The changes are minimal and focused solely on updating the prefix pattern matching in LLM._matches_provider_pattern, directly aligned with the linked issue's requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
lib/crewai/src/crewai/llm.py (2)

114-114: ⚖️ Poor tradeoff

Consider using this constant to eliminate duplication.

The ANTHROPIC_PREFIXES constant is defined but not used in _matches_provider_pattern (line 459) or _is_anthropic_model (line 652), both of which define their own inline prefix lists. This leads to three different Anthropic prefix lists in the codebase:

  • Line 114: ("anthropic/", "claude-", "claude/")
  • Line 459: ["claude-", "anthropic.", "anthropic/"]
  • Line 652: ("anthropic/", "claude-", "claude/")

These lists have different contents ("claude/" vs "anthropic."), which could cause subtle bugs where one method recognizes a model but another doesn't.

Consider consolidating to a single source of truth, or documenting why different prefix sets are needed for different purposes.

🤖 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` at line 114, Replace the three inline Anthropic
prefix lists with the single source-of-truth constant ANTHROPIC_PREFIXES: update
_matches_provider_pattern and _is_anthropic_model to reference
ANTHROPIC_PREFIXES (or a derived normalized set if a variant is required), and
reconcile the differing entries ("anthropic.", "claude/") by deciding the
canonical prefixes and documenting/normalizing them before use so all checks use
the same prefix definitions.

652-653: ⚡ Quick win

Consider using startswith instead of in to avoid false positives.

The substring match (prefix in model.lower()) on line 653 is less precise than the prefix match (model_lower.startswith(prefix)) used in _matches_provider_pattern (line 458). This could cause false positives:

  • "my-provider/anthropic/claude-3" would incorrectly match as Anthropic
  • "openai/custom-claude-like" would incorrectly match as Anthropic

Additionally, this method's prefix list ("anthropic/", "claude-", "claude/") differs from _matches_provider_pattern's list ["claude-", "anthropic.", "anthropic/"] — notably missing the "anthropic." prefix while including "claude/".

🔍 Proposed fix to use startswith and align with _matches_provider_pattern
 `@staticmethod`
 def _is_anthropic_model(model: str) -> bool:
     """Determine if the model is from Anthropic provider.
     
     Args:
         model: The model identifier string.
     
     Returns:
         bool: True if the model is from Anthropic, False otherwise.
     """
-    anthropic_prefixes = ("anthropic/", "claude-", "claude/")
-    return any(prefix in model.lower() for prefix in anthropic_prefixes)
+    model_lower = model.lower()
+    anthropic_prefixes = ("anthropic/", "claude-", "anthropic.")
+    return any(model_lower.startswith(prefix) for prefix in anthropic_prefixes)
🤖 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 652 - 653, The current check uses
substring matching which can yield false positives; in the function defining
anthropic_prefixes and returning any(prefix in model.lower() ...), change to use
a lower-cased model variable (e.g., model_lower = model.lower()) and use
model_lower.startswith(prefix) instead of `in`, and align the prefix list with
_matches_provider_pattern by using prefixes ["claude-", "anthropic.",
"anthropic/"] (remove "claude/" and add "anthropic."). Ensure the updated logic
still returns any(model_lower.startswith(prefix) for prefix in
anthropic_prefixes).
🤖 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.

Nitpick comments:
In `@lib/crewai/src/crewai/llm.py`:
- Line 114: Replace the three inline Anthropic prefix lists with the single
source-of-truth constant ANTHROPIC_PREFIXES: update _matches_provider_pattern
and _is_anthropic_model to reference ANTHROPIC_PREFIXES (or a derived normalized
set if a variant is required), and reconcile the differing entries
("anthropic.", "claude/") by deciding the canonical prefixes and
documenting/normalizing them before use so all checks use the same prefix
definitions.
- Around line 652-653: The current check uses substring matching which can yield
false positives; in the function defining anthropic_prefixes and returning
any(prefix in model.lower() ...), change to use a lower-cased model variable
(e.g., model_lower = model.lower()) and use model_lower.startswith(prefix)
instead of `in`, and align the prefix list with _matches_provider_pattern by
using prefixes ["claude-", "anthropic.", "anthropic/"] (remove "claude/" and add
"anthropic."). Ensure the updated logic still returns
any(model_lower.startswith(prefix) for prefix in anthropic_prefixes).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 66726fda-e2dd-4bc7-9084-7a2b702581e8

📥 Commits

Reviewing files that changed from the base of the PR and between 906cd97 and c8a43e4.

📒 Files selected for processing (1)
  • lib/crewai/src/crewai/llm.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Model naming prefixes filtering is too strict

1 participant