A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
Updated xgrammar backend to not deny supported string formats (#27253)
Signed-off-by: CNE Pierre FICHEPOIL <pierre-1.fichepoil@gendarmerie.interieur.gouv.fr> Signed-off-by: ExtReMLapin <3909752+ExtReMLapin@users.noreply.github.com> Co-authored-by: CNE Pierre FICHEPOIL <pierre-1.fichepoil@gendarmerie.interieur.gouv.fr> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
ExtReMLapin committed
Oct 22, 2025 at 00:25 UTC
4a8a567e16f5e1b2809112442e6da5fc6d9a6aca
2 files changed
+26
-2
tests/v1/structured_output/test_utils.py
+2
-1
@@ -13,7 +13,7 @@ pytestmark = pytest.mark.cpu_test
13
@pytest.fixture
14
def unsupported_string_schemas():
15
return [
16
- {"type": "string", "format": "email"},
16
+ {"type": "string", "format": "non_existing_format"},
17
]
18
19
@@ -58,6 +58,7 @@ def supported_schema():
58
"properties": {
59
"name": {"type": "string"},
60
"age": {"type": "integer"},
61
+ "email": {"type": "string", "format": "email"},
62
"status": {"type": "string"},
63
"scores": {"type": "array", "items": {"type": "number"}},
64
"car_type": {"type": "string", "enum": ["sedan", "suv", "truck"]},
vllm/v1/structured_output/backend_xgrammar.py
+24
-1
@@ -200,6 +200,25 @@ class XgrammarGrammar(StructuredOutputGrammar):
200
self.matcher.reset()
201
202
203
+# cf https://github.com/mlc-ai/xgrammar/blob/a32ac892676d2eedc0327416105b9b06edfb94b2/cpp/json_schema_converter.cc
204
+STRING_SUPPORTED_FORMATS = {
205
+ "email",
206
+ "date",
207
+ "time",
208
+ "date-time",
209
+ "duration",
210
+ "ipv4",
211
+ "ipv6",
212
+ "hostname",
213
+ "uuid",
214
+ "uri",
215
+ "uri-reference",
216
+ "uri-template",
217
+ "json-pointer",
218
+ "relative-json-pointer",
219
+}
220
+
221
+
222
def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool:
223
"""Check if JSON schema contains features unsupported by xgrammar."""
224
@@ -219,7 +238,11 @@ def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool:
238
return True
239
240
# Unsupported keywords for strings
222
- if obj.get("type") == "string" and "format" in obj:
241
+ if (
242
+ obj.get("type") == "string"
243
+ and "format" in obj
244
+ and obj["format"] not in STRING_SUPPORTED_FORMATS
245
+ ):
246
return True
247
248
# Unsupported keywords for objects