Text Classifier: Cannot read properties of undefined (reading 'message')

Hello everyone,

I’ve run into a strange issue with n8n. A few days ago, my workflow was working perfectly, but now some nodes have stopped working, and I keep getting the following error:

bash

КопироватьРедактировать

Cannot read properties of undefined (reading 'message')

Issue description:

  • I’m using Gmail Trigger to fetch new emails.
  • Then, an “Assess if message needs a reply” node determines if the email requires a response.
  • After that, the email goes through a Text Classifier to categorize it.
  • Suddenly, this Text Classifier node fails to read “message”, even though the email data is coming through.
  • Gmail Trigger is correctly fetching the email data (including textAsHtml and text).
  • I’ve tested with different OpenAI models (GPT-4o, GPT-4-mini, GPT-3.5-turbo), but the issue persists.
  • No settings were changed since the last time this workflow worked fine.

What I’ve tried:

  1. Restarting n8n – didn’t help.
  2. Updating n8n to the latest version – issue persists.
  3. Creating a new workflow with the same nodes – still getting the same error.
  4. Trying different logic for processing data (JSON Parser, Edit Fields) – no improvement.
  5. Checking input schematext and textAsHtml are both available.

Question:

What might have changed that is causing Text Classifier to not recognize “message”, even though the data is clearly present?
Is there a workaround or fix for this issue?

I’d really appreciate any help!
(Attaching screenshots of my workflow and the error)



