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 13, 08:15 UTC
[Bugfix] Prevent crash on empty grammar string (#28210)
Signed-off-by: tjandy98 <3953059+tjandy98@users.noreply.github.com>
tjandy98 committed
Nov 13, 2025 at 14:42 UTC
4504e8029bd15c60e164661a4283358381616846
2 files changed
+26
tests/v1/entrypoints/openai/test_chat_completion.py
+20
@@ -138,3 +138,23 @@ async def test_invalid_grammar(client: openai.AsyncOpenAI, model_name: str):
138
"structured_outputs": {"grammar": invalid_simplified_sql_grammar}
139
},
140
)
141
+
142
+
143
+@pytest.mark.asyncio
144
+@pytest.mark.parametrize(
145
+ "model_name",
146
+ [MODEL_NAME],
147
+)
148
+async def test_empty_grammar(client: openai.AsyncOpenAI, model_name: str) -> None:
149
+ prompt = "Say hello"
150
+ with pytest.raises((openai.BadRequestError, openai.APIError)):
151
+ await client.chat.completions.create(
152
+ model=model_name,
153
+ messages=[
154
+ {
155
+ "role": "user",
156
+ "content": prompt,
157
+ }
158
+ ],
159
+ extra_body={"structured_outputs": {"grammar": ""}},
160
+ )
vllm/v1/engine/processor.py
+6
@@ -270,6 +270,12 @@ class Processor:
270
raise ValueError(
271
f"Choice '{params.structured_outputs.choice}' cannot be an empty list" # noqa: E501
272
)
273
+ # Reject empty string grammar early to avoid engine-side crashes
274
+ if (
275
+ isinstance(params.structured_outputs.grammar, str)
276
+ and params.structured_outputs.grammar.strip() == ""
277
+ ):
278
+ raise ValueError("structured_outputs.grammar cannot be an empty string")
279
280
if backend.startswith("xgrammar"):
281
# xgrammar with no fallback