vllm - 💡(How to fix) Fix [Bug]: DeepSeek V3.2 & V4 incorrect structured output when thinking enabled [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vllm-project/vllm#41132Fetched 2026-04-29 06:12:10
View on GitHub
Comments
1
Participants
1
Timeline
4
Reactions
1
Author
Participants
Assignees
Timeline (top)
labeled ×2assigned ×1commented ×1

Code Example

vllm serve deepseek-ai/DeepSeek-V4-Pro\
  --served-model-name "deepseek-ai/DeepSeek-V4-Pro" \
  --trust-remote-code \
  --kv-cache-dtype fp8 \
  --block-size 256 \
  --enable-expert-parallel \
  --tensor-parallel-size 8 \
  --reasoning-parser deepseek_v4 \
  --tokenizer-mode deepseek_v4 \
  --tool-call-parser deepseek_v4 \
  --enable-auto-tool-choice \
  --model-loader-extra-config '{"enable_multithread_load": true, "num_threads": 12}'

---

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1/", api_key="v1",)
so_messages = [
{
  "role": "user",
  "content": "Return ONLY a minified JSON object with EXACTLY these keys and constraints: {\"location\":string, \"temperature\":integer [-100..100], \"conditions\":\"sunny|cloudy|rainy|snowy\", \"unit\":\"celsius\", \"readings\":[{t:integer, ts:ISO-8601 UTC Z} x 3]}. No code fences, no extra text, no newlines. Example shape only; fill realistic values for Boston."
}
]
so_fail = {
  "max_tokens": 65536,
  "response_format": {
   "type": "json_object"
  },
  "chat_template_kwargs": {
    "enable_thinking": True
  },
}

response = client.chat.completions.create(
    model='deepseek-ai/DeepSeek-V4.0',
    messages=so_messages,
    extra_body=so_fail,
)
print(response)

---

ChatCompletion(
  id='chatcmpl-b890b17a7bb5881d',
  choices=[
    Choice(
      finish_reason='stop',
      index=0,
      logprobs=None,
      message=ChatCompletionMessage(
        content=None,
        refusal=None,
        role='assistant',
        annotations=None,
        audio=None, 
        function_call=None, tool_calls=[],
        reasoning='We{\n  "location": "Boston",\n  "temperature": 18,\n  "conditions": "cloudy",\n  "unit": "celsius",\n  "readings": [\n    {"t": 18, "ts": "2025-03-14T19:00:00Z"},\n    {"t": 17, "ts": "2025-03-14T20:00:00Z"},\n    {"t": 16, "ts": "2025-03-14T21:00:00Z"}\n  ]\n}'
        # ^^^^^^^^^^^^^^^^^^^^^^^^ THE PROBLEM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        ),
      stop_reason=None,
      token_ids=None
    )
  ],
  created=1777373352,
  model='deepseek-ai/DeepSeek-V4-Pro',
  object='chat.completion',
  service_tier=None,
  system_fingerprint=None, 
  usage=CompletionUsage(completion_tokens=117, prompt_tokens=101, total_tokens=218, completion_tokens_details=None, prompt_tokens_details=None),
  prompt_logprobs=None, prompt_token_ids=None, kv_transfer_params=None
)
RAW_BUFFERClick to expand / collapse

Your current environment

  • Models: deepseek-ai/DeepSeek-V3.2, deepseek-ai/DeepSeek-V4-Flash, deepseek-ai/DeepSeek-V4-Pro
  • Docker Image: vllm/vllm-openai:v0.20.0-cu130
  • Deployment Mode: multi-GPU (tensor parallel = 8, expert parallel enabled)
  • GPU: b300
  • CUDA: 13.0 (from image)

🐛 Describe the bug

When trying to use response_format: json + thinking model outputs result in reasoning field. Model started with parameters:

vllm serve deepseek-ai/DeepSeek-V4-Pro\
  --served-model-name "deepseek-ai/DeepSeek-V4-Pro" \
  --trust-remote-code \
  --kv-cache-dtype fp8 \
  --block-size 256 \
  --enable-expert-parallel \
  --tensor-parallel-size 8 \
  --reasoning-parser deepseek_v4 \
  --tokenizer-mode deepseek_v4 \
  --tool-call-parser deepseek_v4 \
  --enable-auto-tool-choice \
  --model-loader-extra-config '{"enable_multithread_load": true, "num_threads": 12}'

Reproducer script:

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1/", api_key="v1",)
so_messages = [
{
  "role": "user",
  "content": "Return ONLY a minified JSON object with EXACTLY these keys and constraints: {\"location\":string, \"temperature\":integer [-100..100], \"conditions\":\"sunny|cloudy|rainy|snowy\", \"unit\":\"celsius\", \"readings\":[{t:integer, ts:ISO-8601 UTC Z} x 3]}. No code fences, no extra text, no newlines. Example shape only; fill realistic values for Boston."
}
]
so_fail = {
  "max_tokens": 65536,
  "response_format": {
   "type": "json_object"
  },
  "chat_template_kwargs": {
    "enable_thinking": True
  },
}

response = client.chat.completions.create(
    model='deepseek-ai/DeepSeek-V4.0',
    messages=so_messages,
    extra_body=so_fail,
)
print(response)

This outputs:

ChatCompletion(
  id='chatcmpl-b890b17a7bb5881d',
  choices=[
    Choice(
      finish_reason='stop',
      index=0,
      logprobs=None,
      message=ChatCompletionMessage(
        content=None,
        refusal=None,
        role='assistant',
        annotations=None,
        audio=None, 
        function_call=None, tool_calls=[],
        reasoning='We{\n  "location": "Boston",\n  "temperature": 18,\n  "conditions": "cloudy",\n  "unit": "celsius",\n  "readings": [\n    {"t": 18, "ts": "2025-03-14T19:00:00Z"},\n    {"t": 17, "ts": "2025-03-14T20:00:00Z"},\n    {"t": 16, "ts": "2025-03-14T21:00:00Z"}\n  ]\n}'
        # ^^^^^^^^^^^^^^^^^^^^^^^^ THE PROBLEM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        ),
      stop_reason=None,
      token_ids=None
    )
  ],
  created=1777373352,
  model='deepseek-ai/DeepSeek-V4-Pro',
  object='chat.completion',
  service_tier=None,
  system_fingerprint=None, 
  usage=CompletionUsage(completion_tokens=117, prompt_tokens=101, total_tokens=218, completion_tokens_details=None, prompt_tokens_details=None),
  prompt_logprobs=None, prompt_token_ids=None, kv_transfer_params=None
)

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.

extent analysis

TL;DR

The issue can be resolved by adjusting the response_format to correctly handle the reasoning field output in JSON format.

Guidance

  • The problem seems to be related to the response_format set to json_object and the reasoning field containing a JSON string that is not being parsed correctly.
  • Verify that the reasoning field is being generated correctly by the model and that it matches the expected JSON format.
  • Check the model configuration and the response_format settings to ensure they are compatible with the expected output format.
  • Consider modifying the response_format to handle the reasoning field as a JSON string or object.

Example

No code snippet is provided as the issue seems to be related to the model configuration and output format.

Notes

The issue may be specific to the deepseek-ai/DeepSeek-V4-Pro model and the vllm-openai:v0.20.0-cu130 Docker image. Further investigation may be required to determine the root cause of the issue.

Recommendation

Apply a workaround by modifying the response_format to handle the reasoning field as a JSON string or object, as this seems to be the most likely cause of the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING