diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index 3e605e926f7..75f528d88c0 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -2928,7 +2928,7 @@ class LiteLLMCompletionResponsesConfig: "name": typed_tool.get("name") or "", "description": typed_tool.get("description") or "", "parameters": parameters, - "strict": typed_tool.get("strict", False) or False, + **({"strict": typed_tool["strict"]} if "strict" in typed_tool else {}), }, } if tool.get("cache_control"): diff --git a/tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py b/tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py index 012926c6cb3..add067c7981 100644 --- a/tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py +++ b/tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py @@ -15,6 +15,7 @@ from openai.types.responses.response_function_web_search import ( ActionSearchSource, ResponseFunctionWebSearch, ) +from openai.types.responses.tool_param import FunctionToolParam from pydantic import TypeAdapter, ValidationError import litellm @@ -1699,6 +1700,34 @@ def _chat_response_with_tool_search_call( class TestToolTransformation: """Test cases for tool transformation from Responses API to Chat Completion format""" + @pytest.mark.parametrize("strict", [None, False, True]) + def test_responses_function_tool_preserves_strict_presence(self, strict: bool | None) -> None: + tool: Final = cast( + FunctionToolParam, + { + "type": "function", + "name": "get_weather", + "description": "Look up the weather", + "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}, + **({"strict": strict} if strict is not None else {}), + }, + ) + chat_tools: Final = LiteLLMCompletionResponsesConfig.transform_responses_api_tools_to_chat_completion_tools( + tools=[tool] + )[0] + + assert chat_tools == [ + { + "type": "function", + "function": { + "name": tool["name"], + "description": tool.get("description"), + "parameters": tool["parameters"], + **({"strict": strict} if strict is not None else {}), + }, + } + ] + def test_transform_vertex_ai_tools(self): """Test that Vertex AI tools are passed through as-is""" from litellm.types.llms.vertex_ai import VertexToolName