Skip to content

fix(glm47): improve tool call parsing and content normalization#37386

Merged
chaunceyjiang merged 2 commits intovllm-project:mainfrom
karanb192:fix/glm47-tool-call-bug
Mar 18, 2026
Merged

fix(glm47): improve tool call parsing and content normalization#37386
chaunceyjiang merged 2 commits intovllm-project:mainfrom
karanb192:fix/glm47-tool-call-bug

Conversation

@karanb192
Copy link
Copy Markdown

Summary

  • Improve GLM-4.7 func_detail_regex: Use \S+? instead of .*? for the function name capture group, and make the arg group greedy (.* vs .*?) so all argument pairs are captured correctly. This produces cleaner function names without trailing whitespace/newlines.
  • Simplify func_arg_regex: Replace redundant (?:\\n|\s)* with \s* between </arg_key> and <arg_value> tags.
  • Normalize empty content to None: In Glm4MoeModelToolParser.extract_tool_calls, return content=None instead of content="" when there is no meaningful text before the tool call. This aligns with the OpenAI API convention where content is null when the assistant only produces tool calls.
  • Add GLM-4.7-specific tests: New test file covering zero-argument tool calls, inline args (no newline between name and args), newline-separated args, multiple tool calls, content normalization, and streaming scenarios.
  • Update existing GLM-4.5 tests: Fix expected_content values from "" to None to match the content normalization change.

Test plan

Fixes #37277
Related: #32436, #33877

Fix GLM-4.7 tool call parser regex and normalize empty content to
None for OpenAI API compatibility.

- Improve func_detail_regex to cleanly separate function name from
  args using \S+? instead of .*? to avoid trailing whitespace
- Simplify func_arg_regex by replacing redundant (?:\\n|\s)* with \s*
- Normalize empty/whitespace-only content to None in extract_tool_calls
- Update GLM-4.5 parser tests for the content normalization
- Add GLM-4.7 parser tests for zero-arg calls, inline args, streaming

Fixes: vllm-project#37277
Related: vllm-project#32436, vllm-project#33877
Signed-off-by: karanb192 <karan@example.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves tool call parsing for GLM-4.7 models by refining the regular expressions to handle different formatting and capture function names and arguments more robustly. It also introduces content normalization to align with OpenAI API conventions by treating empty or whitespace-only content as None. The changes are well-supported by new, specific tests for GLM-4.7 and updates to existing tests, ensuring the modifications are correct and don't introduce regressions. The overall changes enhance correctness and maintainability.

Fix test_with_args streaming test that failed because city is declared
as a string type, triggering incremental string streaming.  Split the
arg value chunk so the parser processes <arg_value>, the value content,
and </arg_value> in separate calls, allowing </tool_call> to be
processed in the final call.  Also remove unused FunctionCall/ToolCall
import and apply ruff formatting.

Signed-off-by: karanb192 <karan@example.com>
Copy link
Copy Markdown
Collaborator

@chaunceyjiang chaunceyjiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@chaunceyjiang chaunceyjiang added the ready ONLY add when PR is ready to merge/full CI is needed label Mar 18, 2026
@chaunceyjiang chaunceyjiang enabled auto-merge (squash) March 18, 2026 06:19
@chaunceyjiang
Copy link
Copy Markdown
Collaborator

Did you write this using CC?
@karanb192

@chaunceyjiang chaunceyjiang merged commit fad09e8 into vllm-project:main Mar 18, 2026
45 checks passed
@karanb192
Copy link
Copy Markdown
Author

Did you write this using CC? @karanb192

Yes @chaunceyjiang

wendyliu235 pushed a commit to wendyliu235/vllm-public that referenced this pull request Mar 18, 2026
…-project#37386)

Signed-off-by: karanb192 <karan@example.com>
Co-authored-by: karanb192 <karan@example.com>
@xi1212
Copy link
Copy Markdown

xi1212 commented Mar 19, 2026

Did you write this using CC? @karanb192

Yes @chaunceyjiang
Hello, I noticed that the issue I reported has been marked as fixed. I followed the modifications in the Files changed and updated the files in /usr/local/lib/python3.12/dist-packages/vllm/tool_parsers/, but I still encounter probabilistic invocation failures. The error reported is:

Prompt 3: 'Chris Lee. 42. Interests include jazz music and wo...'
❌ FAILED
-> Error: ValidationError: 1 validation error for TestProfile
Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='Here is the extracted us...Jazz music, woodworking', input_type=str]
For further information visit https://errors.pydantic.dev/2.10/v/json_invalid

Why is this happening?

@chaunceyjiang
Copy link
Copy Markdown
Collaborator

@xi1212 Is your tool_choice set to "required"?

fxdawnn pushed a commit to fxdawnn/vllm that referenced this pull request Mar 19, 2026
…-project#37386)

Signed-off-by: karanb192 <karan@example.com>
Co-authored-by: karanb192 <karan@example.com>
SouthWest7 pushed a commit to SouthWest7/vllm that referenced this pull request Mar 27, 2026
…-project#37386)

Signed-off-by: karanb192 <karan@example.com>
Co-authored-by: karanb192 <karan@example.com>
@xi1212
Copy link
Copy Markdown

xi1212 commented Mar 27, 2026

@xi1212 Is your tool_choice set to "required"?

Sorry,it's my problem

khairulkabir1661 pushed a commit to khairulkabir1661/vllm that referenced this pull request Mar 27, 2026
…-project#37386)

Signed-off-by: karanb192 <karan@example.com>
Co-authored-by: karanb192 <karan@example.com>
Monishver11 pushed a commit to Monishver11/vllm that referenced this pull request Mar 27, 2026
…-project#37386)

Signed-off-by: karanb192 <karan@example.com>
Co-authored-by: karanb192 <karan@example.com>
Signed-off-by: Monishver Chandrasekaran <monishverchandrasekaran@gmail.com>
JiantaoXu pushed a commit to JiantaoXu/vllm that referenced this pull request Mar 28, 2026
…-project#37386)

Signed-off-by: karanb192 <karan@example.com>
Co-authored-by: karanb192 <karan@example.com>
vrdn-23 pushed a commit to vrdn-23/vllm that referenced this pull request Mar 30, 2026
…-project#37386)

Signed-off-by: karanb192 <karan@example.com>
Co-authored-by: karanb192 <karan@example.com>
Signed-off-by: Vinay Damodaran <vrdn@hey.com>
EricccYang pushed a commit to EricccYang/vllm that referenced this pull request Apr 1, 2026
…-project#37386)

Signed-off-by: karanb192 <karan@example.com>
Co-authored-by: karanb192 <karan@example.com>
Signed-off-by: EricccYang <yangyang4991@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GLM47 Tool Call Bug

3 participants