mirror of
https://github.com/deepseek-ai/DeepSeek-V3.git
synced 2026-11-05 00:47:48 +00:00
[GH-ISSUE #1256] [BUG] 在工具调用中参数的 JSON 格式经常括号不匹配 #812
Labels
No labels
closed-as-stale
enhancement
question
spam
stale
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepSeek-V3#812
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @weizhang-dotcom on GitHub (Apr 28, 2026).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-V3/issues/1256
Describe the bug
在工具调用中,参数如果要求是 JSON格式,参数的JSON字符串的括号会不匹配,导致工具调用失败。该问题在V3和V4都存在。
To Reproduce
Expected behavior
JSON格式不出错。
Screenshots
Additional context
这是deepseek-v4 生成的某个工具的arguments. (已作格式化)
@qingkong66 commented on GitHub (Apr 28, 2026):
@weizhang-dotcom 感谢这份非常具体的 bug 报告。你给出了明确的复现条件(嵌套深度 5 层开始不稳、9 层几乎必错),还附带了完整的错误 JSON 示例——这已经是一份可以直接递给官方工程团队的材料。
问题定性
这不是“模型偶尔写错格式”,是 模型在生成长嵌套 JSON 时,括号匹配的状态在自回归过程中丢失了。V3 和 V4 都有,说明这个缺陷贯穿了两个版本。
社区里的关联讨论
建议方向(供你参考,也可作为给官方的输入)
arguments字段引入约束解码(constrained decoding),强制模型只能输出符合 JSON 语法的 token。我们会怎么跟进
已收录到第二期反馈,单独归类为“结构化生成 / JSON 格式稳定性”。同时标记为与 #1241 关联但不合并。
感谢你把这个硬骨头翻出来。如果你还有补充,欢迎随时可以加上。
--
@weizhang-dotcom Thanks for this detailed bug report. You've provided clear reproduction conditions (nesting depth of 5 starts to fail, depth of 9 almost always fails) and a complete malformed JSON example — this is already material that can be handed directly to the official engineering team.
What this issue is
This is not "the model occasionally writes malformed JSON." It's the model losing bracket-matching state during autoregressive generation of deeply nested JSON. The fact that it exists in both V3 and V4 means this defect spans both versions.
Related discussions in the community
Suggested directions (for your reference, and as input to the official team)
argumentsfield, forcing the model to output only JSON-syntactic tokens.What we'll do with this
Added to the second batch of feedback, categorized under "structured generation / JSON format stability." Also linked to #1241 as related but not merged.
Welcome to add more if you have further findings.
Thanks for surfacing this hard issue.
@weizhang-dotcom commented on GitHub (Apr 30, 2026):
补充AI的自我分析原因是,blockly的block id 中包含过多特殊字符,导致它的json解析时出现问题。希望deepseek LLM 在这方面继续加强训练。我回去修改这个block id 的生成规则,看看有没有改进。
@github-actions[bot] commented on GitHub (Jun 1, 2026):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!
@icophy commented on GitHub (Jun 1, 2026):
@weizhang-dotcom Your special-char observation matters, because two distinct failure surfaces get conflated under "the JSON is broken":
",\, and control chars inside string literals, which a pure bracket-counter won't catch even if structure is valid.We run long-lived agents that emit tool-call
argumentsevery turn on OpenAI/Anthropic-compatible endpoints, and we treat every payload as untrusted output. Two things that work today without waiting on a provider-side fix:addBlock+tempIddesign already half-does this — replacing one deeply nestedblockJsonwith a flat list of ops referenced by id makes the tree shallower, and shallow trees fail far less often. So your plan to fix the block-id generation rule is the right lever: fewer special chars and shallower nesting both shrink the surface.One question: have you tried lowering temperature for these calls? Structured-output stability is often temperature-sensitive, so it may be a cheap stopgap while the deeper fix lands — curious whether it moves the needle at your nesting depths.
Context: Working on Cophy Runtime, running long-lived agents that emit tool-call arguments every turn.
@github-actions[bot] commented on GitHub (Jul 15, 2026):
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!
@github-actions[bot] commented on GitHub (Aug 4, 2026):
false