[Frontend] Skip structural tags for auto tool_choice without strict mode (#45600)

Signed-off-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
Flora Feng
2026-06-15 19:55:31 +00:00
committed by GitHub
parent e18fe932ca
commit cd9078fe59
8 changed files with 111 additions and 24 deletions
+1
View File
@@ -75,6 +75,7 @@ class AnthropicTool(BaseModel):
name: str
description: str | None = None
input_schema: dict[str, Any]
strict: bool | None = None
defer_loading: bool | None = None
@field_validator("input_schema")
+1
View File
@@ -462,6 +462,7 @@ class AnthropicServingMessages(OpenAIServingChat):
"name": tool.name,
"description": tool.description,
"parameters": tool.input_schema,
"strict": tool.strict,
"defer_loading": tool.defer_loading,
},
}
@@ -247,11 +247,14 @@ class FunctionDefinition(OpenAIBaseModel):
name: str
description: str | None = None
parameters: dict[str, Any] | None = None
strict: bool | None = None
defer_loading: bool | None = None
@model_serializer(mode="wrap")
def _serialize(self, handler):
data = handler(self)
if self.strict is None:
data.pop("strict", None)
if self.defer_loading is None:
data.pop("defer_loading", None)
return data
@@ -84,6 +84,17 @@ def register_vllm_structural_tag(model: str):
return decorator
def _any_tool_strict(
tools: Sequence[ChatCompletionToolsParam | ResponsesTool],
) -> bool:
for tool in tools:
if isinstance(tool, FunctionTool) and tool.strict is True:
return True
if isinstance(tool, ChatCompletionToolsParam) and tool.function.strict is True:
return True
return False
def get_model_structural_tag(
model: str,
tools: Sequence[ChatCompletionToolsParam | ResponsesTool] | None,
@@ -95,6 +106,9 @@ def get_model_structural_tag(
if not tools or tool_choice == "none":
return None
if tool_choice == "auto" and not _any_tool_strict(tools):
return None
dumped_tools = [_dump_tool_for_xgrammar(tool) for tool in tools]
dumped_tool_choice = _dump_tool_choice_for_xgrammar(tool_choice)