[BUG] deepseek-flash emits internal DSML tool-call markup in content when tools array is omitted but history carries tool_calls
Model: deepseek-flash (also reproduced on deepseek-v4-flash)
API: https://api.deepseek.com/v1/chat/completions (OpenAI-compatible)
Description
When a multi-turn conversation carries a prior assistant tool_calls turn (plus the matching tool result) but the current request omits the tools array, the model still emits a complete, well-formed tool invocation — as raw internal markup in message.content, instead of either the structured tool_calls field or a plain refusal.
The leaked markup is the internal <|DSML| …> envelope:
<|DSML| calls>
<|DSML| invoke name="package_tracker_lookup">
<|DSML| parameter name="tracking_number" string="true">TRK-9902-C</|DSML| parameter>
</|DSML| invoke>
</|DSML| calls>finish_reason is stop, tool_calls is null.
Why this is a bug
The endpoint's own docstring for tool calling says the model either calls a tool through tool_calls or answers in text. Here it does neither: it produces a machine-parseable call in a private internal format the public API never defines. Consequences:
- Leak of internal representation. The
<|DSML|>envelope is DeepSeek's internal tool-call serialization (it also leaks on the web UI, see #1668). It is not part of the documented API surface. - No honest refusal. The model "remembers" the tool from the conversation history and calls it anyway, but the response gives a client no structured channel and no signal (
finish_reason: "stop") that a call was attempted. - Breaks agentic clients silently. A caller parsing only
tool_callssees a successful text reply and proceeds on a hallucinated tool result; a caller naively regexing the content gets a call it cannot answer through the API.
Reproduction (deterministic)
Turn 1 — seed a structured call:
{
"model": "deepseek-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant with tool access."},
{"role": "user", "content": "Please look up the delivery status of parcel TRK-4471-A. You must use the package_tracker_lookup tool; do not answer from memory."}
],
"tools": [{
"type": "function",
"function": {
"name": "package_tracker_lookup",
"description": "Look up the live delivery status of one parcel by its tracking number. Returns status, last scan location and estimated delivery date. This is the only way to obtain parcel status.",
"parameters": {
"type": "object",
"properties": {"tracking_number": {"type": "string", "description": "The parcel tracking number, e.g. TRK-4471-A."}},
"required": ["tracking_number"]
}
}
}],
"temperature": 0
}→ finish_reason: "tool_calls", structured call package_tracker_lookup({"tracking_number": "TRK-4471-A"}). ✅
Turn 2 — replay the history, no tools key:
{
"model": "deepseek-flash",
"messages": [
{"role": "system", "content": "You are a helpful assistant with tool access."},
{"role": "user", "content": "Please look up the delivery status of parcel TRK-4471-A. You must use the package_tracker_lookup tool; do not answer from memory."},
{"role": "assistant", "content": null, "tool_calls": [{"id": "tmem_seed_call", "type": "function", "function": {"name": "package_tracker_lookup", "arguments": "{\"tracking_number\": \"TRK-4471-A\"}"}}]},
{"role": "tool", "tool_call_id": "tmem_seed_call", "content": "status=delivered, last_scan=Berlin DE hub 06:12, eta=<already delivered>"},
{"role": "user", "content": "Thanks. Now also look up parcel TRK-9902-C the same way. You must call the same tool; do not answer from memory."}
],
"temperature": 0
}→ 200, finish_reason: "stop", tool_calls: null, content = the DSML block quoted above. Observed response id: 3bb89e4b-7e68-4a29-b42a-b5504a66287b.
Control — the identical messages with the tools array resent → clean structured tool_calls for TRK-9902-C. So the task itself is answerable; it is the omitted tools key that flips the delivery format.
Expected behavior
The structured tool_calls channel is derived from the conversation history (tools sent once are remembered)
Notes
- Reproduces with
temperature: 0; not sampling noise. - Related: #1668 (DSML envelope leaking on the web UI), #1244 (tool calls intermittently emitted as plain text with
toolspresent — same underlying fall-through, different trigger).
Source: deepseek-ai/DeepSeek-V3