n8n AI Agent 报错“Failed to parse tool arguments... Text: “[]“. SyntaxError” 完美解决方案(2025 年最新)
n8n AI Agent 报错“Failed to parse tool arguments… Text: “[]”. SyntaxError” 完美解决方案(2025 年最新)
最近在用 n8n 搭建 AI Agent 工作流时,频繁遇到这个让人头疼的报错:Failed to parse tool arguments from chat model response. Text: "[]". SyntaxError: Expected ',' or '}' after property value in JSON at position 45 (line 1 column 46) Troubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE/
错误核心原因
LLM(比如 OpenAI、Groq、Ollama、Deepseek 等)在调用工具(Tool Calling / Function Calling)时,返回了一个空的工具参数列表 [],但 n8n 的 LangChain 输出解析器试图把它当成有效的 JSON 对象来解析,导致出现问题
简单说:模型本该返回类似 {“name”: “tool_name”, “arguments”: {“param1”: “value”}} 的结构,但它只返回了空数组 [],解析器不接受,就炸了。
触发原因通常是:
- 模型“幻觉”了,以为自己不需要调用任何工具,直接在最终回答里写了答案(尤其提示词不够严苛时)。
- 使用了不支持/支持不好的工具调用模型(比如某些老版本的 Ollama 模型、某些本地模型)。
- 提示词(System Prompt)没有强迫模型“必须只在需要工具时才调用工具,否则直接回复”。
- 最要命的:在 AI Agent 节点直接挂 Structured Output Parser,如下图所示

本文的解决办法来源于官方文档:
n8n 官方在 Structured Output Parser 的常见问题页面写得清清楚楚: Structured output
parsing is often not reliable when working with agents. If your
workflow uses agents, n8n recommends using a separate LLM-chain to
receive the data from the agent and parse it. 翻译:Agent + Structured
Output Parser 组合非常不靠谱,强烈建议用一个独立的 LLM Chain 来接收 Agent 输出并进行结构化解析。
官方文档地址:
https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.outputparserstructured/common-issues/
正确流程应该是:
触发节点 → AI Agent(只负责思考和调用工具,关闭结构化输出)
→ LLM Chain(专门负责把 Agent 的乱七八糟输出转成干净 JSON)
→ Structured Output Parser(挂在这里,成功率 99.9%)
→ 后续节点
如下图所示
本文还提供了模板代码,可直接导入的完整n8n Workflow JSON
{
"nodes": [
{
"parameters": {
"promptType": "define",
"text": "=新闻标题:{{ $('Read URL content').item.json.title }}\n新闻内容:{{ $json.output[\"网页内容\"] }}",
"options": {
"systemMessage": "## 系统角色\n你是资深「今日头条微头条」创作者与编辑,目标是在不违背事实与平台规范的前提下,围绕今日热榜与我指定的【领域】快速产出150–400 字的高互动微头条。\n\n## 输出格式:\n{\n \"头条标题\":\"XXXX,XXXX,XXXXX\"\n \"头条内容\":\"XXXXXX\"\n\n}"
}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 3,
"position": [
1648,
576
],
"id": "a70ff83f-f7b1-465e-8054-23eb3f943035",
"name": "头条"
},
{
"parameters": {
"model": "deepseek-reasoner",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
"typeVersion": 1,
"position": [
1648,
800
],
"id": "884beaa0-d4b2-499b-a871-4dacc3cdbc6e",
"name": "DeepSeek Chat Model2",
"credentials": {
"deepSeekApi": {
"id": "kacnlIU8NKyBuzcy",
"name": "DeepSeek account"
}
}
},
{
"parameters": {
"jsonSchemaExample": "{\n \"头条标题\":\"XXXX,XXXX,XXXXX\",\n \"头条内容\":\"XXXXXX\"\n}"
},
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"typeVersion": 1.3,
"position": [
2080,
784
],
"id": "de38e68c-abcf-43a0-a461-7a690a3ff18d",
"name": "Structured Output Parser2"
},
{
"parameters": {
"promptType": "define",
"text": "={{ $json.output }}",
"hasOutputParser": true,
"messages": {
"messageValues": [
{
"message": "你是一个严格的 JSON 提取/生成助手。\n从前面的AI Agent 输出中,提取或生成符合以下 JSON Schema 的内容。\n即使 Agent 输出很乱,你也要尽量修复并输出正确的 JSON。\n只输出 JSON,不要任何解释、markdown、代码块、前言后语。\n{\n \"头条标题\":\"XXXX,XXXX,XXXXX\",\n \"头条内容\":\"XXXXXX\"\n}"
}
]
},
"batching": {}
},
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"typeVersion": 1.7,
"position": [
1952,
576
],
"id": "3178f952-edbb-4d96-8153-01fc93e51d81",
"name": "Basic LLM Chain"
},
{
"parameters": {
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
"typeVersion": 1,
"position": [
1936,
784
],
"id": "11bd17f1-97e1-4386-b257-153df33b15b5",
"name": "DeepSeek Chat Model4",
"credentials": {
"deepSeekApi": {
"id": "kacnlIU8NKyBuzcy",
"name": "DeepSeek account"
}
}
}
],
"connections": {
"头条": {
"main": [
[
{
"node": "Basic LLM Chain",
"type": "main",
"index": 0
}
]
]
},
"DeepSeek Chat Model2": {
"ai_languageModel": [
[
{
"node": "头条",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Structured Output Parser2": {
"ai_outputParser": [
[
{
"node": "Basic LLM Chain",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Basic LLM Chain": {
"main": [
[]
]
},
"DeepSeek Chat Model4": {
"ai_languageModel": [
[
{
"node": "Basic LLM Chain",
"type": "ai_languageModel",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "edbcfffffdae1c19473ac55f135d2bbf01921e80e2a6abc48c43437e48dd27ce"
}
}
更多推荐


所有评论(0)