Skip to content

[Bug]: Invalid response_format leads in 500 errors #35438

@antonovsergey93

Description

@antonovsergey93

Your current environment

The output of python collect_env.py
Your output of `python collect_env.py` here

🐛 Describe the bug

The following request

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-oss-120b",
    "messages": [
      {
        "role": "user",
        "content": "hello"
      }
    ],
    "response_format": {
      "type": "json_schema",
      "schema": {
        "type": "object"
  }'} }

results in an HTTP 500 response:

{"error":{"message":"","type":"InternalServerError","param":null,"code":500}}

However, it should return HTTP 400 (Bad Request), because when using "type": "json_schema", the schema must be wrapped inside the json_schema field, like this:

"response_format": {
      "type": "json_schema",
      "json_schema": {
        "name": "response",
        "schema": {
          "type": "object"
        }
      }
    }

In the vLLM logs:

(APIServer pid=1) WARNING 02-26 11:57:44 [protocol.py:53] The following fields were present in the request but ignored: {'schema'}
(APIServer pid=1) Traceback (most recent call last):
(APIServer pid=1)   File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/chat_completion/api_router.py", line 58, in create_chat_completion
(APIServer pid=1)     generator = await handler.create_chat_completion(request, raw_request)
(APIServer pid=1)                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(APIServer pid=1)   File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/chat_completion/serving.py", line 394, in create_chat_completion
(APIServer pid=1)     sampling_params = request.to_sampling_params(
(APIServer pid=1)                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
(APIServer pid=1)   File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/chat_completion/protocol.py", line 428, in to_sampling_params
(APIServer pid=1)     assert json_schema is not None
(APIServer pid=1)            ^^^^^^^^^^^^^^^^^^^^^^^
(APIServer pid=1) AssertionError
(APIServer pid=1) INFO:     127.0.0.1:43142 - "POST /v1/chat/completions HTTP/1.1" 500 Internal Server Error

The issue is that an assert is used to validate user input: https://github.com/vllm-project/vllm/blob/main/vllm/entrypoints/openai/chat_completion/protocol.py#L446
Instead of using assert, the code should explicitly validate the input and raise a ValueError, since this is a client-side request validation issue, not a server error.

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions