hello i currently getting this message when trying to do a gmail soritng automation, i tried different thing, nothing worked Failed to parse. Text: “[{“type”:“text”,“text”:”```json\n{\“Personal\”:true,\“Misc\”:false}\n```“,“annotations”:}]”. Error: [ { “code”: “invalid_type”, “expected”: “object”, “received”: “array”, “path”: , “message”: “Expected object, received array” } ] Troubleshooting URL: OUTPUT_PARSING_FAILURE - Docs by LangChain
Hey @dimi_dimi! This is a classic output parsing error when using AI nodes in n8n.
The error is happening because the LLM is returning an array containing a single string that looks like Markdown JSON, but the n8n Output Parser (likely the JSON one) is expecting a direct JSON object.
Two ways to fix this:
- Adjust the Prompt: Explicitly tell the AI: ‘Return ONLY the JSON object. Do not include markdown formatting, backticks, or any other text.’
- Post-Process with a Code Node: If you can’t get the AI to behave, pipe the output into a Code node before your next step. You’ll need to strip the markdown backticks and use on the content.
The most reliable way is usually to use the ‘Output Parser’ option in the AI Agent node and ensure your Schema is defined as a single object, not an array. If you’re using a specific tool that requires an object, that’s where the mismatch is happening.
Hope that helps you get the sorting working!
Hey @dimi_dimi! This is a classic output parsing error when using AI nodes in n8n.
The error ‘Expected object, received array’ is happening because the LLM is returning an array containing a single string that looks like Markdown JSON, but the n8n Output Parser (likely the JSON one) is expecting a direct JSON object.
Two ways to fix this:
- Adjust the Prompt: Explicitly tell the AI: ‘Return ONLY the JSON object. Do not include markdown formatting, backticks, or any other text.’
- Post-Process with a Code Node: If you can’t get the AI to behave, pipe the output into a Code node before your next step. You’ll need to strip the markdown backticks and use JSON.parse() on the content.
The most reliable way is usually to use the ‘Output Parser’ option in the AI Agent node and ensure your Schema is defined as a single object, not an array. If you’re using a specific tool that requires an object, that’s where the mismatch is happening.
Hope that helps you get the sorting working!