[Bugfix][Frontend] Constrain forced named tool choice with empty parameters to a JSON object (#45290)

Signed-off-by: Ting Sun <suntcrick@gmail.com>
Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
Ting SUN
2026-09-30 05:44:35 +00:00
committed by GitHub
co-authored by Flora Feng
parent 6945d142e5
commit fcf4750466
2 changed files with 33 additions and 5 deletions
+25 -1
View File
@@ -5,7 +5,7 @@ from copy import deepcopy
import pytest
import regex as re
from openai.types.responses import FunctionTool, WebSearchTool
from openai.types.responses import FunctionTool, ToolChoiceFunction, WebSearchTool
from pydantic import TypeAdapter
from vllm.entrypoints.openai.chat_completion.protocol import (
@@ -456,3 +456,27 @@ class TestParallelToolCallsConstraint:
)
assert isinstance(schema, dict)
assert "maxItems" not in schema
class TestForcedNamedToolChoiceEmptyParams:
"""A forced named tool_choice with missing/empty parameters must still
constrain the generated arguments to a JSON object, like the
`tool_choice="required"` path, instead of leaving them unconstrained."""
@pytest.mark.parametrize("params", [None, {}])
def test_chat_empty_params_constrains_object(self, params):
tool = ChatCompletionToolsParam.model_validate(
{"type": "function", "function": {"name": "ping", "parameters": params}}
)
choice = ChatCompletionNamedToolChoiceParam.model_validate(
{"type": "function", "function": {"name": "ping"}}
)
schema = get_json_schema_from_tools(choice, [tool])
assert schema == {"type": "object", "properties": {}}
@pytest.mark.parametrize("params", [None, {}])
def test_responses_empty_params_constrains_object(self, params):
tool = FunctionTool(type="function", name="ping", parameters=params)
choice = ToolChoiceFunction(type="function", name="ping")
schema = get_json_schema_from_tools(choice, [tool])
assert schema == {"type": "object", "properties": {}}