Back Home

GitHub Repo

LangChain Community Reports DeepSeek Tool Result Bloat, with Chinese Test Case Using 5.7× More Tokens

A November 1 report to the LangChain community says the DeepSeek integration converts list-form Chinese tool results into escaped strings, increasing input costs. Another participant reproduced the issue offline, but the API usage multiplier comes from the original author’s test; no official fix has been merged yet.

Dirck van Baburen · Public domain · Image source
zh-Hant

A serialization issue has surfaced in LangChain’s DeepSeek integration that directly affects Chinese-language agent workflows. A report filed on November 1 says langchain-deepseek 1.1.1, when handling a list-form ToolMessage, converts the entire content block into a JSON string. In the author’s Chinese test case, the content grew from 188 characters to 1,041 characters; another participant also reported reproducing the same result offline. Public report and discussion

The key is where the JSON is placed. The tool in the report had already produced Chinese JSON text and placed it inside a text block; the integration layer then called json.dumps on the entire list. Python’s official documentation confirms that the default ensure_ascii=True escapes non-ASCII characters, so Chinese text may become \uXXXX, while the quotation marks in the inner JSON must also be escaped again. If these extra representations remain in the content string read by the model, they change the actual input. Python JSON documentation

The author also called deepseek-chat with the same conversation and tool configuration, changing only the tool message content. The empty-string baseline used 312 prompt tokens, passing the text directly used 416, and the list-block form used 903. After subtracting the baseline, the tool results accounted for 104 and 591 tokens, respectively—about a 5.7× difference. This multiplier describes only that tool result; it should not be read as meaning that the entire conversation or all Chinese requests increase by the same proportion. Test setup and data

LangChain’s official documentation lists ChatDeepSeek as an integration that supports tool calling and token usage reporting. For engineering teams using Chinese search results or knowledge base summaries, the report is a prompt to inspect the final message content sent to the model and verify costs using API usage data. Looking only at the tool’s raw output length may miss extra overhead introduced by the conversion layer. This engineering impact is inferred from the current mechanism; no measurements across different workloads are available yet. Integration documentation

Community members suggested concatenating plain-text blocks into text, while preserving JSON and disabling ASCII escaping for mixed blocks. As of the time of review, the issue remains open, with no maintainer confirmation or related fix PR. Follow-up should examine whether block structure needs to be preserved and whether mixed-content compatibility tests are needed. Fix discussion

Sources

  1. LangChain issue #41609:DeepSeek 清單形式工具結果的 ASCII 跳脫問題
  2. Python json:ensure_ascii 與序列化規則
  3. ChatDeepSeek integration