[Bugfix][Structured Output] Flag multi-branch allOf as unsupported for xgrammar (#59061)

Signed-off-by: Artem Perevedentsev <aperevedents@nvidia.com>
Co-authored-by: Shashank Varma <324153016+shashankvarma499@users.noreply.github.com>
This commit is contained in:
Artem Perevedentsev
2026-10-06 17:01:04 +04:00
committed by GitHub
co-authored by Shashank Varma
parent 1a86733c7b
commit 049507aa76
2 changed files with 184 additions and 25 deletions
+25 -5
View File
@@ -335,6 +335,24 @@ def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool:
):
return True
# Note(arpera):
# Xgrammar lacks support of multi-branch allOf
# For instance, this schema:
# {
# "allOf": [
# { "type": "string" },
# { "enum": ["yes", "no"] }
# ]
# }
# would accept any kind of json, such as
# "maybe", "", 42, {}, [], {"a": 1}, etc.
# which is NOT what is expected.
# Reported this issue to xgrammar team to track progress on resolving:
# https://github.com/mlc-ai/xgrammar/issues/937
allof = obj.get("allOf")
if isinstance(allof, list) and len(allof) >= 2:
return True
# Recursively check all nested objects and arrays
for value in obj.values():
if isinstance(value, dict):
@@ -401,13 +419,15 @@ def validate_xgrammar_grammar(sampling_params: SamplingParams) -> None:
else:
schema = so_params.json
if has_xgrammar_unsupported_json_features(schema):
raise VLLMValidationError(
"The provided JSON schema contains features not supported by xgrammar."
)
try:
if has_xgrammar_unsupported_json_features(schema):
raise VLLMValidationError(
"The provided JSON schema contains features not supported "
"by xgrammar."
)
xgr.Grammar.from_json_schema(schema)
except VLLMValidationError:
raise
except Exception as err:
raise VLLMValidationError(
f"Failed to transform json schema into a grammar: {err}"