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
Improve output when failing json.loads() on structured output test (#25483)
Signed-off-by: dougbtv <dosmith@redhat.com>
Doug Smith committed
Sep 23, 2025 at 20:03 UTC
7ad5e50adf96826acca509747952452524e9422f
1 file changed
+18
-13
tests/v1/entrypoints/llm/test_struct_output_generate.py
+18
-13
@@ -81,16 +81,6 @@ class CarDescription(BaseModel):
81
car_type: CarType
82
83
84
-def _load_json(s: str, backend: str) -> str:
85
- if backend != "xgrammar":
86
- return json.loads(s)
87
-
88
- # xgrammar specific workarounds
89
- # https://github.com/mlc-ai/xgrammar/issues/286
90
- s = re.sub(r'[\x00-\x1F\x7F-\xFF]', '', s)
91
- return json.loads(s)
92
-
93
-
84
def test_guided_decoding_deprecated():
85
with pytest.warns(DeprecationWarning,
86
match="GuidedDecodingParams is deprecated.*"):
@@ -177,7 +167,12 @@ def test_structured_output(
167
if backend != 'lm-format-enforcer':
168
assert "\n" not in generated_text
169
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
180
- output_json = json.loads(generated_text)
170
+ try:
171
+ output_json = json.loads(generated_text)
172
+ except json.JSONDecodeError as e:
173
+ pytest.fail(
174
+ f"Invalid JSON from backend={backend}: {generated_text!r}\n"
175
+ f"Schema: {sample_json_schema}\nError: {e}")
176
jsonschema.validate(instance=output_json, schema=sample_json_schema)
177
178
#
@@ -425,7 +420,12 @@ def test_structured_output(
420
generated_text = output.outputs[0].text
421
assert generated_text is not None
422
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
428
- output_json = json.loads(generated_text)
423
+ try:
424
+ output_json = json.loads(generated_text)
425
+ except json.JSONDecodeError as e:
426
+ pytest.fail(
427
+ f"Invalid JSON from backend={backend}: {generated_text!r}\n"
428
+ f"Schema: {json_schema}\nError: {e}")
429
jsonschema.validate(instance=output_json, schema=json_schema)
430
431
#
@@ -468,7 +468,12 @@ def test_structured_output(
468
generated_text = output.outputs[0].text
469
assert generated_text is not None
470
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
471
- output_json = json.loads(generated_text)
471
+ try:
472
+ output_json = json.loads(generated_text)
473
+ except json.JSONDecodeError as e:
474
+ pytest.fail(
475
+ f"Invalid JSON from backend={backend}: {generated_text!r}\n"
476
+ f"Schema: {json_schema}\nError: {e}")
477
jsonschema.validate(instance=output_json, schema=json_schema)
478
479
if backend not in ["outlines", "lm-format-enforcer"]: