[Bugfix][Structured Outputs] Reject degenerate structured_outputs that crash EngineCore (#45346)
Signed-off-by: Ting Sun <suntcrick@gmail.com>
This commit is contained in:
@@ -48,3 +48,24 @@ def test_plain_request_allowed_for_diffusion_models():
|
||||
StructuredOutputsConfig(),
|
||||
tokenizer=None,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"structured_outputs, match",
|
||||
[
|
||||
(StructuredOutputsParams(json_object=False), "json_object must be True"),
|
||||
(StructuredOutputsParams(json=""), "json cannot be an empty string"),
|
||||
],
|
||||
)
|
||||
def test_degenerate_structured_outputs_rejected(structured_outputs, match):
|
||||
"""json_object=False and an empty json schema pass the `is not None`
|
||||
exclusivity check but resolve to no structured-output key, so they must be
|
||||
rejected at request validation (-> 400) instead of reaching and crashing
|
||||
the engine."""
|
||||
params = SamplingParams(structured_outputs=structured_outputs)
|
||||
with pytest.raises(ValueError, match=match):
|
||||
params._validate_structured_outputs(
|
||||
_StubModelConfig(is_diffusion=False),
|
||||
StructuredOutputsConfig(),
|
||||
tokenizer=object(),
|
||||
)
|
||||
|
||||
@@ -938,6 +938,18 @@ class SamplingParams(
|
||||
and self.structured_outputs.grammar.strip() == ""
|
||||
):
|
||||
raise ValueError("structured_outputs.grammar cannot be an empty string")
|
||||
# Reject empty string json schema early to avoid engine-side crashes
|
||||
if (
|
||||
isinstance(self.structured_outputs.json, str)
|
||||
and self.structured_outputs.json.strip() == ""
|
||||
):
|
||||
raise ValueError("structured_outputs.json cannot be an empty string")
|
||||
# Reject json_object=False early to avoid engine-side crashes
|
||||
if self.structured_outputs.json_object is False:
|
||||
raise ValueError(
|
||||
"structured_outputs.json_object must be True if set; omit "
|
||||
"structured_outputs to disable structured outputs"
|
||||
)
|
||||
|
||||
from vllm.v1.structured_output.backend_guidance import (
|
||||
has_guidance_unsupported_json_features,
|
||||
|
||||
Reference in New Issue
Block a user