Agent generating a python code and using it to visualize results?

Describe the problem/error/question

Hello! I have recently started doing some tests on n8n, and I would love to get some help please. I have been trying to create a local multiagent enviorment using ollama that basically consists on four agents. The first one is going to rewrite the user input to upgrade it. The second agent is going to generate a sql code for that new input. This code will be executed on the database (named superheroes). And here lays the question. The third agent is just going to comment the results of the code, nothing more. However, the last agent needs to write some Python code to create a bar chart (or the most suited type) for the outcome. This same code should be executed on n8n to generate the chart. I have been trying to use Quickchart as a tool, but I dont have any idea if this is the correct path. Lets just say, if the results from the SQL code are
Id |apparitions_number|
|1 | 10 |
|2 | 21 |
|3 | 34 |
|4 | 4 |

The X axis should be id, and the Y one should be the apparitions_number. The pythonc code should be capable of doing this. And then execute via Quickchart

Share the output returned by the last node

Received tool input did not match expected schema. I try to return the outcome to the agent, but it just keeps sayhing things like that. I dont know what Im doing wrong, or what kind of modification could be done.

Information on your n8n setup

  • n8n version: latest version
  • Database: mySQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm locally
  • Operating system: Windows 11

Your workflow connects an AI Agent (AI Agent3) to QuickChart through the Tool interface. However, the QuickChart node expects a toolInput with specific properties, while AI Agent3 simply generates a string of Python code from the prompt.

This causes the error, “Received tool input did not match expected schema.”
Because the output is not a structured JSON object with the keys QuickChart expects (such as chartConfig, data, labels, etc.).

Do not pass Python directly to QuickChart. QuickChart works with Chart.js configuration, not Python or matplotlib.

Change the AI Agent3 prompt to generate a valid chartConfig object:
Generate only JSON like:

{ 
"chartConfig": { 
"type": "bar", 
"data": { 
"labels": ["Value"], 
"datasets": [{ "label": "Count", "data": [{{ $json['COUNT(id)'] }}] }] 
} 
}
}

Do not generate Python code or text explanation.

1 Like

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