Code-Tool-Problem: "Received tool input did not match expected schema"

My n8n verion: 1.80.4 @ n8n-cloud

I got an issue with my workflow in n8n. I use the AI Agent with several code tools. I receive this message all the time but not allways: “Received tool input did not match expected schema”
This is s big PITA since I have no idea, why I end up with this. I tried everything but I have no glue how to solve this issue. The data my tools receive are abolutelety in line with my input schema. the issue occures when the AI is using the addCanvasElement-Tool. This is the input data of that Tool during an execution that ran into the issue:

[
{
"query": {
"conversationId": "67c56dbf4dfd027bee3dd202",
"userId": "67c563654dfd027bee3dd13d",
"type": "propertySearch"
}
}
]

Duing that same execution also the updateHeadline-Tool was used with this input:

[
{
"query": {
"conversationId": "67c56dbf4dfd027bee3dd202",
"headline": "Wohnungskauf in Berlin Mitte bis 300k"
}
}
]

Please help me, I’m so puzzled :confused:


My Worrkflow:

1 curtida

Today I realized, that the described error only occures, when the mentioned tools are called but it does not occure, as soon as the tool propertySearch is also called in the run as a third tool. This is an example of its tool input:

[
{
"query": 
{
"conversationId": 
"67c599964dfd027bee3dd5e8",
"userId": 
"67c1a8344331b918a8363bc6",
"search_operations": 
"rent",
"custom_location_boundary_circle_target_point_address": 
"Berlin Mitte",
"conditions": 
"very-good",
"price_from": 
0,
"price_to": 
1200,
"bedrooms_from": 
2,
"bedrooms_to": 
3,
"bathrooms_from": 
1,
"bathrooms_to": 
2,
"total_area_from": 
50,
"total_area_to": 
100,
"plot_area_from": 
0,
"plot_area_to": 
0,
"construction_year_from": 
0,
"construction_year_to": 
0
}
}
]

I think it’s a version problem. have u tried update n8n?
try if u can, for me it works

Thank you for your answer :slight_smile:

I updated to 1.81.4 (stable) and tried unsuccessfully and then updated to 1.82.1 (beta) and tried unsuccessfully. Next thing I tried was renaming my “type” property to “elementType” since I thought it might be a naming convention I’m unaware of - didn’t help. This is my updated workflow:

I’m quite sure the issue is the addElementToCanvas-Tool. This is its Input:


[
  {
    "query": {
      "conversationId": "67c9d6cb7f1d538844d25d2a",
      "userId": "66fc28c2327904371d61765e",
      "elementType": "propertySearch"
    }
  }
]

I managed to solve the issue. The key was repeating the enum declarations within the main tool prompt and providing the AI with a clear example of a properly formatted tool input. While this seems somewhat counterintuitive, it proved effective. I discovered this when I noticed that the probability of a successful tool invocation directly correlated with the number of enum values defined in the input schema: with only two enums, the success rate was around 90%, but with all enums included, it dropped to approximately 10%. Introducing triple redundancy, as described, increased the success rate to nearly 100%. Additionally, my initial assumption was incorrect—the root issue was actually within the offerSearch tool. Here’s the revised prompt for that tool (translated to english):

This tool can be used to initiate a property search. To display the search results, the “propertySearch” cluster must first be added to the canvas using the “addCanvasElement” tool. This only needs to be done once. This tool can also provide image links and offer links, which can be displayed within the conversation.

Attention: For conditions, you must exclusively use the following values: used, new, ruin, very-good. No other values are permitted!
Attention: For search_operations, you must exclusively use the following values: sale, sold, sale_hold, rent, rented, rent_hold. No other values are permitted!


[
{
"query": 
{
"conversationId": 
"67cb21989a1fdbb75d3d3511",
"userId": 
"66fc28c2327904371d61765e",
"search_operations": 
"rent",
"custom_location_boundary_circle_target_point_address": 
"Berlin",
"conditions": 
"used"
}
}
]
1 curtida