Skip to content

Code node throws "Cannot read properties of undefined (reading 'text')" in version 1.75.2 #12879

Description

@mnaflonso

Describe the problem/error/question

I have a SQL agent connected to a MySQL database. Before the latest version (1.75.2) this worked fine. Now I get the error
"Cannot read properties of undefined (reading 'text')" in my code node.

Was there a problem in version 1.75.2?

What is the error message (if any)?

Cannot read properties of undefined (reading 'text').
Error details:

{
  "errorMessage": "Cannot read properties of undefined (reading 'text')",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "AI Agent1",
    "nodeType": "@n8n/n8n-nodes-langchain.agent",
    "nodeVersion": 1.7,
    "itemIndex": 0,
    "time": "1/27/2025, 10:57:56 PM",
    "n8nVersion": "1.75.2 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "NodeOperationError: Cannot read properties of undefined (reading 'text')",
      "    at ExecuteContext.sqlAgentAgentExecute (C:\\Users\\Mario\\AppData\\Roaming\\nvm\\v22.0.0\\node_modules\\n8n\\node_modules\\@n8n\\n8n-nodes-langchain\\nodes\\agents\\Agent\\agents\\SqlAgent\\execute.ts:139:12)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
      "    at ExecuteContext.execute (C:\\Users\\Mario\\AppData\\Roaming\\nvm\\v22.0.0\\node_modules\\n8n\\node_modules\\@n8n\\n8n-nodes-langchain\\nodes\\agents\\Agent\\Agent.node.ts:432:11)",
      "    at WorkflowExecute.runNode (C:\\Users\\Mario\\AppData\\Roaming\\nvm\\v22.0.0\\node_modules\\n8n\\node_modules\\n8n-core\\src\\WorkflowExecute.ts:1096:8)",
      "    at C:\\Users\\Mario\\AppData\\Roaming\\nvm\\v22.0.0\\node_modules\\n8n\\node_modules\\n8n-core\\src\\WorkflowExecute.ts:1504:27",
      "    at C:\\Users\\Mario\\AppData\\Roaming\\nvm\\v22.0.0\\node_modules\\n8n\\node_modules\\n8n-core\\src\\WorkflowExecute.ts:2065:11"
    ]
  }
}

Please share your workflow/screenshots/recording

Image

This is my workflow:

