vllm - ✅(Solved) Fix [Bug]: Gemma4ToolParser.__init__() missing `tools` parameter — 400 error on tool calls [1 pull requests, 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#38837Fetched 2026-04-08 02:34:38
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
8
Participants
Timeline (top)
subscribed ×2closed ×1cross-referenced ×1renamed ×1

Error Message

  1. Get 400 error immediately

Root Cause

The tools parameter was added to the base ToolParser class (in #38029), but Gemma4ToolParser (added in #38826) was written against the old signature. Every other tool parser accepts (tokenizer, tools):

# All other parsers (mistral, hermes, functiongemma, etc.)
def __init__(self, tokenizer: TokenizerLike, tools: list[Tool] | None = None):
    super().__init__(tokenizer, tools)

# Gemma4ToolParser (broken)
def __init__(self, tokenizer: TokenizerLike):
    super().__init__(tokenizer)

Fix Action

Fixed

PR fix notes

PR #38847: [Bugfix]: Fix Gemma4ToolParser.init() missing tools parameter

Description (problem / solution / changelog)

Purpose

Fix Gemma4ToolParser.__init__() to accept the tools parameter, matching the base ToolParser interface.

Without this fix, enabling tool calling with --tool-call-parser gemma4 results in:

400 Gemma4ToolParser.__init__() takes 2 positional arguments but 3 were given

The tools parameter was added to the base ToolParser class in #38029, but the Gemma4ToolParser introduced in #38826 was written against the old signature.

Fixes #38837

Test Plan

vllm serve nvidia/Gemma-4-31B-IT-NVFP4 \
    --enable-auto-tool-choice \
    --tool-call-parser gemma4

Send a chat completion request with tools specified — previously returned 400, now works.

Test Result

Tested on NVIDIA DGX Spark (GB10, SM 12.1) with nvidia/Gemma-4-31B-IT-NVFP4. Tool calls are processed correctly after the fix.


<details> <summary> Essential Elements of an Effective PR Description Checklist </summary>
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update.
</details>

Changed files

  • vllm/tool_parsers/gemma4_tool_parser.py (modified, +3/-3)

Code Example

vLLM version: 0.18.2rc1.dev71 (main branch, post-#38826)
PyTorch: 2.10.0+cu130
CUDA: 13.0
GPU: NVIDIA GB10 (DGX Spark, SM 12.1)
Python: 3.12.13
OS: Linux-6.17.0-1014-nvidia-aarch64-with-glibc2.35

---

400 Gemma4ToolParser.__init__() takes 2 positional arguments but 3 were given

---

vllm serve nvidia/Gemma-4-31B-IT-NVFP4 \
       --enable-auto-tool-choice \
       --tool-call-parser gemma4

---

# All other parsers (mistral, hermes, functiongemma, etc.)
def __init__(self, tokenizer: TokenizerLike, tools: list[Tool] | None = None):
    super().__init__(tokenizer, tools)

# Gemma4ToolParser (broken)
def __init__(self, tokenizer: TokenizerLike):
    super().__init__(tokenizer)

---

-from vllm.tool_parsers.abstract_tool_parser import ToolParser
+from vllm.tool_parsers.abstract_tool_parser import Tool, ToolParser

-    def __init__(self, tokenizer: TokenizerLike):
-        super().__init__(tokenizer)
+    def __init__(self, tokenizer: TokenizerLike, tools: list[Tool] | None = None):
+        super().__init__(tokenizer, tools)
RAW_BUFFERClick to expand / collapse
<details> <summary>The output of <code>python collect_env.py</code></summary>
vLLM version: 0.18.2rc1.dev71 (main branch, post-#38826)
PyTorch: 2.10.0+cu130
CUDA: 13.0
GPU: NVIDIA GB10 (DGX Spark, SM 12.1)
Python: 3.12.13
OS: Linux-6.17.0-1014-nvidia-aarch64-with-glibc2.35
</details>

🐛 Describe the bug

Gemma4ToolParser.__init__() only accepts (self, tokenizer) but the base class ToolParser.__init__() expects (self, tokenizer, tools). When vLLM instantiates the parser, it passes both arguments, resulting in:

400 Gemma4ToolParser.__init__() takes 2 positional arguments but 3 were given

How to reproduce

  1. Serve a Gemma 4 model with tool calling enabled:
    vllm serve nvidia/Gemma-4-31B-IT-NVFP4 \
        --enable-auto-tool-choice \
        --tool-call-parser gemma4
  2. Send a chat completion request with tools specified
  3. Get 400 error immediately

Root cause

The tools parameter was added to the base ToolParser class (in #38029), but Gemma4ToolParser (added in #38826) was written against the old signature. Every other tool parser accepts (tokenizer, tools):

# All other parsers (mistral, hermes, functiongemma, etc.)
def __init__(self, tokenizer: TokenizerLike, tools: list[Tool] | None = None):
    super().__init__(tokenizer, tools)

# Gemma4ToolParser (broken)
def __init__(self, tokenizer: TokenizerLike):
    super().__init__(tokenizer)

Suggested fix

Three-line change in vllm/tool_parsers/gemma4_tool_parser.py:

-from vllm.tool_parsers.abstract_tool_parser import ToolParser
+from vllm.tool_parsers.abstract_tool_parser import Tool, ToolParser

-    def __init__(self, tokenizer: TokenizerLike):
-        super().__init__(tokenizer)
+    def __init__(self, tokenizer: TokenizerLike, tools: list[Tool] | None = None):
+        super().__init__(tokenizer, tools)
  • 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

Update the Gemma4ToolParser.__init__ method to accept the tools parameter and pass it to the base class ToolParser.__init__.

Guidance

  • Verify that the Gemma4ToolParser class is indeed the cause of the issue by checking the stacktrace for the 400 error.
  • Apply the suggested fix by modifying the __init__ method in vllm/tool_parsers/gemma4_tool_parser.py to accept the tools parameter.
  • Test the updated code by serving the Gemma 4 model with tool calling enabled and sending a chat completion request with tools specified.
  • If the issue persists, check the documentation and search for relevant issues to ensure that the fix is correct and complete.

Example

The corrected Gemma4ToolParser.__init__ method should look like this:

from vllm.tool_parsers.abstract_tool_parser import Tool, ToolParser

def __init__(self, tokenizer: TokenizerLike, tools: list[Tool] | None = None):
    super().__init__(tokenizer, tools)

Notes

This fix assumes that the tools parameter is optional and can be None. If this is not the case, the method signature may need to be adjusted accordingly.

Recommendation

Apply the workaround by updating the Gemma4ToolParser.__init__ method to accept the tools parameter, as this is a targeted fix for the identified 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