Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
7ad5e50a
Unverified
Commit
7ad5e50a
authored
Sep 23, 2025
by
Doug Smith
Committed by
GitHub
Sep 23, 2025
Browse files
Improve output when failing json.loads() on structured output test (#25483)
Signed-off-by:
dougbtv
<
dosmith@redhat.com
>
parent
dc464a3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
tests/v1/entrypoints/llm/test_struct_output_generate.py
tests/v1/entrypoints/llm/test_struct_output_generate.py
+18
-13
No files found.
tests/v1/entrypoints/llm/test_struct_output_generate.py
View file @
7ad5e50a
...
...
@@ -81,16 +81,6 @@ class CarDescription(BaseModel):
car_type
:
CarType
def
_load_json
(
s
:
str
,
backend
:
str
)
->
str
:
if
backend
!=
"xgrammar"
:
return
json
.
loads
(
s
)
# xgrammar specific workarounds
# https://github.com/mlc-ai/xgrammar/issues/286
s
=
re
.
sub
(
r
'[\x00-\x1F\x7F-\xFF]'
,
''
,
s
)
return
json
.
loads
(
s
)
def
test_guided_decoding_deprecated
():
with
pytest
.
warns
(
DeprecationWarning
,
match
=
"GuidedDecodingParams is deprecated.*"
):
...
...
@@ -177,7 +167,12 @@ def test_structured_output(
if
backend
!=
'lm-format-enforcer'
:
assert
"
\n
"
not
in
generated_text
print
(
f
"Prompt:
{
prompt
!
r
}
, Generated text:
{
generated_text
!
r
}
"
)
output_json
=
json
.
loads
(
generated_text
)
try
:
output_json
=
json
.
loads
(
generated_text
)
except
json
.
JSONDecodeError
as
e
:
pytest
.
fail
(
f
"Invalid JSON from backend=
{
backend
}
:
{
generated_text
!
r
}
\n
"
f
"Schema:
{
sample_json_schema
}
\n
Error:
{
e
}
"
)
jsonschema
.
validate
(
instance
=
output_json
,
schema
=
sample_json_schema
)
#
...
...
@@ -425,7 +420,12 @@ def test_structured_output(
generated_text
=
output
.
outputs
[
0
].
text
assert
generated_text
is
not
None
print
(
f
"Prompt:
{
prompt
!
r
}
, Generated text:
{
generated_text
!
r
}
"
)
output_json
=
json
.
loads
(
generated_text
)
try
:
output_json
=
json
.
loads
(
generated_text
)
except
json
.
JSONDecodeError
as
e
:
pytest
.
fail
(
f
"Invalid JSON from backend=
{
backend
}
:
{
generated_text
!
r
}
\n
"
f
"Schema:
{
json_schema
}
\n
Error:
{
e
}
"
)
jsonschema
.
validate
(
instance
=
output_json
,
schema
=
json_schema
)
#
...
...
@@ -468,7 +468,12 @@ def test_structured_output(
generated_text
=
output
.
outputs
[
0
].
text
assert
generated_text
is
not
None
print
(
f
"Prompt:
{
prompt
!
r
}
, Generated text:
{
generated_text
!
r
}
"
)
output_json
=
json
.
loads
(
generated_text
)
try
:
output_json
=
json
.
loads
(
generated_text
)
except
json
.
JSONDecodeError
as
e
:
pytest
.
fail
(
f
"Invalid JSON from backend=
{
backend
}
:
{
generated_text
!
r
}
\n
"
f
"Schema:
{
json_schema
}
\n
Error:
{
e
}
"
)
jsonschema
.
validate
(
instance
=
output_json
,
schema
=
json_schema
)
if
backend
not
in
[
"outlines"
,
"lm-format-enforcer"
]:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment