[Bugfix] Raise VLLMValidationError from structured output validators (#52394)

Signed-off-by: Jeffrey Wang <jeffreywang@anyscale.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffrey Wang
2026-08-16 01:04:51 -07:00
committed by GitHub
co-authored by Claude Opus 5
parent 8efa13b700
commit 41f12a0daf
8 changed files with 109 additions and 30 deletions
+7 -2
View File
@@ -1092,7 +1092,7 @@ class SamplingParams(
try:
validate_xgrammar_grammar(self)
self.structured_outputs._backend = "xgrammar"
except ValueError:
except VLLMValidationError:
# The request either failed validation
# or includes some jsonschema feature(s) that
# are not supported in xgrammar.
@@ -1103,7 +1103,12 @@ class SamplingParams(
so_params = self.structured_outputs
if not skip_guidance and so_params.json:
if isinstance(so_params.json, str):
schema = json_mod.loads(so_params.json)
try:
schema = json_mod.loads(so_params.json)
except json_mod.JSONDecodeError as e:
raise VLLMValidationError(
"Invalid JSON grammar specification."
) from e
else:
schema = so_params.json
skip_guidance = has_guidance_unsupported_json_features(schema)