Fix tool call constrained decoding and parsing for models with native formats (#21593)

This commit is contained in:
Xinyuan Tong
2026-04-10 20:37:23 -07:00
committed by GitHub
parent c2821dfbe9
commit 7c6db40540
9 changed files with 306 additions and 61 deletions
@@ -348,8 +348,12 @@ class TestToolChoiceLlama32(CustomTestCase):
self.assertEqual(found_name, "get_weather")
def test_required_streaming_arguments_chunks_json(self):
"""In streaming required mode, complete tool call arguments should be valid JSON when all chunks are combined"""
"""In streaming required mode, complete tool call arguments should be valid JSON when all chunks are combined.
Uses strict=True so the grammar enforces the parameter schema."""
tools = self.get_test_tools()
# Add strict=True so arguments are schema-constrained
for tool in tools:
tool["function"]["strict"] = True
messages = self.get_test_messages()
response = self.client.chat.completions.create(
@@ -406,13 +410,15 @@ class TestToolChoiceLlama32(CustomTestCase):
)
def test_complex_parameters_required_non_streaming(self):
"""Validate complex nested parameter schemas in non-streaming required mode"""
"""Validate complex nested parameter schemas in non-streaming required mode.
Uses strict=True so the grammar enforces the parameter schema."""
complex_tools = [
{
"type": "function",
"function": {
"name": "analyze_data",
"description": "Analyze complex data structures",
"strict": True,
"parameters": {
"type": "object",
"properties": {