fix(gigachat): honor the global litellm.drop_params for response_format

Greptile flagged this as a merge blocker and it is right: the `json_object`
rejection checked only the per-call `drop_params` argument, so a user who had
set `litellm.drop_params = True` globally still got an `UnsupportedParamsError`
for `response_format={'type': 'json_object'}` — the opposite of what that
setting means everywhere else in the codebase.

`litellm/utils.py` and the Azure transformations all gate on

    litellm.drop_params is True or drop_params is True

so this now uses the same test, and the import moved out of the branch since
it is needed on both paths. Two tests cover it: with the global set the mapping
returns cleanly, and with the global explicitly False the per-call `False` still
raises, so a leftover global cannot mask a real unsupported parameter.
This commit is contained in:
JingHao-Leon 2026-10-11 18:43:55 +08:00
parent 8de7014ec7
commit 3c8adc3a66
2 changed files with 33 additions and 4 deletions

View file

@ -15,6 +15,7 @@ from typing import TYPE_CHECKING, Any, Final
import httpx
import litellm
from litellm._logging import verbose_logger
from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMException
from litellm.llms.gigachat.utils import convert_usage, get_api_base
@ -209,11 +210,12 @@ class GigaChatConfig(BaseConfig):
optional_params["function_call"] = {"name": schema_name}
optional_params["_structured_output"] = True
elif not (isinstance(value, Mapping) and (value.get("type") in (None, "text", "json_schema"))):
# Only json_schema is actually mapped above; other response_format
# values (e.g. json_object) would otherwise be silently ignored.
if not drop_params:
from litellm.utils import UnsupportedParamsError
# Only json_schema is mapped above; anything else (json_object,
# a missing schema, an unexpected shape) is silently dropped by
# GigaChat unless we say so.
from litellm.utils import UnsupportedParamsError
if litellm.drop_params is not True and drop_params is not True:
raise UnsupportedParamsError(
status_code=400,
message=(

View file

@ -391,6 +391,33 @@ class TestMapOpenAiParams:
assert "functions" not in result
assert "function_call" not in result
def test_response_format_json_object_dropped_with_global_drop_params(self, monkeypatch):
"""The per-call flag is not the only switch: litellm.drop_params is global."""
import litellm
monkeypatch.setattr(litellm, "drop_params", True, raising=False)
result = self.config.map_openai_params(
non_default_params={"response_format": {"type": "json_object"}},
optional_params={},
model="GigaChat",
drop_params=False,
)
assert "functions" not in result
assert "function_call" not in result
def test_response_format_json_object_raises_when_global_drop_params_off(self, monkeypatch):
"""A global drop_params left over from elsewhere must not mask the error."""
import litellm
monkeypatch.setattr(litellm, "drop_params", False, raising=False)
with pytest.raises(UnsupportedParamsError):
self.config.map_openai_params(
non_default_params={"response_format": {"type": "json_object"}},
optional_params={},
model="GigaChat",
drop_params=False,
)
def test_response_format_text_is_a_noop(self):
result = self.config.map_openai_params(
non_default_params={"response_format": {"type": "text"}},