{
“nodes”: [
{
“parameters”: {
“pollTimes”: {
“item”: [
{
“mode”: “everyMinute”
}
]
},
“simple”: false,
“filters”: {
“labelIds”: [
“UNREAD”
]
},
“options”: {}
},
“id”: “6c3938cf-3d67-4f9c-a49b-9bd2a2cd5d3f”,
“name”: “Gmail Trigger1”,
“type”: “n8n-nodes-base.gmailTrigger”,
“position”: [
1660,
-260
],
“typeVersion”: 1,
“credentials”: {
“gmailOAuth2”: {
“id”: “AN8RYJKoDMuTEMwl”,
“name”: “Gmail account”
}
}
},
{
“parameters”: {
“jsonSchema”: “{\n "type": "object",\n "properties": {\n "needsReply": {\n "type": "boolean"\n }\n },\n "required": ["needsReply"]\n}\n”
},
“id”: “29979680-ddea-44ff-a462-204568a53aa6”,
“name”: “JSON Parser1”,
“type”: “@n8n/n8n-nodes-langchain.outputParserStructured”,
“position”: [
1960,
0
],
“typeVersion”: 1
},
{
“parameters”: {
“model”: “=gpt-3.5-turbo”,
“options”: {
“responseFormat”: “json_object”,
“temperature”: 0
}
},
“id”: “f293c7a3-97fd-482e-b5ef-65045355d866”,
“name”: “OpenAI Chat1”,
“type”: “@n8n/n8n-nodes-langchain.lmChatOpenAi”,
“position”: [
1820,
0
],
“typeVersion”: 1,
“credentials”: {
“openAiApi”: {
“id”: “hvRVeOzyvPXf9b9g”,
“name”: “OpenAi account”
}
}
},
{
“parameters”: {
“prompt”: "=Subject: {{ $json.subject }}\nMessage:\n{{ $json.textAsHtml }} ",
“messages”: {
“messageValues”: [
{
“message”: “Analyze the subject and message of the email. Determine if the message requires a response. The email may be in Finnish, Estonian, or English. Return your response in this JSON format”
}
]
}
},
“id”: “8c34b2e1-406a-49ac-8ca9-053cd6d70467”,
“name”: “Assess if message needs a reply1”,
“type”: “@n8n/n8n-nodes-langchain.chainLlm”,
“position”: [
1880,
-220
],
“typeVersion”: 1.3,
“retryOnFail”: true,
“maxTries”: 2
},
{
“parameters”: {
“inputText”: “=Subject: {{ $(‘Gmail Trigger1’).item.json.subject }}\nMessage: {{ $(‘Gmail Trigger1’).item.json.textAsHtml }}”,
“categories”: {
“categories”: [
{
“category”: “Kiireelliset ja tärkeät viestit”,
“description”: “Sähköpostit, joissa pyydetään hintatietoja tai kustannusarvioita. Avainsanat: "hinta", "tarjous", "arvio", "kustannus"ellinen", "ASAP", "prioriteetti", "määräaika".”
},
{
“category”: “Hinnatiedustelut”,
“description”: “Sähköpostit, jotka vaativat välitöntä huomiota tai toimintaa. Näihin liittyy usein määräaikoja tai kriittisiä asioita. Avainsanat: "kiireellinen", "ASAP", "prioriteetti", "määräaika".”
},
{
“category”: “Käynnissä olevat projektit”,
“description”: “Sähköpostit, jotka liittyvät käynnissä oleviin projekteihin, kuten päivityksiin tai ongelmiin. Avainsanat: "edistyminen", "käynnissä", "päivitys".”
},
{
“category”: “Laskut ja kirjanpito”,
“description”: “Sähköpostit, jotka liittyvät laskuihin, maksuihin tai kirjanpitoon. Avainsanat: "lasku", "maksu", "kirjanpito", "tilit".”
},
{
“category”: “Tukipyynnöt”,
“description”: “Sähköpostit, joissa pyydetään teknistä tai asiakastukea. Avainsanat: "apua", "tuki", "ongelma", "kysymys".”
},
{
“category”: “Tapaamispyynnöt”,
“description”: “Sähköpostit, joissa pyydetään tai ehdotetaan tapaamista. Avainsanat: "tapaaminen", "ajanvaraus", "aikataulu".”
},
{
“category”: “Mainonta ja promootiot”,
“description”: “Sähköpostit, jotka sisältävät mainontaa tai kampanjoita. Avainsanat: "tarjous", "mainos", "alennus", "kampanja".”
}
]
},
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.textClassifier”,
“typeVersion”: 1,
“position”: [
2220,
-100
],
“id”: “f882cbc8-f5f9-4e97-b73e-e8ac0e0527cd”,
“name”: “Text Classifier1”
},
{
“parameters”: {
“model”: {
“__rl”: true,
“mode”: “list”,
“value”: “gpt-4o-mini”
},
“options”: {
“responseFormat”: “json_object”
}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatOpenAi”,
“typeVersion”: 1.2,
“position”: [
2120,
140
],
“id”: “b195b085-eee4-4c2b-9b98-b350e741d320”,
“name”: “OpenAI Chat Model8”,
“credentials”: {
“openAiApi”: {
“id”: “hvRVeOzyvPXf9b9g”,
“name”: “OpenAi account”
}
}
}
],
“connections”: {
“Gmail Trigger1”: {
“main”: [
[
{
“node”: “Assess if message needs a reply1”,
“type”: “main”,
“index”: 0
}
]
]
},
“JSON Parser1”: {
“ai_outputParser”: [
[
{
“node”: “Assess if message needs a reply1”,
“type”: “ai_outputParser”,
“index”: 0
}
]
]
},
“OpenAI Chat1”: {
“ai_languageModel”: [
[
{
“node”: “Assess if message needs a reply1”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“Assess if message needs a reply1”: {
“main”: [
[
{
“node”: “Text Classifier1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Text Classifier1”: {
“main”: [
,
,
,
,
,
,

]
},
“OpenAI Chat Model8”: {
“ai_languageModel”: [
[
{
“node”: “Text Classifier1”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateId”: “2271”,
“templateCredsSetupCompleted”: true,
“instanceId”: “d234f853a733592736c227a006a21099a0271cb4d2dc30289099364861006e1c”
}
}

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:

n8n version: Using n8n Cloud (latest version)
Database: Default (managed by n8n Cloud)
n8n EXECUTIONS_PROCESS setting: Default (managed by n8n Cloud)
Running n8n via: n8n Cloud
Operating system: Not applicable (n8n Cloud)

Having the same issue, I would really appreciate it if this gets more attention!

Hey @loksa109 and @Hristoslav_Zagortche

I see you’re encountering the “Cannot read properties of undefined (reading ‘message’)” error in your “Assess if message needs a reply” node, even though Gmail Trigger is fetching email data. Since your workflow was working before and stopped suddenly, here are some steps to troubleshoot and fix it:

:white_check_mark: 1. Check If the “textAsHtml” or “text” Field is Available

• The error suggests that $json.textAsHtml is undefined, meaning the email content might not be available.

• In the Gmail Trigger node, verify if the expected fields (textAsHtml or text) are still present.

• Try mapping $json.text instead of $json.textAsHtml in the Assess if message needs a reply node:

{{ $json.text || $json.textAsHtml || “No content available” }}

•	This ensures that at least one of the fields is used, preventing undefined errors.

:white_check_mark: 2. Debug the Data Flow Before the AI Node

• Add a Function Node between the Gmail Trigger and AI nodes.

• Use this Function Node to inspect what data is being passed:

return [{ “debug”: JSON.stringify($json) }];

• Run the workflow and check if textAsHtml or text exists in the debug output.

:white_check_mark: 3. Ensure OpenAI Receives a Valid Input

• If OpenAI Chat Node does not receive a proper message, it might be due to an issue in the prompt formatting.

• Instead of {{ $json.textAsHtml }}, try wrapping it in a fallback:

{{ $json.textAsHtml || “No message content found.” }}

•	If the AI receives an empty string, it may fail and cause errors downstream.

:white_check_mark: 4. Test with a Different Email Format

• If Gmail has changed how it structures the email body, some emails might not contain textAsHtml.

• Try testing with:

• A plain-text email

• An HTML email

• A longer or shorter email

• If some emails work but others fail, it indicates an inconsistency in Gmail’s output.

:white_check_mark: 5. Check n8n Updates & AI Model Behavior

• Since this issue happened without changes, check if:

n8n was updated recently (some versions may handle Gmail data differently).

The AI model behavior changed (GPT-4o, GPT-3.5-turbo might interpret messages differently now).

• If the AI node is returning errors or empty responses, switching models may help.

:pushpin: Recommended Fix

  1. Replace {{ $json.textAsHtml }} with:

{{ $json.text || $json.textAsHtml || “No message content found.” }}

  1. Add a Function Node to debug the data structure .

  2. Try testing different email formats .

  3. Check if n8n was updated and whether AI models behave differently .

Let me know if this helps or if you need further troubleshooting! :rocket:

1 Like

I’m experiencing the same issue. I was working on my workflow when, suddenly, the “Text Classifier” node started throwing an error. I didn’t change anything in the setup—I just left it as it was and tested it again today, and now everything is working fine. It randomly throws that error from time to time without any clear reason. It’s getting pretty frustrating.