chat : keep DSML markup out of DeepSeek V3.2 string tool arguments - #28612
Draft
iamganesha wants to merge 1 commit into
Draft
chat : keep DSML markup out of DeepSeek V3.2 string tool arguments#28612iamganesha wants to merge 1 commit into
iamganesha wants to merge 1 commit into
Conversation
|
Hi @iamganesha, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
iamganesha
force-pushed
the
fix/deepseek-dsml-string-guard
branch
from
September 8, 2026 19:21
7e96bd2 to
7f14622
Compare
Author
|
The Description now follows the template with the requirements section included |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
I ran into this on 6 September while testing DeepSeek V4 Flash 0731 (Unsloth UD-IQ3_XXS) locally on an AMD Strix Halo system. llama.cpp handles its tool format through the DeepSeek V3.2 DSML parser.
During one of the tool loops, the model misspelled a closing parameter marker. Instead of treating that as malformed DSML, the parser swallowed it as part of the string argument. The model then kept generating until it eventually hit the token ceiling.
Tracing that back led to the DeepSeek V3.2 tool-call parser in
common/parsers/deepseek.cpp.At the moment, string parameter values are parsed using a bare
until(PARAM_END). Because of that, the value can consume anything up to the next valid closing parameter tag — including text that itself looks like malformed or unexpected DSML markup.The same PEG is also used to build the sampling grammar, so constrained generation can technically produce stray or nested
<|DSML|...>markup inside a string value and still have it accepted by the grammar.This change tightens that behaviour.
A string value now stops when it encounters either:
<|or</|.Normal angle brackets are still perfectly valid inside string values, so content such as
<east> & Osakacontinues to work as expected.I added two regression tests in
tests/test-chat.cpp:<east> & Osakainside a string parameter to make sure ordinary angle-bracket content is preserved literally.<|DSML|parameter ...>inside the argument value is rejected.The rejection test fails against current master and passes with this change.
The full
test-chatsuite also passes.Additional information
The original failure I saw was not a nested parameter tag. DeepSeek V4 Flash misspelled a closing parameter marker, the parser treated that malformed DSML as part of the argument string, and generation continued until the token limit.
The nested-tag case in the regression test is a simpler deterministic way of exercising the same parser bug: DSML-looking markup should never be allowed to disappear into an ordinary string parameter.
Requirements