Agent Not Passing Data to Tool (mysql_create_table) – "Undefined" Error

NOTE: I cannot add the complete workflow to the topic. I can see the correct preview but getting Error 403 when trying to save. :thinking: Seems like AI Agent tool node is problematic here.

I’m configuring an n8n workflow using a Tools Agent (ChatGPT 4o/Sonnet 3.5) and the mysql_create_table tool via MySQL node. When I send a chat command like “create table cars”, the agent fails to pass any data to the tool. The logs show the error:
Tool: Error during node execution: undefined.

Steps to Reproduce:

  1. The agent receives a message like “create table cars”.
  2. The mysql_create_table tool returns “invalid syntax” or “undefined”.
  3. The tool’s input data appears empty in the logs.
  • n8n version: 1.79.3
  • Database (default: SQLite): MySQL local instance
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): local instance in OS
  • Operating system: Pop!_OS 22.04


Hi there! I can help you troubleshoot this issue. Looking at your screenshots, I can see a few key problems that are causing the MySQL create table operation to fail.

The main issue is that the input parameters ($json.tableName and $json.columns) are undefined, which is causing the SQL syntax error. Here’s how to fix this:

  1. First, modify your Tools Agent prompt to ensure it outputs structured data. Add this to your agent’s system message:
When creating tables, always output JSON in this format:
{
  "tableName": "table_name",
  "columns": "column1 TYPE, column2 TYPE, ..."
}
  1. In the MySQL Create Table node, use this SQL template:
CREATE TABLE IF NOT EXISTS ${tableName} (
  id INT AUTO_INCREMENT PRIMARY KEY,
  ${columns}
);
  1. Add a Function node between the Agent and MySQL node to transform the agent’s output into the correct format if needed.

When testing, try this workflow:

  1. User: “create table cars”
  2. Agent should respond asking for column details: “What columns would you like in the cars table? Please specify the data types.”
  3. User: “make, model, year, price”
  4. Agent should then format this into proper SQL column definitions.

This should resolve the “undefined” error you’re seeing and create the table successfully.

Let me know if you need any clarification or run into other issues!

Looks like a copy/paste answer from AI chat I was getting for the last 2 days… it doesn’t make any sense.

Anyway… I think I just found the solution! When I was playing with the UI some placeholder came up in the text field using “fromAI” so I made:

CREATE TABLE IF NOT EXISTS {{ $fromAI(‘tableName’, , 'string') }} ( id INT AUTO_INCREMENT PRIMARY KEY, {{ $fromAI('columns', , ‘string’) }}
);

and seems to work! Agent now passes the data.

1 Like

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