Skip to content

feat: add support for custom provider prefixes#5966

Open
Eashant3835 wants to merge 2 commits into
crewAIInc:mainfrom
Eashant3835:feature/custom-provider-prefixes
Open

feat: add support for custom provider prefixes#5966
Eashant3835 wants to merge 2 commits into
crewAIInc:mainfrom
Eashant3835:feature/custom-provider-prefixes

Conversation

@Eashant3835
Copy link
Copy Markdown

@Eashant3835 Eashant3835 commented May 28, 2026

Title: feat: add support for custom LLM provider prefixes

Description:
This PR adds support for custom LLM provider prefixes, enabling the LLM class to recognize and route proprietary or custom model naming conventions. This increases the flexibility of the LLM integration for users working with custom-prefixed models.

Changes:

Updated LLM.PROVIDER_PREFIXES to include custom prefix definitions.

Added ClassVar type annotation to PROVIDER_PREFIXES to resolve Pydantic validation errors (PydanticUserError).

Testing performed:

Created a verification script to validate _matches_provider_pattern logic.

Verified that custom prefixes are correctly identified and handled without triggering schema validation errors.

Summary by CodeRabbit

  • New Features
    • LLM model-name matching now supports runtime customization via the CREWAI_LLM_PREFIXES environment variable to extend allowed model prefixes.
  • Chores
    • Added a small verification script to demonstrate and test custom prefix behavior locally.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c4006b4-8c15-4ea3-a385-45ae10b1dbf8

📥 Commits

Reviewing files that changed from the base of the PR and between 14429df and d6fa99b.

📒 Files selected for processing (1)
  • lib/crewai/src/crewai/llm.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/crewai/src/crewai/llm.py

📝 Walkthrough

Walkthrough

The LLM class refactors its provider-pattern matching logic to use a centralized PROVIDER_PREFIXES registry mapping providers to allowed model-name prefixes. The _matches_provider_pattern method now consults this registry and supports runtime prefix extension via the CREWAI_LLM_PREFIXES environment variable. A verification script demonstrates the updated behavior.

Changes

Provider Pattern Matching Refactoring

Layer / File(s) Summary
Provider prefix registry schema
lib/crewai/src/crewai/llm.py
ClassVar import is added and LLM.PROVIDER_PREFIXES is defined as a centralized registry mapping canonical provider names to lists of allowed model-name prefixes, including wildcard entries.
Pattern matching implementation with registry lookup and environment extension
lib/crewai/src/crewai/llm.py
_matches_provider_pattern is refactored to look up allowed prefixes from PROVIDER_PREFIXES, immediately match wildcard patterns, and dynamically extend the prefix list from the CREWAI_LLM_PREFIXES environment variable before validating the model name.
Runtime verification script
verify_prefix.py
Standalone script configures CREWAI_LLM_PREFIXES as an environment variable, calls _matches_provider_pattern with a custom model/provider pair, and prints success or failure output to demonstrate the refactored behavior.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 A registry born to order the chaos of prefixes,
Patterns once hardcoded now dance with flexibility,
The env whispers new prefixes into the LLM's ear,
A small script checks the match and cheers aloud,
Custom models hop in where rigid rules once stood.

🚥 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 'feat: add support for custom provider prefixes' accurately describes the main objective of the changeset—adding support for custom LLM provider prefixes through a new PROVIDER_PREFIXES registry and environment variable support.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
verify_prefix.py (1)

1-19: 💤 Low value

Consider relocating verification script or removing after merge.

This script in the repo root is useful for development verification but may cause confusion if left permanently. Consider:

  1. Moving to tests/ or scripts/ directory with appropriate naming
  2. Converting to a proper unit test in the test suite
  3. Removing after PR validation if it's intended as a one-off check
🤖 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 `@verify_prefix.py` around lines 1 - 19, The verification script
verify_prefix.py is a development-only helper that should not remain in the repo
root; move it into a non-production location (e.g., tests/ or scripts/) or
convert it to a unit test, or remove it after the PR. Specifically, relocate the
file or add it as a proper test that calls LLM._matches_provider_pattern (from
crewai.llm) and uses environment setup only within the test, or delete the
script if it was a one-off check to avoid confusing users and CI.
🤖 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.

Inline comments:
In `@lib/crewai/src/crewai/llm.py`:
- Around line 467-470: Custom prefixes loaded from CREWAI_LLM_PREFIXES are added
as-is causing case-sensitive mismatches with the lowercased model name; update
the logic that appends custom_prefixes to allowed_prefixes (the variable
handling the prefixes) to normalize each entry by trimming whitespace and
lowercasing them before extending allowed_prefixes (e.g., split the env var,
strip and lower each non-empty prefix, then add to allowed_prefixes).
- Line 324: The bedrock provider currently uses an invalid prefix list
("bedrock": ["."]) so _matches_provider_pattern (which calls
model_lower.startswith(prefix)) never matches real Bedrock model IDs; update the
Bedrock prefixes in the same mapping where "bedrock": ["." ] appears to a list
of realistic Bedrock ID starts (e.g., "us.", "eu.", "apac.", "global.",
"amazon.", "anthropic.", "meta.", "aws.", and any other known region/vendor
prefixes you support) or change the matching strategy in
_matches_provider_pattern to support substring/regex matching for Bedrock IDs;
reference the mapping key "bedrock" and the function _matches_provider_pattern
to locate and fix the logic so models like "us.amazon.nova-pro-v1:0" validate
correctly.

---

Nitpick comments:
In `@verify_prefix.py`:
- Around line 1-19: The verification script verify_prefix.py is a
development-only helper that should not remain in the repo root; move it into a
non-production location (e.g., tests/ or scripts/) or convert it to a unit test,
or remove it after the PR. Specifically, relocate the file or add it as a proper
test that calls LLM._matches_provider_pattern (from crewai.llm) and uses
environment setup only within the test, or delete the script if it was a one-off
check to avoid confusing users and CI.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d1747832-8451-4d6f-ac36-8160f90015dc

📥 Commits

Reviewing files that changed from the base of the PR and between fca21b1 and 14429df.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • lib/crewai/src/crewai/llm.py
  • verify_prefix.py

Comment thread lib/crewai/src/crewai/llm.py Outdated
Comment thread lib/crewai/src/crewai/llm.py Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

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.

1 participant