fix(llm): align the DeepSeek-V3.2 tool prompt with its parser #6011
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.57) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #6011"
general
weight: 0.35
Jackmeson1
What happens
At
2600f287, the DeepSeek-V3.2 catalog template instructs the model to emit V3.1-style tool-call tokens. Its configureddeepseek-v3.2parser reads DSML/plainfunction_callsblocks, so it returns the instructed V3.1 syntax as ordinary content.Tool-result history also uses V3.1 tokens, and an assistant message with
tool_calls: []loses its text. Out-of-order results can be paired with the wrong invocation when replayed positionally.Replaying vLLM's inline reasoning can add a second closing thinking tag or retain completed-turn reasoning as answer text. Ordinary replies with explicitly separated reasoning can also lose answer text containing a literal closing marker.
Cause
The V3.2 template retains V3.1's tool instruction, assistant call history and result format. It mishandles empty tool-call lists and does not consistently replay the current turn's reasoning. Result rendering follows arrival order, and assistant replies do not consistently separate reasoning embedded in content.
Change
Use DeepSeek's V3.2
TOOLS_SYSTEM_TEMPLATE, with one JSON schema line per tool, and replay assistant calls using DSMLfunction_calls,invokeandparameterelements. String arguments remain text; other values use JSON. Nonempty argument text that is not a JSON object is represented as anargumentsstring parameter.Replay tool results in
<function_results>blocks containing<result>elements ordered by the corresponding call IDs within each round. Missing or unrecognized IDs retain their results after matched results in relative arrival order. Completed results continue with<think>in the current thinking turn or</think>otherwise.Normalize reasoning for every assistant reply, including ordinary replies after tool results. When
reasoning_contentis absent or null, separate inline reasoning at the first</think>. Preserve explicitreasoning_content, including an empty string, and retain answer text verbatim when reasoning is already separated. Replay reasoning once in the current thinking turn, omit it from completed turns, and rendertool_calls: []as an ordinary assistant message.Remove literal template padding while preserving whitespace inside payloads, keep the encoder's newline for calls without arguments, and omit the tool instruction when the tools list is empty. Removing padding changes ordinary prompt bytes too.
The parser and other DeepSeek catalogs are unchanged. For the tested histories accepted by the saved official V3.2 encoder, complete prompts match its output after removing its leading BOS token. Assistant-ending histories explicitly disable the generation prompt; user-ending histories and tool-result continuations retain their corresponding prefixes.
For reversed results and inline reasoning, the encoder receives equivalent histories with results already ordered and reasoning separated, as its positional interface expects. Empty-reasoning ordinary replies in the current thinking turn are checked against explicit policy expectations because the saved encoder rejects them.
Developer-role encoding and the encoder's prompt-level response-format section remain outside this tool-format change. No Python encoder asset or shared dispatch change is introduced.
Tests
The regressions exercise real catalog selection, argument normalization, actual vLLM postprocessing and
VLLMChatModel._prepare_chat_inputs(), the configured parser and an offline Transformers tokenizer.Ordinary replies, replies after tool results and tool-call replies are replayed with reasoning exposure off/on, in current/completed turns and chat/thinking modes, through raw Jinja and the tokenizer. Cases include empty/null reasoning, optional opening thinking tags, the first closing boundary, literal closing markers in separated answers, reversed parallel results across successive rounds, incomplete results, empty tool-call lists, missing tool descriptions and payload whitespace. Tokenizer cases verify that its renderer was used.
On Windows with Python 3.10.20 and 3.14.6 and Transformers 5.17.0:
d2fdaf16catalog gives 46 failed, 204 passed. With the fix, 250 passed on each interpreter.The official encoder runs in an isolated process. Comparisons account explicitly for BOS and generation-prefix behavior and preserve payload whitespace.
Pre-commit on the changed files plus
xinference/types.pypassed.On Ubuntu 24.04.5 with Python 3.12.3 (Transformers 5.x and the CI pin 4.57.6) and 3.10.22, the test file gave 250 passed on each. Changed-file pre-commit passed there too.
The documentation generator produced identical output for all 401 snapshotted files with the original
2600f287, PR-headd2fdaf16and fixed catalogs. The offline-mirror suite gives 84 passed on each Windows interpreter.Native macOS and a V3.2 checkpoint were not run. These checks establish prompt/replay behavior, not model generation quality.
AI disclosure: this was prepared with AI assistance (Claude Opus 5.5, Claude Sonnet 5.5 and OpenAI Codex).
🤖 Generated with Claude Code
https://claude.ai/code/session_01JfvcPZyKcKQUG9fQGYfRMw