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"}},