-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
feat(router): add expose_router_debug_in_errors flag (default True) to redact internal model_group/fallback names #30418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Sameerlite
merged 4 commits into
BerriAI:litellm_oss_170626_1
from
GhishaDev:fix/redact-router-debug-in-errors
Jun 17, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a03467e
feat(router)!: redact internal model_group/fallback names from except…
songkuan-zheng 706832b
test(router): cover sites 1 + 3 of expose_router_debug_in_errors gate
songkuan-zheng 2ad3225
chore(router): flip expose_router_debug_in_errors default to True
songkuan-zheng e560169
ci: retrigger workflows after base branch change to litellm_internal_…
songkuan-zheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,311 @@ | ||
| """ | ||
| Tests for `litellm.expose_router_debug_in_errors`. | ||
|
|
||
| The Router historically appended internal config names (model_group, | ||
| fallback_model_group, fallback failure detail, deployment timeouts, | ||
| context_window_fallbacks dict, etc.) onto the message of the exception | ||
| it re-raises. That message is then surfaced to clients by | ||
| ProxyException, leaking the proxy's internal wiring. | ||
|
|
||
| The flag defaults to True to preserve historical behavior (no | ||
| breaking change for existing deployments). Set it to False to redact | ||
| those strings from the raised exception's message. | ||
|
|
||
| These tests verify that with the flag ON (default) the historical | ||
| leak strings appear in the raised exception's message, and with the | ||
| flag OFF the proxy's internal wiring is redacted. | ||
|
|
||
| Five leak sites are gated in `litellm/router.py`: | ||
|
|
||
| 1. Deployment timeout debug after `litellm.Timeout` | ||
| 2. ContextWindowExceededError fallback hint | ||
| 3. ContentPolicyViolationError fallback hint | ||
| 4. "No fallback model group found for..." when fallbacks dict misses | ||
| 5. "Received Model Group=...\\nAvailable Model Group Fallbacks=..." | ||
| (always fires on terminal raise from the fallback orchestrator) | ||
|
|
||
| Site 5 is the broadest — it fires for every failing call that goes | ||
| through the fallback orchestrator with any non-context-window / | ||
| non-content-policy error, regardless of whether `fallbacks` is set. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| import litellm | ||
| from litellm import Router | ||
|
|
||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
| _RECEIVED_MODEL_GROUP_PHRASE = "Received Model Group=" | ||
| _AVAILABLE_FALLBACKS_PHRASE = "Available Model Group Fallbacks=" | ||
| _CONTEXT_WINDOW_HINT_PHRASE = "context_window_fallbacks=" | ||
| _INTERNAL_MODEL_GROUP_NAME = "all-anthropic/claude-secret-internal" | ||
|
|
||
|
|
||
| def _router_with_rate_limit_failure() -> Router: | ||
| return Router( | ||
| model_list=[ | ||
| { | ||
| "model_name": _INTERNAL_MODEL_GROUP_NAME, | ||
| "litellm_params": { | ||
| "model": "gpt-4o", | ||
| "api_key": "key", | ||
| "mock_response": "litellm.RateLimitError", | ||
| }, | ||
| "model_info": {"id": "secret-deployment-id"}, | ||
| }, | ||
| ], | ||
| num_retries=0, | ||
| ) | ||
|
|
||
|
|
||
| def _router_with_context_window_failure() -> Router: | ||
| return Router( | ||
| model_list=[ | ||
| { | ||
| "model_name": _INTERNAL_MODEL_GROUP_NAME, | ||
| "litellm_params": { | ||
| "model": "gpt-4o", | ||
| "api_key": "key", | ||
| "mock_response": "litellm.ContextWindowExceededError", | ||
| }, | ||
| "model_info": {"id": "secret-deployment-id"}, | ||
| }, | ||
| ], | ||
| num_retries=0, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _reset_expose_flag(): | ||
| """Each test starts with the flag in its default (on) state.""" | ||
| original = litellm.expose_router_debug_in_errors | ||
| litellm.expose_router_debug_in_errors = True | ||
| try: | ||
| yield | ||
| finally: | ||
| litellm.expose_router_debug_in_errors = original | ||
|
|
||
|
|
||
| def test_flag_defaults_on(): | ||
| assert litellm.expose_router_debug_in_errors is True | ||
|
|
||
|
|
||
| # --- Site 5: "Received Model Group=..." on terminal raise -------------------- | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_flag_off_does_not_leak_received_model_group(): | ||
| litellm.expose_router_debug_in_errors = False | ||
| router = _router_with_rate_limit_failure() | ||
| with pytest.raises(litellm.RateLimitError) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert _RECEIVED_MODEL_GROUP_PHRASE not in msg, msg | ||
| assert _AVAILABLE_FALLBACKS_PHRASE not in msg, msg | ||
| assert _INTERNAL_MODEL_GROUP_NAME not in msg, msg | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_leaks_received_model_group(): | ||
| router = _router_with_rate_limit_failure() | ||
| with pytest.raises(litellm.RateLimitError) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert _RECEIVED_MODEL_GROUP_PHRASE in msg, msg | ||
| assert _AVAILABLE_FALLBACKS_PHRASE in msg, msg | ||
| assert _INTERNAL_MODEL_GROUP_NAME in msg, msg | ||
|
|
||
|
|
||
| # --- Site 2: ContextWindowExceededError fallback hint ------------------------ | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_flag_off_does_not_leak_context_window_fallback_hint(): | ||
| litellm.expose_router_debug_in_errors = False | ||
| router = _router_with_context_window_failure() | ||
| with pytest.raises(litellm.ContextWindowExceededError) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert _CONTEXT_WINDOW_HINT_PHRASE not in msg, msg | ||
| assert _RECEIVED_MODEL_GROUP_PHRASE not in msg, msg | ||
| assert _INTERNAL_MODEL_GROUP_NAME not in msg, msg | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_leaks_context_window_fallback_hint(): | ||
| router = _router_with_context_window_failure() | ||
| with pytest.raises(litellm.ContextWindowExceededError) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert _CONTEXT_WINDOW_HINT_PHRASE in msg, msg | ||
| # Site 5 also fires for ContextWindow errors that exit the | ||
| # orchestrator without fallback resolution, so the model_group | ||
| # name leaks under the default behavior. | ||
| assert _INTERNAL_MODEL_GROUP_NAME in msg, msg | ||
|
|
||
|
|
||
| # --- Site 4: "No fallback model group found..." when fallbacks miss --------- | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_flag_off_does_not_leak_when_no_fallback_group_found(): | ||
| litellm.expose_router_debug_in_errors = False | ||
| router = Router( | ||
| model_list=[ | ||
| { | ||
| "model_name": _INTERNAL_MODEL_GROUP_NAME, | ||
| "litellm_params": { | ||
| "model": "gpt-4o", | ||
| "api_key": "key", | ||
| "mock_response": "litellm.RateLimitError", | ||
| }, | ||
| "model_info": {"id": "secret-deployment-id"}, | ||
| }, | ||
| ], | ||
| # Fallbacks defined for a different model_group, so resolution | ||
| # ends with fallback_model_group=None and hits site 4. | ||
| fallbacks=[{"some-other-group": ["some-other-target"]}], | ||
| num_retries=0, | ||
| ) | ||
| with pytest.raises(litellm.RateLimitError) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert "No fallback model group found" not in msg, msg | ||
| assert "some-other-group" not in msg, msg | ||
| assert _INTERNAL_MODEL_GROUP_NAME not in msg, msg | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_leaks_when_no_fallback_group_found(): | ||
| router = Router( | ||
| model_list=[ | ||
| { | ||
| "model_name": _INTERNAL_MODEL_GROUP_NAME, | ||
| "litellm_params": { | ||
| "model": "gpt-4o", | ||
| "api_key": "key", | ||
| "mock_response": "litellm.RateLimitError", | ||
| }, | ||
| "model_info": {"id": "secret-deployment-id"}, | ||
| }, | ||
| ], | ||
| fallbacks=[{"some-other-group": ["some-other-target"]}], | ||
| num_retries=0, | ||
| ) | ||
| with pytest.raises(litellm.RateLimitError) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert "No fallback model group found" in msg, msg | ||
| assert _INTERNAL_MODEL_GROUP_NAME in msg, msg | ||
|
|
||
|
|
||
| # --- Site 1: Deployment timeout debug on litellm.Timeout -------------------- | ||
|
|
||
|
|
||
| def _router_with_plain_deployment() -> Router: | ||
| """Plain deployment, no preconfigured mock_response — caller supplies via kwargs. | ||
|
|
||
| Exception instances cannot live in `model_list[*].litellm_params` because | ||
| `Router.__init__` deep-copies model_list and several LiteLLM exceptions | ||
| (Timeout, ContentPolicyViolationError) require positional args that | ||
| `__reduce__` cannot reconstruct. Passing the trigger at call-site bypasses | ||
| the deepcopy entirely. | ||
| """ | ||
| return Router( | ||
| model_list=[ | ||
| { | ||
| "model_name": _INTERNAL_MODEL_GROUP_NAME, | ||
| "litellm_params": {"model": "gpt-4o", "api_key": "key"}, | ||
| "model_info": {"id": "secret-deployment-id"}, | ||
| }, | ||
| ], | ||
| num_retries=0, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_flag_off_does_not_leak_deployment_timeout_debug(): | ||
| litellm.expose_router_debug_in_errors = False | ||
| router = _router_with_plain_deployment() | ||
| with pytest.raises(litellm.Timeout) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| mock_timeout=True, | ||
| timeout=0.001, | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert "Deployment Info: request_timeout:" not in msg, msg | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_leaks_deployment_timeout_debug(): | ||
| router = _router_with_plain_deployment() | ||
| with pytest.raises(litellm.Timeout) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| mock_timeout=True, | ||
| timeout=0.001, | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert "Deployment Info: request_timeout:" in msg, msg | ||
|
|
||
|
|
||
| # --- Site 3: ContentPolicyViolationError fallback hint (no fallback set) ---- | ||
|
|
||
|
|
||
| def _content_policy_error() -> litellm.ContentPolicyViolationError: | ||
| return litellm.ContentPolicyViolationError( | ||
| message="mocked policy violation", | ||
| model="gpt-4o", | ||
| llm_provider="openai", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_flag_off_does_not_leak_content_policy_fallback_hint(): | ||
| litellm.expose_router_debug_in_errors = False | ||
| router = _router_with_plain_deployment() | ||
| with pytest.raises(litellm.ContentPolicyViolationError) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| mock_response=_content_policy_error(), | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert "content_policy_fallback=" not in msg, msg | ||
| assert _INTERNAL_MODEL_GROUP_NAME not in msg, msg | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_default_leaks_content_policy_fallback_hint(): | ||
| router = _router_with_plain_deployment() | ||
| with pytest.raises(litellm.ContentPolicyViolationError) as excinfo: | ||
| await router.acompletion( | ||
| model=_INTERNAL_MODEL_GROUP_NAME, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| mock_response=_content_policy_error(), | ||
| ) | ||
| msg = excinfo.value.message | ||
| assert "content_policy_fallback=" in msg, msg | ||
| assert _INTERNAL_MODEL_GROUP_NAME in msg, msg | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.