[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
+14
View File
@@ -35,6 +35,7 @@ from vllm.entrypoints.generate.base.protocol import (
from vllm.entrypoints.openai.chat_completion.protocol import (
ChatCompletionRequest,
)
from vllm.exceptions import VLLMValidationError
from vllm.parser.engine.events import EventType
from vllm.parser.engine.streaming_parser_engine import StreamingParserEngine
from vllm.parser.mistral import _DEFAULT_JSON_SCHEMA, MistralParser, mistral_config
@@ -1890,6 +1891,19 @@ def test_adjust_request_structured_outputs_generates_grammar(
assert len(result.structured_outputs.grammar) > 0
def test_adjust_request_deeply_nested_json_string_rejected(
mistral_tool_parser: MistralToolParser,
) -> None:
"""The schema string is parsed here, before request validation, and
json.loads raises RecursionError on a string nested this deeply."""
schema = '{"type": "array", "items": ' * 20_000 + "{}" + "}" * 20_000
request = _make_request(
structured_outputs=StructuredOutputsParams(json=schema),
)
with pytest.raises(VLLMValidationError, match="nested too deeply"):
mistral_tool_parser.adjust_request(request)
@pytest.mark.parametrize(
"response_format_kwargs,expected_json_schema",
[