Repository navigation
fix(fallback-generalizations): anchor bedrock-claude-ids and restrict routing rules to bare ids - #32990
fix(fallback-generalizations): anchor bedrock-claude-ids and restrict routing rules to bare ids#32990yucheng-berri wants to merge 1 commit into
Conversation
… routing rules to bare ids
Greptile SummaryThis PR fixes a routing regex in
Confidence Score: 5/5Safe to merge — the change is tightly scoped to routing-generalization fallback and does not touch any other provider resolution path. Both fix layers (JSON pattern anchoring and Python slash guard) are correct and complementary. The existing test_shipped_bedrock_syntax_claude_id_routes_to_bedrock test covers all current Bedrock region-prefix forms against the anchored pattern, so no regression in legitimate routing. The two new tests are mock-only and directly pin the fixed failure modes. No pre-existing tests are weakened. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/get_llm_provider_logic.py | Adds a "/" not in model guard so routing-generalization fallback is only consulted for bare IDs, preventing slash-namespaced foreign providers from being incorrectly resolved via a matching rule. |
| model_prices_and_context_window.json | Anchors the bedrock-claude-ids routing rule pattern from anthropic\.claude- to ^(?:[a-z-]+\.)?anthropic\.claude-, preventing it from matching slash-prefixed IDs under foreign namespaces via re.search. |
| litellm/model_prices_and_context_window_backup.json | Mirror of the same bedrock-claude-ids pattern anchoring applied to the bundled/backup cost map. |
| tests/test_litellm/litellm_core_utils/test_fallback_generalizations.py | Adds two regression tests: one verifying the slash guard in get_llm_provider raises for unknown slash-prefixed IDs even when a rule matches, and one verifying the anchored bedrock-claude-ids rule no longer matches foreign-namespace IDs like bedrockz/anthropic.claude-.... |
Reviews (1): Last reviewed commit: "fix(fallback-generalizations): anchor be..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Relevant issues
Every PR's "Unit Tests: Proxy Legacy Tests / auth-and-jwt" job started failing at 2026-07-12 00:43 UTC on two model-access deny params (
bedrockz/anthropic.claude-3-5-sonnet-20240620against key/team models['bedrock/*']), for example https://github.com/BerriAI/litellm/actions/runs/29174424786/job/86600954535. The failures show up on branches whose diffs cannot affect auth, which is what pointed to shared state rather than any PR's changesLinear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Live proxy on this branch, default cost-map behavior (no
LITELLM_LOCAL_MODEL_COST_MAP, so the proxy fetched the current, still unanchored map from main at boot; the deny below is the new bare-id guard inget_llm_providerbehaving exactly as an upgraded customer proxy would). Config is abedrock/*wildcard deployment, the deployment shape this regression affectsA key scoped to
bedrock/*must not reachbedrockz/...(this returned a completion-path error before the fix because auth let it through; it now fails auth)The same key still reaches real Bedrock through the wildcard (live AWS call, not mocked)
Type
🐛 Bug Fix
Changes
The
fallback_generalizationsblock introduced in #32873 ships a routing rule namedbedrock-claude-idswith the unanchored patternanthropic\.claude-. Rules match withre.search, so the rule also fires inside ids under a foreign provider namespace such asbedrockz/anthropic.claude-3-5-sonnet-20240620.get_llm_providerthen resolves that id to providerbedrock, and_model_custom_llm_provider_matches_wildcard_patterninauth_checks.pyrewrites it asbedrock/anthropic.claude-3-5-sonnet-20240620, so keys and teams scoped tobedrock/*passed the model access check for ids they should never reach. The staging sync #32884 (merged 2026-07-12 00:42:56 UTC) published the rule to main'smodel_prices_and_context_window.json, which every proxy and CI job withoutLITELLM_LOCAL_MODEL_COST_MAPfetches at import; that is why auth-and-jwt went red on every PR at 00:43 with no related diff anywhereThe fix has two layers. The rule's pattern is now anchored as
^(?:[a-z-]+\.)?anthropic\.claude-, which still covers bare, region-prefixed (us./eu./au./jp./apac./us-gov.) and global.-prefixed Bedrock ids but no longer matches slash-namespaced ids; this is the layer that heals released proxies, which fetch main's copy remotely and have no code from this PR. Separately,get_llm_providernow consults routing generalizations only for bare ids: a slash means an explicit provider prefix that already failed every provider lookup, and that keeps raisingBadRequestErrorexactly as it did before the rules feature landed. The guard is why this PR's own CI is green immediately, and why every other PR heals on the next rebase or merge-queue run once this lands, even while main's JSON copy stays unanchored until the next staging syncBoth layers are pinned by new tests in
tests/test_litellm/litellm_core_utils/test_fallback_generalizations.py: one asserts the shipped rule no longer matchesbedrockz/anthropic.claude-...and thatget_llm_providerraises for it, the other asserts a slash-prefixed unknown provider raises even when a rule matches inside the id. Each test was verified to fail with its half of the fix reverted. The previously failing params intests/proxy_unit_tests/test_auth_checks.pypass again both with the bundled map and against the current remote map