Error in AI Agent Node - Cannot read properties of undefined (reading 'map')

I have a flow that scrapes 10 websites and the feeds the result of the scrape into an AI agent node to create 10 personalise emails.

The agent runs and gets a result for run 1 but on run 2 it throws the error

Cannot read properties of undefined (reading ‘map’)

The agent is using the Anthropic model and a community node to clean the scraped website data.

Please share your workflow

{
  "errorMessage": "Cannot read properties of undefined (reading 'map')",
  "errorDetails": {},
  "n8nDetails": {
    "n8nVersion": "1.71.3 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "TypeError: Cannot read properties of undefined (reading 'map')",
      "    at _formatContent (/usr/local/lib/node_modules/n8n/node_modules/@langchain/anthropic/dist/utils/message_inputs.cjs:92:39)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/@langchain/anthropic/dist/utils/message_inputs.cjs:216:26",
      "    at Array.map (<anonymous>)",
      "    at _convertMessagesToAnthropicPayload (/usr/local/lib/node_modules/n8n/node_modules/@langchain/anthropic/dist/utils/message_inputs.cjs:164:52)",
      "    at ChatAnthropic._generateNonStreaming (/usr/local/lib/node_modules/n8n/node_modules/@langchain/anthropic/dist/chat_models.cjs:714:75)",
      "    at ChatAnthropic._generate (/usr/local/lib/node_modules/n8n/node_modules/@langchain/anthropic/dist/chat_models.cjs:752:25)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/@langchain/core/dist/language_models/chat_models.cjs:215:96",
      "    at Array.map (<anonymous>)",
      "    at ChatAnthropic._generateUncached (/usr/local/lib/node_modules/n8n/node_modules/@langchain/core/dist/language_models/chat_models.cjs:215:67)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)"
    ]
  }
}

Information on your n8n setup

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

Hi @Robm

Can you try to turn the toggle off for Require Specific Output Format? Because you’re not giving any instructions on the output format but it’s expecting it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.