From 3c8adc3a66bc62a676d4ea1df93a6dce02cc026c Mon Sep 17 00:00:00 2001 From: JingHao-Leon <102573344+JingHao-Leon@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:43:55 +0800 Subject: [PATCH] fix(gigachat): honor the global litellm.drop_params for response_format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- litellm/llms/gigachat/chat/transformation.py | 10 ++++--- .../chat/test_gigachat_chat_transformation.py | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/litellm/llms/gigachat/chat/transformation.py b/litellm/llms/gigachat/chat/transformation.py index 5a3cbbaf4a9..525b39cbf33 100644 --- a/litellm/llms/gigachat/chat/transformation.py +++ b/litellm/llms/gigachat/chat/transformation.py @@ -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=( diff --git a/tests/unit/llms/gigachat/chat/test_gigachat_chat_transformation.py b/tests/unit/llms/gigachat/chat/test_gigachat_chat_transformation.py index 26f13472ebb..27849c147ec 100644 --- a/tests/unit/llms/gigachat/chat/test_gigachat_chat_transformation.py +++ b/tests/unit/llms/gigachat/chat/test_gigachat_chat_transformation.py @@ -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"}},