n8n-code-tool

Write JavaScript or Python code for the n8n Custom Code Tool invoked by AI agents.

6.2k|1.0k|Updated Oct 20, 2025
One-click install
npx skills add https://github.com/czlonkowski/n8n-skills --skill n8n-code-tool
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: n8n-code-tool
Source: https://github.com/czlonkowski/n8n-skills/tree/main/skills/n8n-code-tool
Command: npx skills add https://github.com/czlonkowski/n8n-skills --skill n8n-code-tool

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Developers frequently confuse the n8n Custom Code Tool (@n8n/n8n-nodes-langchain.toolCode) with the regular Code node, causing cryptic runtime errors like "Wrong output type returned" and "No execution data available" when building AI-agent-callable tools.

Core Features & Use Cases

  • Contract Clarification: Teaches the Code Tool's string-in/string-out contract, the query/_query input variable, and which sandbox helpers ($fromAI, $input, $helpers) are unavailable.
  • Structured Input Schemas: Explains how to enable specifyInputSchema with fromJson or manual JSON Schema so the LLM passes validated typed arguments instead of free-form strings.
  • Error Catalog: Maps the signature runtime errors to exact causes and fixes, including AI agents that never invoke the tool due to generic names or vague descriptions.
  • Use Case: You attach a Code Tool to an AI Agent to calculate loan payments; this skill shows how to name the tool, parse the query input, return JSON.stringify output, and avoid $fromAI() misuse.

Quick Start

Ask the AI to write an n8n Custom Code Tool that reads the query input and returns a JSON-stringified result for your AI Agent workflow.

Frequently Asked Questions about n8n-code-tool

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Custom Code Tool for an n8n AI Agent?▼

Create a node of type @n8n/n8n-nodes-langchain.toolCode, read input from the query variable (or _query in Python), and return a string. Connect it to the AI Agent via the ai_tool connection and give it a descriptive snake_case name.

What is the difference between the n8n Code node and Code Tool?▼

The Code node (n8n-nodes-base.code) receives items via $input.all() and returns [{json:{...}}]. The Code Tool (@n8n/n8n-nodes-langchain.toolCode) is invoked by an AI Agent, receives a query string or object, and must return a string.

Why does my n8n Code Tool throw "Wrong output type returned"?▼

This error occurs when you return the workflow item format [{json:{...}}], which belongs to the regular Code node. The Code Tool follows the LangChain tool contract and must return a string, so wrap structured data in JSON.stringify().

Does $fromAI work inside the n8n Custom Code Tool?▼

No, $fromAI() is not available in the Code Tool sandbox and throws "No execution data available". Read AI-supplied input from the query variable, or use toolWorkflow or HTTP Request Tool if you need $fromAI bindings.

How do I pass multiple typed parameters to an n8n Code Tool?▼

Set specifyInputSchema to true and define the schema via schemaType fromJson (an example JSON, requires v1.3+) or manual (a full JSON Schema). The LLM then passes a validated object as query that you can destructure directly.

Why does my AI agent never call the Code Tool?▼

Generic names like "Code Tool" and vague descriptions give the LLM no invocation signal. Rename the tool to a verb-y snake_case name, state trigger conditions explicitly in the description, and verify the ai_tool connection to the AI Agent exists.