Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/v1/structured_output/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions vllm/sampling_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,18 @@ def _validate_structured_outputs(
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,
Expand Down
Loading