fix(proxy): say Claude Code and Codex keep drop_params on when litellm_settings.drop_params is unreadable

This commit is contained in:
mateo-berri 2026-10-30 01:51:18 -07:00
parent e81dd348a4
commit ea09a32ae5
5 changed files with 32 additions and 31 deletions

View file

@ -168,13 +168,6 @@ def drops_unsupported_params(drop_params: object) -> bool:
return litellm.drop_params is True or normalize_drop_params(drop_params) is True
def drop_params_flag(value: object, source: str, logger: logging.Logger) -> bool:
normalized: Final = normalize_drop_params(value)
if normalized is None and value is not None:
logger.warning("%s=%r is not a flag value, treating it as off", source, value)
return bool(normalized)
DROP_PARAMS_ENV_VAR: Final = "LITELLM_DROP_PARAMS"

View file

@ -1145,6 +1145,17 @@ def should_auto_drop_params_for_agentic_cli(
return normalize_drop_params(litellm_settings.get("drop_params")) is not False
def parse_litellm_settings_drop_params(value: object) -> bool:
normalized: Final = normalize_drop_params(value)
if normalized is None and value is not None:
verbose_proxy_logger.warning(
"litellm_settings.drop_params=%r is not a flag value, treating it as off, except for Claude Code and "
"Codex requests, which keep their drop_params default on. Set it to true or false",
value,
)
return normalized is True
def safe_add_api_version_from_query_params(data: dict, request: Request):
try:
if hasattr(request, "query_params"):

View file

@ -365,7 +365,6 @@ from litellm.litellm_core_utils.agentic_loop_settings import (
from litellm.litellm_core_utils.audio_utils.utils import resolve_speech_media_type
from litellm.litellm_core_utils.core_helpers import (
as_str_mapping,
drop_params_flag,
get_litellm_metadata_from_kwargs,
get_parent_otel_span_from_kwargs,
iter_items,
@ -681,6 +680,7 @@ from litellm.proxy.litellm_pre_call_utils import (
SCHEDULER_PRIORITY_HEADER,
LiteLLMProxyRequestSetup,
add_litellm_data_to_request,
parse_litellm_settings_drop_params,
)
from litellm.proxy.logging_endpoints.callback_logs_endpoints import (
rust_control_plane_router,
@ -6974,7 +6974,7 @@ class ProxyConfig:
parse_budget_reset_time(value)
setattr(litellm, key, value)
elif key == "drop_params":
litellm.drop_params = drop_params_flag(value, "litellm_settings.drop_params", verbose_proxy_logger)
litellm.drop_params = parse_litellm_settings_drop_params(value)
elif key == "suppress_startup_output":
continue
else:

View file

@ -17,7 +17,6 @@ from litellm.litellm_core_utils.core_helpers import (
bind_budget_reservation_to_callbacks,
budget_reservation_from_metadata,
drop_params_env_flag,
drop_params_flag,
get_litellm_metadata_from_kwargs,
get_or_create_metadata_bucket,
get_parent_otel_span_from_kwargs,
@ -437,20 +436,6 @@ def test_normalize_drop_params(value, expected):
assert normalize_drop_params(value) is expected
@pytest.mark.parametrize("value, expected", [("true", True), ("off", False), (None, False)])
def test_drop_params_flag_returns_a_bool_without_a_warning(value, expected, caplog):
with caplog.at_level(logging.WARNING, logger="drop-params-test"):
assert drop_params_flag(value, "LITELLM_DROP_PARAMS", logging.getLogger("drop-params-test")) is expected
assert caplog.text == ""
@pytest.mark.parametrize("value", ["temperature", "ture", 2])
def test_drop_params_flag_treats_non_flag_values_as_off_with_a_warning(value, caplog):
with caplog.at_level(logging.WARNING, logger="drop-params-test"):
assert drop_params_flag(value, "LITELLM_DROP_PARAMS", logging.getLogger("drop-params-test")) is False
assert f"LITELLM_DROP_PARAMS={value!r} is not a flag value, treating it as off" in caplog.text
@pytest.mark.parametrize(
"environ, expected",
[

View file

@ -32,6 +32,7 @@ import litellm
from litellm._logging import turn_on_json
from litellm.proxy._types import CommonProxyErrors, ConfigGeneralSettings
from litellm.proxy.common_utils.encrypt_decrypt_utils import encrypt_value_helper
from litellm.proxy.litellm_pre_call_utils import should_auto_drop_params_for_agentic_cli
from litellm.router_api import ApplyResult, RouterSettings
from litellm.types.router import Deployment, LiteLLM_Params
from litellm.proxy.proxy_server import (
@ -3666,7 +3667,7 @@ def test_ProxyConfig__add_deployment_keeps_loading_rows_after_a_non_flag_drop_pa
@pytest.mark.asyncio
@pytest.mark.parametrize("configured, expected", [("true", True), ("false", False)])
async def test_ProxyConfig_load_config_turns_litellm_settings_drop_params_string_into_bool(
tmp_path, monkeypatch, configured, expected
tmp_path, monkeypatch, caplog, configured, expected
):
f = tmp_path / "c.yaml"
f.write_text(f'model_list: []\nlitellm_settings:\n drop_params: "{configured}"\n')
@ -3675,9 +3676,11 @@ async def test_ProxyConfig_load_config_turns_litellm_settings_drop_params_string
monkeypatch.delenv("LITELLM_CONFIG_BUCKET_NAME", raising=False)
monkeypatch.setattr(litellm, "drop_params", not expected)
await ProxyConfig().load_config(router=None, config_file_path=str(f))
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
await ProxyConfig().load_config(router=None, config_file_path=str(f))
assert litellm.drop_params is expected
assert "drop_params" not in caplog.text
@pytest.mark.asyncio
@ -3696,21 +3699,30 @@ async def test_ProxyConfig_load_config_resolves_a_litellm_settings_drop_params_e
@pytest.mark.asyncio
async def test_ProxyConfig_load_config_warns_and_turns_off_a_non_flag_litellm_settings_drop_params(
tmp_path, monkeypatch, caplog
@pytest.mark.parametrize("configured, logged", [("ture", "'ture'"), ('"maybe"', "'maybe'"), ("2", "2")])
async def test_ProxyConfig_load_config_warns_that_a_non_flag_litellm_settings_drop_params_is_off_except_for_agentic_clis(
tmp_path, monkeypatch, caplog, configured, logged
):
f = tmp_path / "c.yaml"
f.write_text("model_list: []\nlitellm_settings:\n drop_params: ture\n")
f.write_text(f"model_list: []\nlitellm_settings:\n drop_params: {configured}\n")
monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", None)
monkeypatch.setattr("litellm.proxy.proxy_server.store_model_in_db", False)
monkeypatch.delenv("LITELLM_CONFIG_BUCKET_NAME", raising=False)
monkeypatch.setattr(litellm, "drop_params", True)
proxy_config = ProxyConfig()
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
await ProxyConfig().load_config(router=None, config_file_path=str(f))
await proxy_config.load_config(router=None, config_file_path=str(f))
assert litellm.drop_params is False
assert "litellm_settings.drop_params='ture' is not a flag value, treating it as off" in caplog.text
assert caplog.text.count("is not a flag value") == 1
assert (
f"litellm_settings.drop_params={logged} is not a flag value, treating it as off, except for Claude Code and "
"Codex requests, which keep their drop_params default on" in caplog.text
)
assert should_auto_drop_params_for_agentic_cli("claude-cli/2.1.299 (external, cli)", False, proxy_config)
assert should_auto_drop_params_for_agentic_cli("codex_cli_rs/0.165.0", False, proxy_config)
assert not should_auto_drop_params_for_agentic_cli("curl/8.5.0", False, proxy_config)
# ---------------------------------------------------------------------------