Issue with code node tool for AI Agent

Hi,
I’ve using a code node as one of the tools for my AI agent and am struggling to get the input data setup. Each time I run it I get the following:

My code node is currently configured as follows:

The full n8n workflow is shown below.

Any help would be greatly appreciated.

Thanks
Andy

1 Like

Hi @andyfelton The error might be caused by linkedin_posts field being defined as an array type in your Custom Code Tool’s input schema, and this is a known limitation with n8n’s AI Agent tool schema, which has restricted support for array types, what i would do is that i will change the array to a string and then would use that, although this is a really bad practice that letting AI agent have access to code nodes would really creates a big room for multiple errors consider using AI agent only for a specific task and then use the native data control nodes to manipulate the data to fit your code node’s needs then use that.

1 Like

Hi @andyfelton, welcome to the n8n community!
In my view, the AI Agent is calling the tool, but the generated tool input does not match the expected schema. This typically happens when the model is not properly instructed to generate structured input that aligns with the schema, or when the schema is too strict (for example, having multiple required fields), which makes it harder for the model to produce valid tool arguments. My recommendation is to temporarily remove the required array from the schema and test again, ensure that the tool description clearly explains each required field and the expected format, and check the execution logs to see the exact JSON the Agent is sending to the tool. If the tool input is {} or only partially filled, that confirms the model is not generating valid arguments.

Hey Andy, the screenshots aren’t loading for me so I can’t see the error or your code node config — could you paste the actual error message as text and share what code you’ve got in the node?

Your code is using query to access the input but when you define a custom input schema the fields come in as their own variables, so you’d access them as website_content, linkedin_about, etc. directly. Also worth simplifying that schema, drop the array type for linkedin_posts and just make it a string since the agent tends to choke on nested array schemas in tool inputs.

Thanks for all the help - based on the comments by @Anshul_Namdev I moved the Custom code tool out of the AI agent and did it afterwards!

1 Like