Fix regex patterns in DeepSeekV31ToolParser to use non-greedy matching#23618
Fix regex patterns in DeepSeekV31ToolParser to use non-greedy matching#23618eric8810 wants to merge 9 commits intovllm-project:mainfrom
Conversation
Change greedy .* to non-greedy .*? in tool call regex patterns to prevent over-matching when parsing function names and arguments in tool calls.
There was a problem hiding this comment.
Code Review
This pull request aims to fix issues with greedy regex patterns in the DeepSeekV31ToolParser by making them non-greedy. The changes to tool_call_regex are correct and comprehensive. However, the change to stream_tool_call_portion_regex is incomplete. While the function_name is now non-greedy, the function_arguments group remains greedy (.*), which can cause it to match beyond the intended arguments, including the <|tool call end|> token. I've provided a critical review comment with a suggested fix to make the argument parsing robust and prevent incorrect tool call extraction during streaming.
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run You ask your reviewers to trigger select CI tests on top of Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. 🚀 |
|
#23454 |
Looks good, thanks for your contribution. |
|
@aarnphm |
|
This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you! |
|
This pull request has been automatically closed due to inactivity. Please feel free to reopen if you intend to continue working on it. Thank you! |
Fix regex patterns in DeepSeekV31ToolParser to use non-greedy matching
Purpose
Fix tool call parsing issues in DeepSeek V3.1 model by changing greedy regex patterns (.) to non-greedy patterns (.?) in the tool parser. This prevents over-matching when parsing function names and
arguments in tool calls, which could lead to incorrect extraction of tool call information from model outputs.
The issue occurs when the model output contains multiple tool separators or special tokens, causing the greedy patterns to match beyond the intended boundaries.
Test Plan
Test the regex pattern changes with various tool call scenarios: