← Back to Pull requests

fix(llm): align the DeepSeek-V3.2 tool prompt with its parser #6011

Closed
unknown closed this pull request without merging on Nov 05, 2026 08:01 UTC
View on GitHub
unknown unknown commented on Nov 04, 2026 04:02 UTC
Author

What happens

At 2600f287, the DeepSeek-V3.2 catalog template instructs the model to emit V3.1-style tool-call tokens. Its configured deepseek-v3.2 parser reads DSML/plain function_calls blocks, 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 DSML function_calls, invoke and parameter elements. String arguments remain text; other values use JSON. Nonempty argument text that is not a JSON object is represented as an arguments string 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_content is absent or null, separate inline reasoning at the first </think>. Preserve explicit reasoning_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 render tool_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:

  • The updated file against the d2fdaf16 catalog gives 46 failed, 204 passed. With the fix, 250 passed on each interpreter.

  • The selected suite including that file and neighbouring tests gives 1362 passed on each interpreter.

  • The unchanged encoder comparisons match for 40 fixed mode cases and 800 seeded conversations, producing 1600 prompts across two modes. Raw Jinja and Transformers agree.

  • The extended comparison covers 72 histories from actual vLLM postprocessing and three ordering histories. It produces 284 direct renderer-to-encoder matches per interpreter. The encoder rejects eight current ordinary-thinking cases with empty reasoning; their 16 renderer outputs match explicit policy expectations also covered in pytest. These are not counted as encoder matches.

  • Five independent mutations fail the corresponding tests: disabling ordinary normalization, ignoring normalized reasoning during replay, removing explicit-field precedence, splitting at the last closing marker and removing result sorting.
  • 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.py passed.

    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-head d2fdaf16 and 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

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Jackmeson1 Review duration: 1679m
    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
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.7% · Safe to merge
    24.7%