Skip to content

chat : keep DSML markup out of DeepSeek V3.2 string tool arguments - #28612

Draft
iamganesha wants to merge 1 commit into
ggml-org:masterfrom
iamganesha:fix/deepseek-dsml-string-guard
Draft

chat : keep DSML markup out of DeepSeek V3.2 string tool arguments#28612
iamganesha wants to merge 1 commit into
ggml-org:masterfrom
iamganesha:fix/deepseek-dsml-string-guard

Conversation

@iamganesha

@iamganesha iamganesha commented Sep 8, 2026

Copy link
Copy Markdown

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:

  • the actual closing parameter tag, or
  • anything that looks like DSML markup: <| or </|.

Normal angle brackets are still perfectly valid inside string values, so content such as <east> & Osaka continues to work as expected.

I added two regression tests in tests/test-chat.cpp:

  • A parser test with <east> & Osaka inside a string parameter to make sure ordinary angle-bracket content is preserved literally.
  • A grammar test that builds the DeepSeek V3.2 tool grammar, confirms that a clean tool call is accepted, and confirms that a call containing a nested <|DSML|parameter ...> inside the argument value is rejected.

The rejection test fails against current master and passes with this change.

The full test-chat suite 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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. The original fix and the two regression tests were produced with the assistance of Codex Sol. I reviewed the generated changes, verified that they address the issue I reproduced locally, ran the relevant test suite, and take responsibility for the submitted change.

@iamganesha
iamganesha requested review from a team and pwilkin as code owners September 8, 2026 18:41
@github-actions github-actions Bot added the testing Everything test related label Sep 8, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

Hi @iamganesha, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Sep 8, 2026
@github-actions
github-actions Bot marked this pull request as draft September 8, 2026 18:47
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Sep 8, 2026
@iamganesha
iamganesha force-pushed the fix/deepseek-dsml-string-guard branch from 7e96bd2 to 7f14622 Compare September 8, 2026 19:21
@iamganesha

Copy link
Copy Markdown
Author

The Description now follows the template with the requirements section included

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant