Repository navigation
Conversation
Strix Security ReviewWarning This pull request has 25 commits after the last Strix review ( ✅ No open security findings. PR summary: Fixes LLM routing so that when an explicit provider is passed alongside a model string that repeats that provider's prefix (e.g. model="openai/gpt-4o", provider="openai"), the prefix is stripped before the model id is sent to the API, instead of being forwarded verbatim. Review summaryNo security issues found. The patch only changes the model identifier sent to the already-selected provider when a model string repeats that provider's prefix; provider selection, base_url/api_key resolution, and host targeting are all keyed off the unchanged explicit provider value, and the change is strictly subtractive (it can only remove a leading alias segment, never add one). DeepInfra's org/model validation now runs on the stripped id and is stricter, not weaker. Two independent traces through the native provider classes and LiteLLM fallback found no sink where the stripped value behaves differently in a security-relevant way. One non-security note for maintainers: the comparison uses the raw provider value, so alias spellings such as claude, google, aws, and azure_openai still fail to strip, leaving the original bug only partially fixed. Ruled out (2)
Review 1 on this PR · Reviewed by Strix |
4dc3d3d to
b9b25e9
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b9b25e9. Configure here.
|
Friendly ping for a review when you have a moment. Both Bugbot threads are resolved and the PR is mergeable; happy to adjust anything. |
The prefix strip compared a canonicalized model prefix against the raw provider kwarg, so alias spellings (claude, google, aws, azure_openai) never matched and their prefixed model ids were still sent to the API verbatim. Canonicalize both sides and cover the alias routes.
7353870 to
30fd598
Compare

Related issue
Fixes #8736
Summary
LLM(model="openai/gpt-4o", provider="openai")kept the full prefixed model string (openai/gpt-4o) and sent it verbatim to the API, which rejects it — whileLLM(model="openai/gpt-4o")correctly routes withgpt-4o. Theexplicit_providerbranch of_resolve_routenow strips the prefix when it canonicalizes viaPROVIDER_ALIASESto the same provider, mirroring the existing behavior of thecustom_openaibranch. Unrelated prefixes (e.g. a namespaced model id) are left untouched, and DeepInfra'sorg/modelvalidation now applies to the stripped id.Verification
lib/crewai/tests/test_llm.py(105 passed, 3 skipped): newtest_explicit_provider_strips_matching_model_prefixcovers openai/anthropic/deepinfra stripping, unrelated prefixes staying intact, malformed DeepInfra ids failing loudly, andkwargsnot being mutated.ruff checkclean on changed files.The rebase onto main pulled in #7459's
test_llm_explicit_deepinfra_provider_rejects_malformed_model, which asserted the old behavior formodel="deepinfra/deepseek-ai/...", provider="deepinfra"(and CI has not run yet, so it went unnoticed). Since stripping that redundant prefix is this PR's intent — mirroring the prefix-routing andcustom_openaipaths — the double-prefixed case moved into a new positive test (test_llm_explicit_deepinfra_provider_strips_matching_prefix, 7353870) and the genuinely malformed cases (no org part, trailing slash) stay in the rejection set.tests/llms/+tests/test_llm.py: 1192 passed, 23 skipped.Disclosure: this PR was produced with AI assistance (ZCode agent) and human-reviewed — please apply the
llm-generatedlabel.Additional context
None
From ZCode
Note
Medium Risk
Changes core LLM factory routing for every call with an explicit
provider, which determines the model string sent to provider APIs; behavior is narrowed and well tested but affects a hot path.Overview
Fixes a routing bug where
LLM(..., provider=...)kept a redundant provider prefix on the model id and sent it verbatim to native APIs (e.g.openai/gpt-4owithprovider="openai"), while unprefixed routing already usedgpt-4o.The
explicit_providerbranch in_resolve_routenow strips the first path segment when it canonicalizes (viaPROVIDER_ALIASES) to the same provider as the kwarg—including alias pairs likeclaude/anthropic,google/gemini,aws/bedrock, andazure_openai/azure. Unrelated prefixes (e.g. namespaced ids) are unchanged. DeepInfraorg/modelvalidation runs on the stripped id.Tests cover
_resolve_route, DeepInfra integration (including moving double-prefixeddeepinfra/...from malformed rejection to expected stripping), and kwargs immutability.Reviewed by Cursor Bugbot for commit 30fd598. Bugbot is set up for automated code reviews on this repo. Configure here.