Appearance
DeepSeek API strict 模式下 Function Call 返回畸形 JSON
问题
在 Function Calling 中设置 strict: true 时,DeepSeek API 返回的 function.arguments 字段包含畸形 JSON:
json
{"selected: ["A", "C", "D"]}预期应为合法 JSON:
json
{"selected": ["A", "C", "D"]}属性名缺少右引号,导致 JSON.parse() / json.loads() 抛出异常:
JSONDecodeError: Expecting ':' delimiter解决方案
Workaround:在 tool/function 定义中去掉 strict: true:
javascript
// 有问题的写法
{
"type": "function",
"function": { ... },
"strict": true // ← 去掉这行
}
// 正确写法(暂时)
{
"type": "function",
"function": { ... }
}根本原因:DeepSeek API 的 strict 模式(强制 JSON Schema 约束)目前存在 bug,strict: true 时模型的 JSON 序列化逻辑有缺陷,输出会截断属性名引号。
这是 DeepSeek API 的已知 bug,预计后续版本修复。在修复前,生产代码应避免依赖
strict: true,可以在客户端自行校验 JSON 格式。