Skip to content

fix: strip DeepSeek DSML tool-call markers from assistant content - #805

Open
sharadvc wants to merge 1 commit into
lsdefine:mainfrom
sharadvc:fix/dsml-marker-stripping
Open

fix: strip DeepSeek DSML tool-call markers from assistant content#805
sharadvc wants to merge 1 commit into
lsdefine:mainfrom
sharadvc:fix/dsml-marker-stripping

Conversation

@sharadvc

Copy link
Copy Markdown

Problem

DeepSeek's DSML protocol injects tool-call routing markers into the content stream before the actual tool_calls delta arrives. These markers (e.g. <‖DSML‖tool_calls>, <‖DSML‖invoke ...>) leak into the UI when tool calls fail or aren't parsed in time.

Fix

Adds _strip_dsml_markers() — a fast regex filter applied to every content chunk yielded by _parse_openai_sse().

  • Zero overhead on non-DeepSeek streams: the guard short-circuits on chunks that don't contain 'DSML'
  • Catches all known marker variants: full-width , Unicode , ASCII pipe |, and double-escaped forms
  • Applied at both the streaming yield point (real-time UI) and the final block assembly (fallback)

Testing

  • Verified with synthetic SSE chunks containing <‖DSML‖tool_calls>, <‖DSML‖invoke name="ShellCommand" arguments="{...}"> — all stripped cleanly
  • Non-DeepSeek streams unaffected (guard short-circuits)

Closes #804

DeepSeek's DSML protocol injects tool-call routing markers (e.g.
<‖DSML‖tool_calls>, <‖DSML‖invoke ...>) into the content stream
before the actual tool_calls delta arrives.  These markers leak into
the UI when tool calls fail or are not parsed in time.

This adds _strip_dsml_markers() — a fast regex filter applied to every
content chunk yielded by _parse_openai_sse().  The guard short-circuits
on chunks that don't contain 'DSML' so there is zero overhead on
non-DeepSeek streams.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DeepSeek DSML tool-call markers leak into assistant content and streamlit UI

1 participant