[Bugfix][Structured Output] Cap JSON schema nesting to prevent 500s and API-server stalls (#60036)

Signed-off-by: Mazukiri <maihoangduc04@gmail.com>
Signed-off-by: sfeng33 <4florafeng@gmail.com>
Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
Mai Hoàng Đức
2026-10-06 00:06:59 +00:00
committed by GitHub
co-authored by Flora Feng
parent fa423b614c
commit 5cd8a2626b
11 changed files with 259 additions and 8 deletions
+17 -1
View File
@@ -13,7 +13,8 @@ from vllm.entrypoints.openai.chat_completion.protocol import (
ChatCompletionRequest,
ChatCompletionToolsParam,
)
from vllm.parser.abstract_parser import DelegatingParser
from vllm.exceptions import VLLMValidationError
from vllm.parser.abstract_parser import DelegatingParser, structured_outputs_to_format
from vllm.sampling_params import StructuredOutputsParams
from vllm.tool_parsers.abstract_tool_parser import ToolParser
from vllm.tool_parsers.qwen3_engine_tool_parser import Qwen3EngineToolParser
@@ -303,3 +304,18 @@ class TestToolChoice_Plus_ResponseFormat:
assert _is_grammar_accept_string(grammar, self._qwen_tool_call())
assert not _is_grammar_accept_string(grammar, '{"text": "hi"}')
mock_warn.assert_called_once()
@pytest.mark.parametrize("field", ["json", "structural_tag"])
def test_structured_outputs_to_format_rejects_deeply_nested_string(field):
"""Parsers convert the constraint before request validation, and json.loads
raises RecursionError on a string nested this deeply."""
schema = '{"type": "array", "items": ' * 20_000 + "{}" + "}" * 20_000
value = schema
if field == "structural_tag":
value = (
'{"type": "structural_tag", "format": {"type": "json_schema", '
f'"json_schema": {schema}}}}}'
)
with pytest.raises(VLLMValidationError, match="nested too deeply"):
structured_outputs_to_format(StructuredOutputsParams(**{field: value}))