Skip to content

fix: strip existing provider prefix in get_known_models_from_wildcard - #30406

Closed
ylcnymn wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
ylcnymn:fix-wildcard-double-prefix
Closed

ylcnymn wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
ylcnymn:fix-wildcard-double-prefix

Conversation

@ylcnymn

@ylcnymn ylcnymn commented Jun 14, 2026

Copy link
Copy Markdown

Closes #30358

Root cause

get_known_models_from_wildcard receives model names from get_provider_models that may already carry a provider prefix (e.g. ollama/gemma3:1b from OllamaModelInfo). When the user-defined model_name prefix differs from that provider (e.g. ollama_server1/*), the code unconditionally prepends the user prefix, producing a double prefix like ollama_server1/ollama/gemma3:1b.

Fix

Before adding the user-defined prefix, strip the existing provider prefix when it does not match the user-defined one. Raw (unprefixed) model names are unaffected. When the wildcard prefix happens to match the provider prefix, the existing startswith guard still applies.

Test

Added a regression test with three cases:

  1. Prefixed provider model + different user prefix (the exact bug scenario)
  2. Raw (unprefixed) model name (existing behavior preserved)
  3. Matching prefix (existing behavior preserved)

Type

Bug Fix

When get_provider_models returns names that already carry a provider
prefix (e.g. ollama/gemma3:1b) and the user-defined model_name prefix
differs from that provider (e.g. ollama_server1/*), the code was
unconditionally prepending the user prefix, producing a double prefix
like ollama_server1/ollama/gemma3:1b.

Before adding the user-defined prefix, strip the existing provider
prefix when it does not match the user-defined one. Raw (unprefixed)
model names are unaffected, and when the wildcard prefix happens to
match the provider prefix the existing startswith guard still applies.

Fixes BerriAI#30358
@CLAassistant

CLAassistant commented Jun 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a double-prefix bug in get_known_models_from_wildcard where provider models returned with an existing prefix (e.g. ollama/gemma3:1b) were unconditionally prepended with the user-defined wildcard prefix, producing names like ollama_server1/ollama/gemma3:1b.

  • Fix (model_checks.py): Before prepending wildcard_provider_prefix, the code now strips the first /-delimited segment from any model that contains a slash, so ollama/gemma3:1b becomes gemma3:1b before the user prefix is applied. Models without slashes and models that already carry the correct prefix are unaffected.
  • Tests (test_model_checks.py): Three monkeypatched regression cases are added — mismatched prefix (the bug), raw model name (no prefix), and matching prefix (existing startswith guard). All get_provider_models calls are mocked, so no network calls are made.

Confidence Score: 5/5

The change is narrowly scoped to wildcard model expansion and does not touch the auth critical path; the three regression tests cover the fixed scenario and boundary conditions.

The fix correctly targets the double-prefix bug: it only executes when the model already failed the startswith guard, so models that already carry the right prefix are never touched. The partial-filter path was reviewed and the new stripping still produces the correct result there. No regressions were found in the changed logic.

The unconditional split("/", 1)[-1] in model_checks.py (noted in a prior review thread) is worth a follow-up if providers start returning HuggingFace-style org/model-name strings, but it does not affect current behavior for the providers that use this path today.

Important Files Changed

Filename Overview
litellm/proxy/auth/model_checks.py Adds prefix-stripping before prepending the user-defined wildcard prefix to prevent double-prefixed model names (e.g. ollama_server1/ollama/gemma3:1b). The split("/", 1)[-1] approach is unconditional and may silently drop legitimate namespaces for non-provider slashes (noted in prior thread).
tests/test_litellm/proxy/auth/test_model_checks.py Adds three regression test cases covering the bug scenario, raw model names, and matching-prefix pass-through. No network calls; all dependencies are monkeypatched.

Reviews (2): Last reviewed commit: "fix: strip existing provider prefix in g..." | Re-trigger Greptile

# Strip any existing provider prefix (e.g. "ollama/gemma3:1b" -> "gemma3:1b")
# before prepending the user-defined wildcard prefix.
# This prevents double prefixes like "ollama_server1/ollama/gemma3:1b"
_model = model.split("/", 1)[-1] if "/" in model else model

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Unconditional stripping of first /-segment may drop legitimate namespace

model.split("/", 1)[-1] unconditionally discards the first slash-delimited segment, treating it as a provider prefix. For models whose names genuinely contain a / (e.g. HuggingFace-style organization/model-name returned by a provider), this will silently drop organization, producing wildcard_prefix/model-name instead of the intended wildcard_prefix/organization/model-name. Consider checking whether the first segment is a recognised LiteLLM provider name before stripping it, so the stripping only fires for true provider-prefixed strings.

def test_wildcard_expansion_handles_prefixed_provider_models(monkeypatch):
"""
Regression test: when get_provider_models returns names with a provider prefix
(e.g. "ollama/gemma3:1b"), the wildcard expansion must NOT double-prefix them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Docstring issue URL points to author's fork, not the upstream repo

The docstring says https://github.com/ylcnymn/litellm/issues/30358 (the contributor's personal fork) instead of https://github.com/BerriAI/litellm/issues/30358. Anyone reading the test later and trying to follow the link to understand the original bug report will land on the wrong repository.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@codecov

codecov Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ylcnymn

ylcnymn commented Jun 14, 2026

Copy link
Copy Markdown
Author

@greptileai

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]: ollama_chat wildcard expansion prepends extra "ollama/" prefix when model_name differs from provider prefix

3 participants