[Bugfix][Structured Outputs] Reject empty structural_tag at request validation (#47450)
Signed-off-by: linnea-lin-00638949 <15521435947@163.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Artem Perevedentsev <aperevedents@nvidia.com>
This commit is contained in:
co-authored by
Claude
Artem Perevedentsev
parent
362a64b21d
commit
e548298f81
@@ -56,13 +56,18 @@ def test_plain_request_allowed_for_diffusion_models():
|
||||
[
|
||||
(StructuredOutputsParams(json_object=False), "json_object must be True"),
|
||||
(StructuredOutputsParams(json=""), "json cannot be an empty string"),
|
||||
(
|
||||
StructuredOutputsParams(structural_tag=""),
|
||||
"structural_tag 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."""
|
||||
rejected at request validation (-> 400). Empty `structural_tag` is rejected
|
||||
for the same reason: `json.loads("")` in `compile_grammar` would otherwise
|
||||
raise JSONDecodeError and surface as a per-request engine error."""
|
||||
params = SamplingParams(structured_outputs=structured_outputs)
|
||||
with pytest.raises(VLLMValidationError, match=match):
|
||||
params._validate_structured_outputs(
|
||||
|
||||
@@ -1144,6 +1144,18 @@ class SamplingParams(
|
||||
raise VLLMValidationError(
|
||||
"structured_outputs.regex must not contain a NUL character ('\\x00')"
|
||||
)
|
||||
# Note(arpera):
|
||||
# We do NOT check here structured output regex on emptiness because
|
||||
# empty regex is indeed compiles to a valid grammar as well as
|
||||
# whitespace-only regexps, for instance, regex="\n" or regex=" "
|
||||
# are valid patterns and we MUST process them.
|
||||
if (
|
||||
isinstance(self.structured_outputs.structural_tag, str)
|
||||
and self.structured_outputs.structural_tag.strip() == ""
|
||||
):
|
||||
raise VLLMValidationError(
|
||||
"structured_outputs.structural_tag cannot be an empty string"
|
||||
)
|
||||
|
||||
from vllm.v1.structured_output.backend_guidance import (
|
||||
has_guidance_unsupported_json_features,
|
||||
|
||||
Reference in New Issue
Block a user