[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(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user