vllm-sglang-tool-call-parser-debugger 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vllm_sglang_tool_call_parser_debugger-0.1.0/LICENSE +179 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/PKG-INFO +143 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/README.md +122 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/pyproject.toml +37 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/setup.cfg +4 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/tests/test_causes.py +78 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/tests/test_outputs.py +31 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/tests/test_reference.py +61 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/tests/test_server.py +105 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/tests/test_watch.py +100 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/__init__.py +0 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/analyze.py +171 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/capture.py +221 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/cases.py +84 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/causes.py +150 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/chunking.py +87 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/cli.py +269 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/diagnose.py +760 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/answer-returned-as-thinking.tools.json +1 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/answer-returned-as-thinking.txt +1 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/lost-while-streaming.tools.json +19 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/lost-while-streaming.txt +1 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/quoted-markup-becomes-call.tools.json +16 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/quoted-markup-becomes-call.txt +11 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/request.json +30 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/wrong-parser.tools.json +19 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/examples/wrong-parser.txt +3 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/faketok.py +128 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/formats.py +268 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/minimize.py +40 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/realtok.py +86 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/reference.py +203 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/report.py +98 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/runner.py +194 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/sglang_driver.py +163 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/ui.py +257 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/util.py +23 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/vllm_driver.py +447 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger/watch.py +231 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger.egg-info/PKG-INFO +143 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger.egg-info/SOURCES.txt +43 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger.egg-info/dependency_links.txt +1 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger.egg-info/entry_points.txt +3 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger.egg-info/requires.txt +7 -0
- vllm_sglang_tool_call_parser_debugger-0.1.0/vllm_sglang_tool_call_parser_debugger.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
Copyright 2026 Ameerul Ali Shah Pattan
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vllm-sglang-tool-call-parser-debugger
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Find why vLLM and SGLang tool-call parsers break your AI agent's tool calls, and what to fix.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/AmeerulShah/vllm-sglang-tool-call-parser-debugger
|
|
7
|
+
Project-URL: Issues, https://github.com/AmeerulShah/vllm-sglang-tool-call-parser-debugger/issues
|
|
8
|
+
Keywords: vllm,sglang,tool-calling,function-calling,llm-serving,agents,testing
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Topic :: Software Development :: Testing
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: regex
|
|
16
|
+
Provides-Extra: mistral
|
|
17
|
+
Requires-Dist: mistral-common[sentencepiece]; extra == "mistral"
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest; extra == "test"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# vllm-sglang-tool-call-parser-debugger
|
|
23
|
+
|
|
24
|
+
<p align="center"><img src="docs/poster.png" alt="vllm-sglang-tool-call-parser-debugger" width="720"></p>
|
|
25
|
+
|
|
26
|
+
<p align="center"><a href="https://doi.org/10.5281/zenodo.24673045"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.24673045.svg" alt="DOI"></a></p>
|
|
27
|
+
|
|
28
|
+
**Find why vLLM and SGLang tool-call parsers break your AI agent's tool calls, and what to fix.**
|
|
29
|
+
|
|
30
|
+
**For teams running agents on Qwen models served by vLLM: vllm-sglang-tool-call-parser-debugger tells you, in one command, why a tool call, its arguments or the thinking came back wrong, and what to change.** It runs your vLLM version's own serving code on your model's raw output, so no GPU is needed. Every 2026 vLLM issue of this kind that it can see is a test case on vLLM's real server ([the slice](validation/slice/SCORE.md)). It also covers 18 other tool-call formats and SGLang.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install vllm-sglang-tool-call-parser-debugger # where vLLM or SGLang is installed
|
|
34
|
+
tcdebug demo # see it diagnose a real bug report first
|
|
35
|
+
tcdebug --server http://localhost:8000 --request failing_request.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
It sends the failing request to your server as your client does (once; twice for a streamed request on SGLang), gets the model's raw output, and checks it. Here it is on vLLM 0.34.0's own server, replaying the model output from a real report ([vllm#48347](https://github.com/vllm-project/vllm/issues/48347); see `validation/live/`):
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
$ tcdebug --server http://localhost:8000 --request request.json
|
|
42
|
+
tcdebug · vllm 0.34.0 · --tool-call-parser internlm · server vllm 0.34.0
|
|
43
|
+
|
|
44
|
+
note: parser not given: checking --tool-call-parser internlm, the format this output is in. Pass --parser if your server uses another.
|
|
45
|
+
|
|
46
|
+
✗ Your server streamed a wrong result, and the internlm parser causes it: the call to `get_weather` is lost (1 written, 0 returned).
|
|
47
|
+
|
|
48
|
+
The model wrote: get_weather({"city": "Tokyo"}), text "Sure, let me check."
|
|
49
|
+
Your server streamed: text "Sure, let me check." [wrong]
|
|
50
|
+
Replay, your 3 deltas: text "Sure, let me check." [wrong] (3 of them carried several tokens)
|
|
51
|
+
→ The replay of your server's own deltas gives the same wrong result: the parser causes it, not the model or the client.
|
|
52
|
+
Replay, no streaming: get_weather({"city": "Tokyo"}), text "Sure, let me check."
|
|
53
|
+
Replay, all 27 splits: fails in 1/27 · trigger: `.<|action_start|><|plugin|>{"name": "get_weather", "parameters": {"city": "Tokyo"}}<|action_end|>`
|
|
54
|
+
|
|
55
|
+
What to do:
|
|
56
|
+
• Workaround now: `"stream": false` for tool-calling requests (non-streaming returns the right result).
|
|
57
|
+
• Or keep streaming with one token per delta: `--stream-interval 1`, no speculative decoding or MTP, no `--async-scheduling`.
|
|
58
|
+
• Report it upstream with this report: it holds your output, the expected result and the minimal deltas.
|
|
59
|
+
|
|
60
|
+
Full report (ready to attach to an issue): tcdebug-report/vllm-0.34.0-internlm-output.md
|
|
61
|
+
Open the issue: https://github.com/vllm-project/vllm/issues/new?title=%5BBug%5D%3A%20internlm%20tool%20parser%3A%20the%20call%20to%20%60get_weather%60%20is%20lost%20%281%20written%2C%200%20returned%29%20when%20several%20tokens%20share%20a%20stream%20delta
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## What it tells you
|
|
65
|
+
|
|
66
|
+
One verdict, with the fix:
|
|
67
|
+
|
|
68
|
+
- **You chose the wrong parser.** The output is in another model family's format; serve with `--tool-call-parser X`.
|
|
69
|
+
- **A start marker was stripped.** Send `"skip_special_tokens": false`.
|
|
70
|
+
- **The parser drops part of the output:** a call, a parameter or text.
|
|
71
|
+
- **Streaming changes the result.** You get the exact tokens that must share one delta to trigger it, and the workaround.
|
|
72
|
+
- **Quoted markup becomes a call.** An example the model wrote in a code fence comes back as a real tool call.
|
|
73
|
+
- **The arguments are broken:** invalid JSON, duplicate keys, a required parameter missing, or a tool that isn't in the request.
|
|
74
|
+
- **The server ignored the request:** `tool_choice` `required`, a named tool or `none` not honoured, `finish_reason` saying `tool_calls` with no call, or calls without ids (`--server` and `watch`).
|
|
75
|
+
- **The model wrote the call inside its thinking** and never closed it, so the reasoning parser keeps it.
|
|
76
|
+
- **Thinking and answer are mixed up** (add `--reasoning-parser`).
|
|
77
|
+
- **The request or template explains it:** the template switched thinking off but `enable_thinking` wasn't sent, `stop` strings break streamed thinking, `tool_choice` `required` after tool results or with several calls, `tool_choice: null`.
|
|
78
|
+
- **The model explains it:** it ended inside its thinking, was cut off by `max_tokens`, or wrote malformed markup (often speculative decoding).
|
|
79
|
+
- **The parser is fine.** Then look at the client (for example, one that reads `reasoning_content` while vLLM sends `reasoning`).
|
|
80
|
+
|
|
81
|
+
Every run also writes a markdown report, ready to attach to an upstream issue, and prints a link that opens the issue on the engine's tracker with a title filled in.
|
|
82
|
+
|
|
83
|
+
## Four ways to run it
|
|
84
|
+
|
|
85
|
+
**1. Against your running server:** `--server URL --request FILE`, where FILE is the chat request body your agent sent (`model`, `messages`, `tools`, `stream`; an OpenAI SDK `extra_body` is merged in). It reads the engine, the version and, on SGLang, the parser from the server, and shows what your server returned next to what the model wrote. If the request streams on vLLM, it also replays your server's own deltas. It replays with the engine installed where it runs, so run it next to the server's version (it warns on a mismatch). The simplest place is the server's container:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
docker exec -i <container> sh -c 'pip install -q vllm-sglang-tool-call-parser-debugger && tcdebug --server http://localhost:8000 --request -' < failing_request.json
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**2. Watch your agent:** `watch --server URL`. A proxy: point your agent at it instead of the server, and it checks every tool-calling response as it happens, without slowing the stream. Each wrong one gets a verdict and a report with its request and raw output, so you don't need to know which request failed. Your client gets the same responses. (SGLang sends no token ids while streaming, so there streamed responses get the request checks only.) Tested with the official `openai` client in front of vLLM's real server (`validation/live/WATCH.md`).
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
tcdebug watch --server http://localhost:8000 --port 8001 # then use http://localhost:8001/v1
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**3. Offline, from the raw output:** `--output raw.txt` takes the model's text with special tokens kept. `--response resp.json --tokenizer <model>` takes a saved response to a request sent with `"return_token_ids": true`. The parser is detected from the output if you leave out `--parser`. To see it work first, `tcdebug demo` runs it on a real bug report's output that ships with the package.
|
|
98
|
+
|
|
99
|
+
**4. Before an engine upgrade:** `--parser NAME` or `--all`. This runs 12 test cases written in each model's real format through that version's parsers, once without streaming and under 27 ways of splitting the stream. Every failure is shrunk to the tokens that trigger it. Exit code 0 means everything passed, so it works as a CI gate:
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
- run: pip install vllm==0.34.0 vllm-sglang-tool-call-parser-debugger # the version you plan to deploy
|
|
103
|
+
- run: tcdebug --engine vllm --parser qwen3_coder
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Why
|
|
107
|
+
|
|
108
|
+
Agents break when the server mangles a tool call: a call is silently dropped, the arguments are not valid JSON, the thinking leaks into the answer, or the text is cut off. Across 61,576 issues in 10 serving projects, this is the fastest-growing user problem: 4 issues per half-year in early 2024, 292 in late 2026, 778 in total. Many of these bugs appear only when the server sends several tokens in one stream delta (speculative decoding, MTP, `stream_interval`, async scheduling). The engines' own tests rarely catch that, because they stream one token at a time.
|
|
109
|
+
|
|
110
|
+
## How it works
|
|
111
|
+
|
|
112
|
+
- **Your engine's own parser, along its own server path.** Each version is driven the way its server calls the parser, including end-of-stream flushes.
|
|
113
|
+
- **An independent reading of what the model meant.** A lenient reader per format says which calls and text the model wrote. It ignores markup inside code fences. The parser's answer is compared against it, without and with streaming.
|
|
114
|
+
- **Only cuts a real tokenizer can make.** Streams are split only at the model's own token boundaries, and each marker is kept or dropped on decode as the model's tokenizer does. So a finding is never an artifact of an impossible split.
|
|
115
|
+
|
|
116
|
+
Black-box checkers such as toolcall-conformance query a live server. They get whatever chunking the model happens to produce, and they can't say which tokens caused a failure.
|
|
117
|
+
|
|
118
|
+
## Results
|
|
119
|
+
|
|
120
|
+
| Test | Result |
|
|
121
|
+
|---|---|
|
|
122
|
+
| **Qwen on vLLM: every in-scope 2026 issue** (37 of 61; the rest are HTTP 400s, GPU generation, other models), on vLLM's real server and the reporter's version (0.13–0.34) | **36 of 37 solved and verified**, from 15 before this round; 1 partial (workaround found, exact symptom not reproduced) |
|
|
123
|
+
| **30 fresh real reports it had never seen** (blind, random) | Of the 19 in scope: 8 solved and verified (3 before the fixes this test drove), 9 covered but not verifiable here, 2 not covered |
|
|
124
|
+
| `--server` against vLLM's real server (scripted model), on 0.20.2, 0.30.0 and 0.34.0 | 39 of 39 runs right, reasoning included. In every run, the replay equals what the server returned or streamed |
|
|
125
|
+
| Real model outputs from 44 GitHub issues, on the reporters' versions | Verdict names the reported problem in 43; the miss feeds single characters that no tokenizer produces |
|
|
126
|
+
| The same real outputs through vLLM's real server (29 issues, 4 versions) | The replay equals what the server sent in 86 of 86 checks |
|
|
127
|
+
| 40 random real user reports (the set the first fixes were tuned on) | Cause and fix found for 9, verified on the users' own outputs (2 before `--output`); 7 covered but not verifiable; 10 outside what a parser check can see |
|
|
128
|
+
| Reported bugs, replayed exactly | 15 of 15 fail on the affected versions and pass on the versions that fixed them |
|
|
129
|
+
| The same bugs, found blind by the generic cases | 16 of 16, on the right versions |
|
|
130
|
+
| Tracker corrections | 4 closed SGLang issues still reproduce on 0.5.23. 3 open vLLM issues are already fixed in 0.34.0 |
|
|
131
|
+
| Not yet reported (vLLM 0.34.0) | DeepSeek V3/V3.1 cut the text next to a tool call. Mistral v11+ puts trailing text into the arguments when streaming |
|
|
132
|
+
|
|
133
|
+
Details: [docs/VALIDATION.md](docs/VALIDATION.md). Which parser works on which version: [docs/MATRIX.md](docs/MATRIX.md).
|
|
134
|
+
|
|
135
|
+
## Supported
|
|
136
|
+
|
|
137
|
+
- **Engines:** vLLM and SGLang. Tested on vLLM 0.13.0, 0.15.1, 0.16.0, 0.17.0, 0.18.1, 0.19.0, 0.20.2, 0.27.1, 0.30.0, 0.34.0 and SGLang 0.5.9, 0.5.17, 0.5.20, 0.5.23.
|
|
138
|
+
- **Tool parsers:** `hermes`, `qwen3_coder`, `qwen3_xml`, `qwen25`, `deepseek_v3`, `deepseek_v31`, `deepseek_v32`, `deepseek_v4`, `kimi_k2`, `glm45`, `glm47`, `minimax_m2`, `gemma4`, `mistral` (v11+ and pre-v11), `llama3_json`, `pythonic`, `olmo3`, `jamba`, `internlm`. SGLang names (`deepseekv31`, `minimax-m2`, …) work too. `tcdebug list` shows what your installed engine has.
|
|
139
|
+
- **Reasoning + tool pairs:** `qwen3+hermes`, `qwen3+qwen3_coder`, `deepseek_v3+deepseek_v31`, `glm45+glm45`, `glm47+glm47`.
|
|
140
|
+
|
|
141
|
+
A wrong or missing diagnosis is a bug: open an issue with the report attached.
|
|
142
|
+
|
|
143
|
+
License: Apache-2.0.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# vllm-sglang-tool-call-parser-debugger
|
|
2
|
+
|
|
3
|
+
<p align="center"><img src="docs/poster.png" alt="vllm-sglang-tool-call-parser-debugger" width="720"></p>
|
|
4
|
+
|
|
5
|
+
<p align="center"><a href="https://doi.org/10.5281/zenodo.24673045"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.24673045.svg" alt="DOI"></a></p>
|
|
6
|
+
|
|
7
|
+
**Find why vLLM and SGLang tool-call parsers break your AI agent's tool calls, and what to fix.**
|
|
8
|
+
|
|
9
|
+
**For teams running agents on Qwen models served by vLLM: vllm-sglang-tool-call-parser-debugger tells you, in one command, why a tool call, its arguments or the thinking came back wrong, and what to change.** It runs your vLLM version's own serving code on your model's raw output, so no GPU is needed. Every 2026 vLLM issue of this kind that it can see is a test case on vLLM's real server ([the slice](validation/slice/SCORE.md)). It also covers 18 other tool-call formats and SGLang.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install vllm-sglang-tool-call-parser-debugger # where vLLM or SGLang is installed
|
|
13
|
+
tcdebug demo # see it diagnose a real bug report first
|
|
14
|
+
tcdebug --server http://localhost:8000 --request failing_request.json
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
It sends the failing request to your server as your client does (once; twice for a streamed request on SGLang), gets the model's raw output, and checks it. Here it is on vLLM 0.34.0's own server, replaying the model output from a real report ([vllm#48347](https://github.com/vllm-project/vllm/issues/48347); see `validation/live/`):
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
$ tcdebug --server http://localhost:8000 --request request.json
|
|
21
|
+
tcdebug · vllm 0.34.0 · --tool-call-parser internlm · server vllm 0.34.0
|
|
22
|
+
|
|
23
|
+
note: parser not given: checking --tool-call-parser internlm, the format this output is in. Pass --parser if your server uses another.
|
|
24
|
+
|
|
25
|
+
✗ Your server streamed a wrong result, and the internlm parser causes it: the call to `get_weather` is lost (1 written, 0 returned).
|
|
26
|
+
|
|
27
|
+
The model wrote: get_weather({"city": "Tokyo"}), text "Sure, let me check."
|
|
28
|
+
Your server streamed: text "Sure, let me check." [wrong]
|
|
29
|
+
Replay, your 3 deltas: text "Sure, let me check." [wrong] (3 of them carried several tokens)
|
|
30
|
+
→ The replay of your server's own deltas gives the same wrong result: the parser causes it, not the model or the client.
|
|
31
|
+
Replay, no streaming: get_weather({"city": "Tokyo"}), text "Sure, let me check."
|
|
32
|
+
Replay, all 27 splits: fails in 1/27 · trigger: `.<|action_start|><|plugin|>{"name": "get_weather", "parameters": {"city": "Tokyo"}}<|action_end|>`
|
|
33
|
+
|
|
34
|
+
What to do:
|
|
35
|
+
• Workaround now: `"stream": false` for tool-calling requests (non-streaming returns the right result).
|
|
36
|
+
• Or keep streaming with one token per delta: `--stream-interval 1`, no speculative decoding or MTP, no `--async-scheduling`.
|
|
37
|
+
• Report it upstream with this report: it holds your output, the expected result and the minimal deltas.
|
|
38
|
+
|
|
39
|
+
Full report (ready to attach to an issue): tcdebug-report/vllm-0.34.0-internlm-output.md
|
|
40
|
+
Open the issue: https://github.com/vllm-project/vllm/issues/new?title=%5BBug%5D%3A%20internlm%20tool%20parser%3A%20the%20call%20to%20%60get_weather%60%20is%20lost%20%281%20written%2C%200%20returned%29%20when%20several%20tokens%20share%20a%20stream%20delta
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## What it tells you
|
|
44
|
+
|
|
45
|
+
One verdict, with the fix:
|
|
46
|
+
|
|
47
|
+
- **You chose the wrong parser.** The output is in another model family's format; serve with `--tool-call-parser X`.
|
|
48
|
+
- **A start marker was stripped.** Send `"skip_special_tokens": false`.
|
|
49
|
+
- **The parser drops part of the output:** a call, a parameter or text.
|
|
50
|
+
- **Streaming changes the result.** You get the exact tokens that must share one delta to trigger it, and the workaround.
|
|
51
|
+
- **Quoted markup becomes a call.** An example the model wrote in a code fence comes back as a real tool call.
|
|
52
|
+
- **The arguments are broken:** invalid JSON, duplicate keys, a required parameter missing, or a tool that isn't in the request.
|
|
53
|
+
- **The server ignored the request:** `tool_choice` `required`, a named tool or `none` not honoured, `finish_reason` saying `tool_calls` with no call, or calls without ids (`--server` and `watch`).
|
|
54
|
+
- **The model wrote the call inside its thinking** and never closed it, so the reasoning parser keeps it.
|
|
55
|
+
- **Thinking and answer are mixed up** (add `--reasoning-parser`).
|
|
56
|
+
- **The request or template explains it:** the template switched thinking off but `enable_thinking` wasn't sent, `stop` strings break streamed thinking, `tool_choice` `required` after tool results or with several calls, `tool_choice: null`.
|
|
57
|
+
- **The model explains it:** it ended inside its thinking, was cut off by `max_tokens`, or wrote malformed markup (often speculative decoding).
|
|
58
|
+
- **The parser is fine.** Then look at the client (for example, one that reads `reasoning_content` while vLLM sends `reasoning`).
|
|
59
|
+
|
|
60
|
+
Every run also writes a markdown report, ready to attach to an upstream issue, and prints a link that opens the issue on the engine's tracker with a title filled in.
|
|
61
|
+
|
|
62
|
+
## Four ways to run it
|
|
63
|
+
|
|
64
|
+
**1. Against your running server:** `--server URL --request FILE`, where FILE is the chat request body your agent sent (`model`, `messages`, `tools`, `stream`; an OpenAI SDK `extra_body` is merged in). It reads the engine, the version and, on SGLang, the parser from the server, and shows what your server returned next to what the model wrote. If the request streams on vLLM, it also replays your server's own deltas. It replays with the engine installed where it runs, so run it next to the server's version (it warns on a mismatch). The simplest place is the server's container:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
docker exec -i <container> sh -c 'pip install -q vllm-sglang-tool-call-parser-debugger && tcdebug --server http://localhost:8000 --request -' < failing_request.json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**2. Watch your agent:** `watch --server URL`. A proxy: point your agent at it instead of the server, and it checks every tool-calling response as it happens, without slowing the stream. Each wrong one gets a verdict and a report with its request and raw output, so you don't need to know which request failed. Your client gets the same responses. (SGLang sends no token ids while streaming, so there streamed responses get the request checks only.) Tested with the official `openai` client in front of vLLM's real server (`validation/live/WATCH.md`).
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
tcdebug watch --server http://localhost:8000 --port 8001 # then use http://localhost:8001/v1
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**3. Offline, from the raw output:** `--output raw.txt` takes the model's text with special tokens kept. `--response resp.json --tokenizer <model>` takes a saved response to a request sent with `"return_token_ids": true`. The parser is detected from the output if you leave out `--parser`. To see it work first, `tcdebug demo` runs it on a real bug report's output that ships with the package.
|
|
77
|
+
|
|
78
|
+
**4. Before an engine upgrade:** `--parser NAME` or `--all`. This runs 12 test cases written in each model's real format through that version's parsers, once without streaming and under 27 ways of splitting the stream. Every failure is shrunk to the tokens that trigger it. Exit code 0 means everything passed, so it works as a CI gate:
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
- run: pip install vllm==0.34.0 vllm-sglang-tool-call-parser-debugger # the version you plan to deploy
|
|
82
|
+
- run: tcdebug --engine vllm --parser qwen3_coder
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Why
|
|
86
|
+
|
|
87
|
+
Agents break when the server mangles a tool call: a call is silently dropped, the arguments are not valid JSON, the thinking leaks into the answer, or the text is cut off. Across 61,576 issues in 10 serving projects, this is the fastest-growing user problem: 4 issues per half-year in early 2024, 292 in late 2026, 778 in total. Many of these bugs appear only when the server sends several tokens in one stream delta (speculative decoding, MTP, `stream_interval`, async scheduling). The engines' own tests rarely catch that, because they stream one token at a time.
|
|
88
|
+
|
|
89
|
+
## How it works
|
|
90
|
+
|
|
91
|
+
- **Your engine's own parser, along its own server path.** Each version is driven the way its server calls the parser, including end-of-stream flushes.
|
|
92
|
+
- **An independent reading of what the model meant.** A lenient reader per format says which calls and text the model wrote. It ignores markup inside code fences. The parser's answer is compared against it, without and with streaming.
|
|
93
|
+
- **Only cuts a real tokenizer can make.** Streams are split only at the model's own token boundaries, and each marker is kept or dropped on decode as the model's tokenizer does. So a finding is never an artifact of an impossible split.
|
|
94
|
+
|
|
95
|
+
Black-box checkers such as toolcall-conformance query a live server. They get whatever chunking the model happens to produce, and they can't say which tokens caused a failure.
|
|
96
|
+
|
|
97
|
+
## Results
|
|
98
|
+
|
|
99
|
+
| Test | Result |
|
|
100
|
+
|---|---|
|
|
101
|
+
| **Qwen on vLLM: every in-scope 2026 issue** (37 of 61; the rest are HTTP 400s, GPU generation, other models), on vLLM's real server and the reporter's version (0.13–0.34) | **36 of 37 solved and verified**, from 15 before this round; 1 partial (workaround found, exact symptom not reproduced) |
|
|
102
|
+
| **30 fresh real reports it had never seen** (blind, random) | Of the 19 in scope: 8 solved and verified (3 before the fixes this test drove), 9 covered but not verifiable here, 2 not covered |
|
|
103
|
+
| `--server` against vLLM's real server (scripted model), on 0.20.2, 0.30.0 and 0.34.0 | 39 of 39 runs right, reasoning included. In every run, the replay equals what the server returned or streamed |
|
|
104
|
+
| Real model outputs from 44 GitHub issues, on the reporters' versions | Verdict names the reported problem in 43; the miss feeds single characters that no tokenizer produces |
|
|
105
|
+
| The same real outputs through vLLM's real server (29 issues, 4 versions) | The replay equals what the server sent in 86 of 86 checks |
|
|
106
|
+
| 40 random real user reports (the set the first fixes were tuned on) | Cause and fix found for 9, verified on the users' own outputs (2 before `--output`); 7 covered but not verifiable; 10 outside what a parser check can see |
|
|
107
|
+
| Reported bugs, replayed exactly | 15 of 15 fail on the affected versions and pass on the versions that fixed them |
|
|
108
|
+
| The same bugs, found blind by the generic cases | 16 of 16, on the right versions |
|
|
109
|
+
| Tracker corrections | 4 closed SGLang issues still reproduce on 0.5.23. 3 open vLLM issues are already fixed in 0.34.0 |
|
|
110
|
+
| Not yet reported (vLLM 0.34.0) | DeepSeek V3/V3.1 cut the text next to a tool call. Mistral v11+ puts trailing text into the arguments when streaming |
|
|
111
|
+
|
|
112
|
+
Details: [docs/VALIDATION.md](docs/VALIDATION.md). Which parser works on which version: [docs/MATRIX.md](docs/MATRIX.md).
|
|
113
|
+
|
|
114
|
+
## Supported
|
|
115
|
+
|
|
116
|
+
- **Engines:** vLLM and SGLang. Tested on vLLM 0.13.0, 0.15.1, 0.16.0, 0.17.0, 0.18.1, 0.19.0, 0.20.2, 0.27.1, 0.30.0, 0.34.0 and SGLang 0.5.9, 0.5.17, 0.5.20, 0.5.23.
|
|
117
|
+
- **Tool parsers:** `hermes`, `qwen3_coder`, `qwen3_xml`, `qwen25`, `deepseek_v3`, `deepseek_v31`, `deepseek_v32`, `deepseek_v4`, `kimi_k2`, `glm45`, `glm47`, `minimax_m2`, `gemma4`, `mistral` (v11+ and pre-v11), `llama3_json`, `pythonic`, `olmo3`, `jamba`, `internlm`. SGLang names (`deepseekv31`, `minimax-m2`, …) work too. `tcdebug list` shows what your installed engine has.
|
|
118
|
+
- **Reasoning + tool pairs:** `qwen3+hermes`, `qwen3+qwen3_coder`, `deepseek_v3+deepseek_v31`, `glm45+glm45`, `glm47+glm47`.
|
|
119
|
+
|
|
120
|
+
A wrong or missing diagnosis is a bug: open an issue with the report attached.
|
|
121
|
+
|
|
122
|
+
License: Apache-2.0.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vllm-sglang-tool-call-parser-debugger"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Find why vLLM and SGLang tool-call parsers break your AI agent's tool calls, and what to fix."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = ["regex"]
|
|
14
|
+
keywords = ["vllm", "sglang", "tool-calling", "function-calling", "llm-serving", "agents", "testing"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Topic :: Software Development :: Testing",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
mistral = ["mistral-common[sentencepiece]"]
|
|
23
|
+
test = ["pytest"]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/AmeerulShah/vllm-sglang-tool-call-parser-debugger"
|
|
27
|
+
Issues = "https://github.com/AmeerulShah/vllm-sglang-tool-call-parser-debugger/issues"
|
|
28
|
+
|
|
29
|
+
[project.scripts]
|
|
30
|
+
tcdebug = "vllm_sglang_tool_call_parser_debugger.cli:main"
|
|
31
|
+
vllm-sglang-tool-call-parser-debugger = "vllm_sglang_tool_call_parser_debugger.cli:main"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools]
|
|
34
|
+
packages = ["vllm_sglang_tool_call_parser_debugger"]
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.package-data]
|
|
37
|
+
vllm_sglang_tool_call_parser_debugger = ["examples/*"]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Named causes, each from a real Qwen-on-vLLM report (validation/slice/), and the pieces they rest on."""
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from mock_server import serve
|
|
5
|
+
|
|
6
|
+
from vllm_sglang_tool_call_parser_debugger.capture import held_texts, stop_hold
|
|
7
|
+
from vllm_sglang_tool_call_parser_debugger.diagnose import compare_expected
|
|
8
|
+
|
|
9
|
+
TOOLS = [{"type": "function", "function": {"name": "get_weather", "parameters": {
|
|
10
|
+
"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _req(tmp_path, **kw):
|
|
14
|
+
p = tmp_path / "req.json"
|
|
15
|
+
p.write_text(json.dumps({"model": "mock-model", "messages": [{"role": "user", "content": "hi"}], "tools": TOOLS,
|
|
16
|
+
"stream": False, **kw}))
|
|
17
|
+
return str(p)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_template_closed_thinking_reads_prompt_from_server(cli, tmp_path):
|
|
21
|
+
# vllm#53284: the prompt ends with <think></think>, enable_thinking not sent: the answer comes back as reasoning.
|
|
22
|
+
raw = "Sure, here is the plan."
|
|
23
|
+
msg = {"role": "assistant", "content": None, "reasoning": raw}
|
|
24
|
+
srv, url, _ = serve("vllm", raw, msg, version="0.34.0", prompt_tail="<think>\n\n</think>\n\n")
|
|
25
|
+
try:
|
|
26
|
+
r = cli("vllm", "--server", url, "--request", _req(tmp_path, chat_template_kwargs={"reasoning_effort": "none"}),
|
|
27
|
+
"--parser", "qwen3_coder", "--reasoning-parser", "qwen3", "--out", str(tmp_path / "o"))
|
|
28
|
+
finally:
|
|
29
|
+
srv.shutdown()
|
|
30
|
+
assert "already closed the thinking" in r.stdout and '"enable_thinking": false' in r.stdout, r.stdout + r.stderr
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_reasoning_field_note(cli, tmp_path):
|
|
34
|
+
# vllm#37558: vLLM 0.16+ sends `reasoning` only; clients reading `reasoning_content` show nothing.
|
|
35
|
+
raw = "<think>\nCheck the weather.\n</think>\n\n<tool_call>\n{\"name\": \"get_weather\", \"arguments\": {\"city\": \"Paris\"}}\n</tool_call>"
|
|
36
|
+
msg = {"role": "assistant", "content": None, "reasoning": "\nCheck the weather.\n", "tool_calls": [
|
|
37
|
+
{"id": "c1", "type": "function", "function": {"name": "get_weather", "arguments": '{"city": "Paris"}'}}]}
|
|
38
|
+
srv, url, _ = serve("vllm", raw, msg, version="0.34.0")
|
|
39
|
+
try:
|
|
40
|
+
r = cli("vllm", "--server", url, "--request", _req(tmp_path), "--parser", "hermes", "--reasoning-parser", "qwen3",
|
|
41
|
+
"--out", str(tmp_path / "o"))
|
|
42
|
+
finally:
|
|
43
|
+
srv.shutdown()
|
|
44
|
+
assert "`reasoning` field only" in r.stdout, r.stdout + r.stderr
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_thinking_never_closed_is_the_model(cli, tmp_path):
|
|
48
|
+
# vllm#55420: the model samples its end token inside <think>: empty content is the model, not the server.
|
|
49
|
+
out = tmp_path / "raw.txt"
|
|
50
|
+
out.write_text("Let me plan the refactor. First the module layout, then")
|
|
51
|
+
r = cli("vllm", "--output", str(out), "--parser", "qwen3_coder", "--reasoning-parser", "qwen3", "--prompt-think",
|
|
52
|
+
"--out", str(tmp_path / "o"))
|
|
53
|
+
assert "ended inside its thinking" in r.stdout, r.stdout + r.stderr
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_malformed_markup_is_the_generation(cli, tmp_path):
|
|
57
|
+
# vllm#56077: ngram speculative decoding wrote <function=run_shell command="ls">.
|
|
58
|
+
out = tmp_path / "raw.txt"
|
|
59
|
+
out.write_text('<tool_call>\n<function=run_shell command="ls">\n</function>\n</tool_call>')
|
|
60
|
+
r = cli("vllm", "--output", str(out), "--parser", "qwen3_coder", "--out", str(tmp_path / "o"))
|
|
61
|
+
assert "output is malformed" in r.stdout and "generation" in r.stdout, r.stdout + r.stderr
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_string_where_schema_says_array():
|
|
65
|
+
# vllm#43238: qwen3_xml returned an array argument as a JSON string.
|
|
66
|
+
tools = [{"type": "function", "function": {"name": "save", "parameters": {
|
|
67
|
+
"type": "object", "properties": {"tasks": {"type": "array"}}}}}]
|
|
68
|
+
exp = {"calls": [{"name": "save", "args": {"tasks": [{"done": True}]}}], "content": "", "quoted": 0}
|
|
69
|
+
got = {"calls": [{"name": "save", "arguments": json.dumps({"tasks": '[{"done": true}]'})}], "content": None}
|
|
70
|
+
assert any("schema says array" in d for d in compare_expected(exp, got, tools))
|
|
71
|
+
got_ok = {"calls": [{"name": "save", "arguments": json.dumps({"tasks": [{"done": True}]})}], "content": None}
|
|
72
|
+
assert not compare_expected(exp, got_ok, tools)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_stop_strings_hold_back_text():
|
|
76
|
+
# vllm#38789: with stop strings vLLM holds back len(longest stop) - 1 characters of every delta.
|
|
77
|
+
assert stop_hold({"stop": ["Observation:"]}) == 11 and stop_hold({}) == 0
|
|
78
|
+
assert held_texts(["ab", "cd", "ef"], 2) == ["", "ab", "cdef"]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""--output on real model outputs from GitHub issues (validation/real/corpus.py), on vLLM."""
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "validation", "real"))
|
|
8
|
+
from corpus import CORPUS # noqa: E402
|
|
9
|
+
|
|
10
|
+
# issue -> a phrase the verdict must contain (from the grades in validation/real)
|
|
11
|
+
EXPECT = {
|
|
12
|
+
"vllm#17161": "in hermes's format, not llama3_json's",
|
|
13
|
+
"vllm#59218": "'Done.' is not returned as content",
|
|
14
|
+
"vllm#57541": "quoted",
|
|
15
|
+
"vllm#65242": "not valid JSON",
|
|
16
|
+
"vllm#48347": "several tokens share a delta",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.mark.parametrize("issue", sorted(EXPECT))
|
|
21
|
+
def test_real_output(cli, tmp_path, issue):
|
|
22
|
+
e = next(c for c in CORPUS if c["issue"] == issue)
|
|
23
|
+
out = tmp_path / "raw.txt"
|
|
24
|
+
out.write_text(e["output"])
|
|
25
|
+
args = ["--output", str(out), "--parser", e["parser"], "--out", str(tmp_path / "o"), "--markdown"]
|
|
26
|
+
if e.get("tools"):
|
|
27
|
+
import json
|
|
28
|
+
(tmp_path / "tools.json").write_text(json.dumps(e["tools"]))
|
|
29
|
+
args += ["--tools", str(tmp_path / "tools.json")]
|
|
30
|
+
r = cli("vllm", *args)
|
|
31
|
+
assert r.returncode == 1 and EXPECT[issue] in r.stdout, r.stdout[:2000] + r.stderr[-2000:]
|