{
  "nodes": [
    {
      "parameters": {
        "public": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        -180,
        100
      ],
      "id": "1ec9cc79-4704-44df-949a-46fc920c3aac",
      "name": "When chat message received",
      "webhookId": "c0c96495-31b4-4bb8-8a4a-203eb86eb00f"
    },
    {
      "parameters": {
        "agent": "sqlAgent",
        "dataSource": "mysql",
        "options": {
          "prefixPrompt": "=__ASK__\n- Generate syntactically correct SQL queries based on user input.\n- Provide answers to questions about the database in the same language as the input.\n- Handle greetings naturally by responding politely in the same language.\n- If the input includes both a greeting and a query, prioritize answering the query while including a polite greeting.\n\n__CONTEXT__\nYou are an agent designed to interact with an SQL database.\nThe database operates on **Server version: 10.6.20-MariaDB - mariadb.org binary distribution**. It has the following structure:\n\nDatabase Schema:\n1. Table: beneficio\n   - Purpose: This table stores information about benefits, including details about discounts, validity periods, and associations with businesses and categories.\n   - Columns:\n     - beneficio_id: Primary key, unique identifier for each benefit.\n     - nombre: The name of the benefit.\n     - descripcion: The description of the benefit.\n     - condiciones: The conditions of the benefit.\n     - descuento: Benefit discount, a number that indicates how much is discounted.\n     - estado: Indicates if the benefit is active or inactive.\n       - 1 = Active  \n       - 0 = Inactive  \n     - fecha_inicio: The date the benefit starts, indicating when the benefit can be used.\n     - fecha_termino: Benefit end date, after this date, the benefit can no longer be used.\n     - created_at: Timestamp of when the benefit was created.\n     - created_by: Name of the user who created the benefit.\n     - updated_at: Timestamp of the last time the benefit was updated.\n     - updated_by: Name of the user who last updated the benefit.\n     - scrapping: Indicates whether the benefit was scraped or not.\n       - 1 = Yes  \n       - 0 = No \n     - cantidad_visitas: Number of views the benefit has received from users.\n     - propio: Indicates whether the benefit is proprietary or from a credit card.\n       - 1 = Proprietary  \n       - 0 = Credit Card \n     - comercio_id: Foreign key linking to the `comercio` table (comercio.comercio_id).\n     - categoria_id: Foreign key linking to the `categoria` table (categoria.categoria_id).\n2. Table: categoria\n   - Purpose: Stores categories for organizing benefits and businesses hierarchically.\n   - Columns:\n     - categoria_id: Primary key, unique identifier for each category.\n     - descripcion: The name of the category.\n     - categoria_padre_id: Foreign key linking to the `categoria` table (categoria.categoria_id). Indicates parent category.\n     - is_for_beneficio: Specifies if the category is for benefits, businesses, or both.\n       - comercio = Business\n       - ambos = Business and Benefit\n       - beneficio = Benefit\n     - orden: The order in which the categories should be listed.\n3. Table: comercio\n   - Purpose: Stores information about businesses, such as names, descriptions, locations, and statuses.\n   - Columns:\n     - comercio_id: Primary key, unique identifier for each business.\n     - nombre: The name of the business.\n     - descripcion: Brief description of the business.\n     - direccion: Address in Google Maps format.\n     - estado: Business status.\n       - 1 = Active\n       - 0 = Inactive\n     - premiun_comercio: Indicates premium status.\n       - 1 = Premium\n       - 0 = Non-premium\n     - latitud: Latitude for geolocation.\n     - longitud: Longitude for geolocation.\n     - categoria_id: Foreign key linking to the `categoria` table (categoria.categoria_id).\n4. Table: comercio_comentario\n   - Purpose: Stores user comments and ratings for businesses.\n   - Columns:\n     - comercio_comentario_id: Primary key, unique identifier for each comment about a business.\n     - fecha: Date when the comment was registered.\n     - comentario: User's opinion about the business.\n     - puntuacion: User rating (0–5).\n     - comercio_id: Foreign key linking to the `comercio` table (comercio.comercio_id).\n5. Table: dia_semana\n   - Purpose: Store the days of the week.\n   - Columns:\n     - dia_semana_id : Primary key, unique identifier for each day of the week.\n     - dia: Full name of the day of the week.\n     - sigla: Abbreviations of the day of the week.\n6. Table: horario_comercio\n   - Purpose: Store the business hours.\n   - Columns:\n     - horario_comercio_id : Primary key, unique identifier for each business schedule.\n     - hora_inicio: Opening time of the business.\n     - hora_fin: Closing time of the business..\n     - dia_semana_id: Foreign key linking to the `dia_semana` table (dia_semana.dia_semana_id).\n     - comercio_id: Foreign key linking to the `comercio` table (comercio.comercio_id).\n\nBehavior Guidelines:\n - Greeting Handling:\n   - If the input contains a greeting, respond politely in the same language.\n     Example 1: Input: \"Hello, how are you?\" → Output: \"Hello! I'm here to help. How can I assist you today?\"\n     Example 2: Input: \"Hola, ¿cómo estás?\" → Output: \"¡Hola! Estoy aquí para ayudarte. ¿En qué puedo asistirte hoy?\"\n   - If the input includes a greeting and a query, respond to the query while including a polite greeting.\n     Example: Input: \"Hi, can you show me the active benefits?\" → Output: \"Hi! Sure, here’s a list of the active benefits: [...]\"\n - Query Creation:\n   - Generate SQL queries that are syntactically correct and relevant to the input.\n   - Limit results to {top_k} rows using the LIMIT clause unless the user specifies otherwise.\n   - Order results by relevant columns to return meaningful outputs.\n   - Avoid selecting all columns; only retrieve the ones relevant to the query.\n - Error Handling:\n   - If an SQL query fails, rewrite and retry.\n   - Avoid performing DML operations (INSERT, UPDATE, DELETE, DROP, etc.).\n - User-Focused Answers:\n   - Provide concise and meaningful responses based on query results.\n   - DO NOT reveal or explain the structure of the database or its tables.\n     Example:\n       Input: \"Do the stars indicate verified ratings?\" \n       Incorrect Response: \"The table comercio_comentario does not have a field for verifying ratings.\"\n       Correct Response: \"The ratings are not marked as verified.\"\n   - Focus on delivering clear insights without referencing database internals.\n - Non-database Questions:\n   - If the question is unrelated to the database, respond with: \"Lo siento, no puedo contestar.\" \n\n__CONSTRAINTS__\n- The database operates on **Server version: 10.6.20-MariaDB - mariadb.org binary distribution.**\n- The information stored in the database is in Spanish.\n- Always respond in the same language as the input.\n- Never perform any DML operations (e.g., INSERT, UPDATE, DELETE).\n- Limit the output to a maximum of {top_k} rows unless explicitly requested otherwise.\n- Prioritize clarity and accuracy when constructing SQL queries.\n- Use only the given database schema and context for query generation.\n- Avoid mentioning or describing the structure or columns of the database in your responses.\n- If input is unclear, request clarification instead of making assumptions.\n- DO NOT REVEAL OR DISCUSS THE STRUCTURE OF THE DATABASE, INCLUDING:  \n     - Table names.  \n     - Column names.  \n     - Data types.  \n     - Relationships between tables.\n- Frame answers in terms of the requested information without mentioning database details.  \n     Example:  \n     Input: \"¿Cuáles son los beneficios activos?\"  \n     Incorrect: \"Los beneficios activos están en la tabla `beneficio` y tienen un estado de 1.\"  \n     Correct: \"Aquí tienes los beneficios activos: [...]\"  \n   - If the input mentions concepts like \"table,\" \"column,\" or \"data type,\" politely redirect the conversation to focus on user needs without confirming or denying the database structure.  \n     Example:  \n     Input: \"¿La tabla de beneficios tiene una columna de fecha?\"  \n     Response: \"Lo siento, no puedo proporcionar esa información. ¿Hay algo más en lo que pueda ayudarte con los beneficios?\"  "
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        240,
        100
      ],
      "id": "a2ca8659-a3d8-445e-880d-13b88788d351",
      "name": "AI Agent1",
      "credentials": {
        "mySql": {
          "id": "arhOqNd5JLbzfHG4",
          "name": "MySQL account"
        }
      }
    },
    {
      "parameters": {
        "model": "=deepseek/deepseek-chat",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.1,
      "position": [
        220,
        280
      ],
      "id": "29a351f2-aeca-436a-9347-bac119ad87e1",
      "name": "OpenAI Chat Model1",
      "credentials": {
        "openAiApi": {
          "id": "1KylwHJ9DViTUMYa",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {
        "contextWindowLength": 10
      },
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "typeVersion": 1.3,
      "position": [
        440,
        280
      ],
      "id": "9a73127d-ade9-4076-a5fe-4a3c4c15f4c5",
      "name": "Postgres Chat Memory",
      "credentials": {
        "postgres": {
          "id": "xv08LH2Jq4yPytlA",
          "name": "Postgres account"
        }
      }
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "ab36529844e3c8aab42cfa229506c9c8b42dd570174ea0e047a12b5165f8dbba"
  }
}

Share the output returned by the last node

This is de data from the previous node (Chat:

[
  {
    "sessionId": "ca5268f0006442eb84b2c3d13ef72d43",
    "action": "sendMessage",
    "chatInput": "hi"
  }
]

Debug info

core

  • n8nVersion: 1.75.2
  • platform: npm
  • nodeJsVersion: 22.0.0
  • database: MySql
  • executionMode: regular
  • concurrency: -1
  • license: community

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: memory

pruning

  • enabled: true
  • maxAge: 336 hours
  • maxCount: 10000 executions

client

  • userAgent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/132.0.0.0 safari/537.36
  • isTouchDevice: false

Generated at: 2025-01-27T14:07:52.616Z}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions