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 7, 14:00 UTC
[Bugfix] Move chat completion response_format validation to Pydantic model_validator (#35510)
Signed-off-by: umut-polat <52835619+umut-polat@users.noreply.github.com>
Umut Polat committed
Feb 28, 2026 at 08:26 UTC
1d5ab5d603792e6c96584c3c6f4cd50b9925690f
2 files changed
+40
tests/entrypoints/openai/test_chat_error.py
+12
@@ -370,3 +370,15 @@ def test_system_message_warns_on_video(video_content):
370
call_args = str(mock_logger.warning_once.call_args)
371
assert "System messages should only contain text" in call_args
372
assert "video_url" in call_args
373
+
374
+
375
+def test_json_schema_response_format_missing_schema():
376
+ """When response_format type is 'json_schema' but the json_schema field
377
+ is not provided, request construction should raise a validation error
378
+ so the API returns 400 instead of 500."""
379
+ with pytest.raises(Exception, match="json_schema.*must be provided"):
380
+ ChatCompletionRequest(
381
+ model=MODEL_NAME,
382
+ messages=[{"role": "user", "content": "hello"}],
383
+ response_format={"type": "json_schema"},
384
+ )
vllm/entrypoints/openai/chat_completion/protocol.py
+28
@@ -502,6 +502,34 @@ class ChatCompletionRequest(OpenAIBaseModel):
502
skip_clone=True, # Created fresh per request, safe to skip clone
503
)
504
505
+ @model_validator(mode="before")
506
+ @classmethod
507
+ def validate_response_format(cls, data):
508
+ response_format = data.get("response_format")
509
+ if response_format is None:
510
+ return data
511
+
512
+ rf_type = (
513
+ response_format.get("type")
514
+ if isinstance(response_format, dict)
515
+ else getattr(response_format, "type", None)
516
+ )
517
+
518
+ if rf_type == "json_schema":
519
+ json_schema = (
520
+ response_format.get("json_schema")
521
+ if isinstance(response_format, dict)
522
+ else getattr(response_format, "json_schema", None)
523
+ )
524
+ if json_schema is None:
525
+ raise VLLMValidationError(
526
+ "When response_format type is 'json_schema', the "
527
+ "'json_schema' field must be provided.",
528
+ parameter="response_format",
529
+ )
530
+
531
+ return data
532
+
533
@model_validator(mode="before")
534
@classmethod
535
def validate_stream_options(cls, data):