Failed to parse text

I am using the AI-text classifier node and I use Llama3.2. I use Ollama to run the model locally. There is a problem in parsing the answer from the AI-Model. The text classifier node hast to decide if the Chatmessage input belongs to the category correct, incorrect or not existing. Sometimes the parsing works, but most of the time not. I also tried to adjust the systemprompt, but that did not work reliable.
Failed to parse. Text: “{\n “correct”: false,\n " incorrect”: false,\n “not existing”: true\n}“. Error: [\n {\n “code”: “invalid_type”,\n “expected”: “boolean”,\n “received”: “undefined”,\n “path”: [\n " correct”\n ],\n “message”: “Required”\n }\n]\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE/\n

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • **n8n version:**latest version
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): locally
  • **Operating system:**windows

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi n8n Team,

I faced the same issue with AI-text classifier
here my config details :
n8n version:1.68.0
Database (default: SQLite): PostgrSQL
n8n EXECUTIONS_PROCESS setting (default: own, main):Deprecated
Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
Operating system:Ubuntu 22.04

Failed to parse. Text: "```json { "type": "object", "properties": { "Sales": { "type": "boolean", "description": "Should be true if the input has category \"Sales\"" }, "Human Resources (RH)": { "type": "boolean", "description": "Should be true if the input has category \"Human Resources (RH}\"" }, "Business Development": { "type": "boolean", "description": "Should be true if the input has category \"Business Development\"" }, "Procurement": { "type": "boolean", "description": "Should be true if the input has category \"Procurement\"" }, "Other": { "type": "boolean", "description": "Should be true if the input has category \"Other\"" } }, "required": ["Sales", "Human Resources (RH)", "Business Development", "Procurement", "Other"], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } ```". Error: [ { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [ "Sales" ], "message": "Required" }, { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [ "Human Resources (RH)" ], "message": "Required" }, { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [ "Business Development" ], "message": "Required" }, { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [ "Procurement" ], "message": "Required" }, { "code": "invalid_type", "expected": "boolean", "received": "undefined", "path": [ "Other" ], "message": "Required" } ] Troubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE/

Regards

I’m also receiving this error. Have tried a couple different Models in Ollama was well as simplifing the Text Classifier down about as much as possible.

I am facing this error too!

I have this error too with n8n Version 1.77.3

Same problem. I have a Conversational agents connect to Ollama with llama3.2 and a Custom Code Tool that can tell current time.

  • n8n version: 1.78.1
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: OSX (Docker Alpine Linux)

Error details:

{
  "errorMessage": "Failed to parse. Text: \"```json\n{\n  \"action\": \"Final Answer\",\n  \"action_input\": `\"The current time is 21:25:41 GMT+0000 (Coordinated Universal Time), as confirmed by the tools.\"`\n}\n```\n\nI have reformatted the JSON object to satisfy the constraints of Option #2, and included the surrounding markdown code snippet delimiters.\". Error: SyntaxError: Unexpected token '`', ...\"n_input\": `\"The curr\"... is not valid JSON\n\nTroubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE/\n",
  "errorDetails": {},
  "n8nDetails": {
    "n8nVersion": "1.78.1 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "Error: Failed to parse. Text: \"```json",
      "{",
      "  \"action\": \"Final Answer\",",
      "  \"action_input\": `\"The current time is 21:25:41 GMT+0000 (Coordinated Universal Time), as confirmed by the tools.\"`",
      "}",
      "```",
      "",
      "I have reformatted the JSON object to satisfy the constraints of Option #2, and included the surrounding markdown code snippet delimiters.\". Error: SyntaxError: Unexpected token '`', ...\"n_input\": `\"The curr\"... is not valid JSON",
      "",
      "Troubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE/",
      "",
      "    at ChatConversationalAgentOutputParser.parse (/usr/local/lib/node_modules/n8n/node_modules/langchain/dist/agents/chat_convo/outputParser.cjs:62:19)",
      "    at OutputFixingParser.parse (/usr/local/lib/node_modules/n8n/node_modules/langchain/dist/output_parsers/fix.cjs:84:40)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
      "    at AgentExecutor._call (/usr/local/lib/node_modules/n8n/node_modules/langchain/dist/agents/executor.cjs:432:26)",
      "    at AgentExecutor.invoke (/usr/local/lib/node_modules/n8n/node_modules/langchain/dist/chains/base.cjs:58:28)",
      "    at ExecuteContext.conversationalAgentExecute (/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js:74:30)",
      "    at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/dist/nodes/agents/Agent/Agent.node.js:380:20)",
      "    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:633:19)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:882:51",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:1216:20"
    ]
  }
}

I think this can be the problematic JSON with Markdown.

{
  "response": {
    "generations": [
      [
        {
          "text": "```json\n{\n  \"action\": \"Final Answer\",\n  \"action_input\": `\"The current time is 21:25:41 GMT+0000 (Coordinated Universal Time), as confirmed by the tools.\"`\n}\n```\n\nI have reformatted the JSON object to satisfy the constraints of Option #2, and included the surrounding markdown code snippet delimiters."
        }
      ]
    ]
  },
  "tokenUsageEstimate": {
    "completionTokens": 75,
    "promptTokens": 319,
    "totalTokens": 394
  }
}

Ran into the same issue now as well.

Same issue

I am running into the same issue!

Same issue! My json contains words with éáí from my country language (pt-BR), but I put the output json into an online json formatter and its works there. Very frustraiting. I already got the correct response, but cannot use it.

Having this error too with the information extractor, would be great to have a clue how to fix…

Same, anyone managed to figure this out and share?

The issue here is the AI didn’t give you the valid JSON string.

```json\n{\n  \"action\": \"Final Answer\",\n  \"action_input\": `\"The current time is 21:25:41 GMT+0000 (Coordinated Universal Time), as confirmed by the tools.\"`\n}\n```\n\nI have reformatted the JSON object to satisfy the constraints of Option #2, and included the surrounding markdown code snippet delimiters.

First. When start with

 ```json

Then it’s not a valid json string.

Your expected output from AI is

"{\n  \"action\": \"Final Answer\",\n  \"action_input\": \"The current time is 21:25:41 GMT+0000 (Coordinated Universal Time), as confirmed by the tools.\"}"

Maybe change the prompt a bit and use output parser if need in AI.

This will give you the right parse object.

I tried several ways to avoid this and the error continues
n8n 1.99