From 062ec4240aba776a87900fa3c1fe6054f01642ec Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 1 May 2026 17:23:47 +0000 Subject: [PATCH] Fix hosted vllm custom tool schema fallback --- .../llms/hosted_vllm/chat/transformation.py | 2 +- .../test_hosted_vllm_chat_transformation.py | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/litellm/llms/hosted_vllm/chat/transformation.py b/litellm/llms/hosted_vllm/chat/transformation.py index d23420eb3dc..88f77347e4f 100644 --- a/litellm/llms/hosted_vllm/chat/transformation.py +++ b/litellm/llms/hosted_vllm/chat/transformation.py @@ -57,7 +57,7 @@ class HostedVLLMChatConfig(OpenAIGPTConfig): custom_tool.get("name") or tool.get("name") or f"custom_tool_{idx}" ) tool_description = custom_tool.get("description") or tool.get("description") - tool_parameters = custom_tool.get("input_schema") + tool_parameters = custom_tool.get("input_schema") or tool.get("input_schema") if not isinstance(tool_parameters, dict): tool_parameters = { diff --git a/tests/test_litellm/llms/hosted_vllm/chat/test_hosted_vllm_chat_transformation.py b/tests/test_litellm/llms/hosted_vllm/chat/test_hosted_vllm_chat_transformation.py index ec78cfee2d5..29ab3790609 100644 --- a/tests/test_litellm/llms/hosted_vllm/chat/test_hosted_vllm_chat_transformation.py +++ b/tests/test_litellm/llms/hosted_vllm/chat/test_hosted_vllm_chat_transformation.py @@ -289,3 +289,33 @@ def test_hosted_vllm_custom_tools_are_converted_to_function_tools(): assert tools[0]["function"]["description"] == "Apply text patch" assert tools[0]["function"]["parameters"]["type"] == "object" assert "input" in tools[0]["function"]["parameters"]["properties"] + + +def test_hosted_vllm_custom_tools_use_top_level_input_schema(): + config = HostedVLLMChatConfig() + input_schema = { + "type": "object", + "properties": {"query": {"type": "string"}}, + "required": ["query"], + } + optional_params = config.map_openai_params( + non_default_params={ + "tools": [ + { + "type": "custom", + "name": "search", + "description": "Search docs", + "input_schema": input_schema, + } + ] + }, + optional_params={}, + model="hosted_vllm/gpt-oss-120b", + drop_params=False, + ) + + tools = optional_params["tools"] + assert len(tools) == 1 + assert tools[0]["function"]["name"] == "search" + assert tools[0]["function"]["description"] == "Search docs" + assert tools[0]["function"]["parameters"] == input_schema