Skip to content

fix: support anthropic-- prefix in model name filtering#6356

Open
C1-BA-B1-F3 wants to merge 1 commit into
crewAIInc:mainfrom
C1-BA-B1-F3:fix/anthropic-model-prefix-filtering
Open

fix: support anthropic-- prefix in model name filtering#6356
C1-BA-B1-F3 wants to merge 1 commit into
crewAIInc:mainfrom
C1-BA-B1-F3:fix/anthropic-model-prefix-filtering

Conversation

@C1-BA-B1-F3

@C1-BA-B1-F3 C1-BA-B1-F3 commented Jun 26, 2026

Copy link
Copy Markdown

Problem

The _matches_provider_pattern method only recognizes claude- and anthropic. prefixes for Anthropic models. Self-hosted deployments using naming conventions like anthropic--claude-... are incorrectly rejected or routed to the wrong provider.

Fixes #5893

Changes

lib/crewai/src/crewai/llm.py (2 changes):

  1. _matches_provider_pattern: Added "anthropic--" to the Anthropic prefix list so models like anthropic--claude-3-5-sonnet pass validation.

  2. _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 test
  • test_infer_provider_from_model_anthropic_prefixes — provider inference test
  • Extended test_validate_model_in_constants with anthropic-- prefix assertions

Testing

All 3 new tests pass, plus all existing anthropic-related tests remain green.

Summary by CodeRabbit

  • Bug Fixes

    • Improved model-provider detection for additional Anthropic model name formats, including double-dash prefixes.
    • Better fallback provider inference now recognizes more Anthropic-style model names instead of defaulting incorrectly.
    • Preserved the original model name while using the native Anthropic path when applicable.
  • Tests

    • Added coverage for Anthropic double-dash model prefixes and provider inference behavior.
    • Expanded validation checks for supported Anthropic model naming patterns.

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

@corridor-security corridor-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

LLM now recognizes anthropic-- as an Anthropic prefix in provider matching and inference. Tests were added to cover native Anthropic routing and validation for anthropic-- model names.

Changes

Anthropic prefix handling

Layer / File(s) Summary
Provider prefix handling and tests
lib/crewai/src/crewai/llm.py, lib/crewai/tests/test_llm.py
LLM accepts anthropic-- in Anthropic prefix checks and fallback inference, and tests cover native Anthropic routing plus validation of anthropic-- model names.
🚥 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 clearly summarizes the main change: supporting the anthropic-- model prefix in model-name filtering.
Linked Issues check ✅ Passed The changes address #5893 by broadening Anthropic prefix matching and provider inference, with tests covering the new naming pattern.
Out of Scope Changes check ✅ Passed The PR stays focused on Anthropic prefix handling and related tests, with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 | 🟡 Minor

Extend _is_anthropic_model to match broadened Anthropic patterns.

_matches_provider_pattern and _infer_provider_from_model recognize anthropic-- and anthropic. as Anthropic identifiers, but _is_anthropic_model only checks ("anthropic/", "claude-", "claude/"). This causes models like anthropic--my-deploy (without claude) to incorrectly return False, blocking the litellm fallback's Anthropic-specific "first message must be user" handling.

Update lib/crewai/src/crewai/llm.py lines 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

📥 Commits

Reviewing files that changed from the base of the PR and between f364a7d and 7bad52a.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/llm.py
  • lib/crewai/tests/test_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