- Topic Title:
AI Agent Fails with "Received tool input did not match expected schema" on Complex Tool Call - Your n8n Version:
1.103.2 (Cloud) - The Error:
Received tool input did not match expected schema - Summary of the Problem:
“The AI Agent fails to call a Code node tool that uses multiple parameters (including some of type JSON). The error occurs even when the prompt provides a direct command with hardcoded data that perfectly matches the tool’s schema. Simple, no-argument tools work, but the agent fails when it needs to construct the arguments for a more complex tool.”
{
“nodes”: [
{
“parameters”: {
“chatModel”: “openai:gpt-4o”,
“prompt”: {
“__rl”: true,
“value”: “Your only task is to call the format_email_html tool. You must use these exact, hardcoded values for the parameters:\n- weatherData: { "conditions": "test weather", "temperature": 75 }\n- todaysEvents: [{ "name": "Test a meeting" }]\n- upcomingEvents: \n- recommendation: "This is a test of the formatting tool."”,
“mode”: “define”
}
},
“name”: “AI Agent”,
“type”: “@n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 2.1,
“position”: [
1120,
360
],
“credentials”: {
“openAiApi”: {
“id”: “YOUR_CREDENTIAL_ID”,
“name”: “Your OpenAI Credential”
}
}
},
{
“parameters”: {
“toolName”: “format_email_html”,
“toolDescription”: “Formats the final email. It requires four parameters: weatherData (object), todaysEvents (array), upcomingEvents (array), and recommendation (string).”,
“specifySchema”: true,
“schemaType”: “fixed”,
“parameters”: {
“parameters”: [
{
“name”: “weatherData”,
“type”: “json”,
“required”: true
},
{
“name”: “todaysEvents”,
“type”: “json”,
“required”: true
},
{
“name”: “upcomingEvents”,
“type”: “json”,
“required”: true
},
{
“name”: “recommendation”,
“type”: “string”,
“required”: true
}
]
},
“code”: “const weatherDataInput = weatherData || {};\nconst todaysEventsInput = todaysEvents || ;\nconst upcomingEventsInput = upcomingEvents || ;\nconst recommendationInput = recommendation || ‘No specific recommendation provided.’;\n\nconst htmlEmailBody = \n<html>\n <body>\n <h1>Test Report</h1>\n <h2>Weather</h2>\n <p>${weatherDataInput.conditions || 'N/A'}</p>\n <h2>Today's Events</h2>\n <p>${todaysEventsInput.length > 0 ? todaysEventsInput[0].name : 'N/A'}</p>\n <h2>Recommendation</h2>\n <p>${recommendationInput}</p>\n </body>\n</html>\n;\n\nreturn { string: htmlEmailBody };”
},
“name”: “format_email_html”,
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
900,
360
]
}
],
“connections”: {
“format_email_html”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
}
}
}