Ai Agent parsing issue with mongodb tool

Describe the problem/error/question

Hi Folks, I am learning n8n flows. I stuck to store the object in the mongodb through ai agent tool.

What is the error message (if any)?

There is no error message but the output is not correct. Agent is sending Fields as json string.

I have tried multiple case to parse the output but nothing works fine.

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey!

You can use a structured output node to provide JSON schema to validate the output from the AI. Then, you need to explain in the system prompt very specifically the structure which you require and test around until it starts to return it.

In the MongoDB node, you can also try disabling the :sparkles: button and use this instead (replace the values):

{{$fromAI('fieldName', 'description', 'type')}}

This will allow you to also test another way of getting the string to JSON:

{{JSON.parse($fromAI('fieldName', 'description', 'type'))}}

Alternatively, feel free to to PIN the data on your webhook node and copy-paste your workflow in a code node so I can test it :slight_smile:

Hey,

If i use the structured output node then before storing it in to DB then i can’t use the ai tool feature. I also try that as well in that case i used mutiple ai aget node that i want to avoid.

Now, as you mentioned to change the “Field” option in the tool try disabling the :sparkles: button. I also tried that as well. On customizing the Fields , the input values given by ai agent also changing like :

Fields value Input by ai agent to tool error
{{JSON.parse($fromAI(‘Fields’, ``, ‘string’))}} Field: JSON_STRING error by tool : fields.split is not a function
{{$fromAI(‘Fields’, ``, ‘json’)}} Field: JSON object error by tool : fields.split is not a function
comma separated keys — error by agent : Tool call validation failed: tool call validation failed: parameters for tool Insert_in_DB did not match schema: errors: [additionalProperties ‘full_name’, ‘contact’, ‘requestedStart’, ‘requestedEnd’, ‘description’ not allowed]

This is the main flow with all the details without please add your credentials while testing

I tested it with the structured output parser and it works very well. Sorry I couldn’t understand why you wanted to skip it - you mentioned you can’t use the tool? Can you clarify what happens?

By using output parser i also tried i is working fine. But i want to use the tool itself.
In case of output parser some more nodes that are required extra in the flow , that i want to avoid.

But thanks for your help!

Finally I got the solution.
The tool description should be



Insert an object in database. Send with the different json just with the values of the
{{ $fromAI('full_name', `Name of the customer`, 'string') }},
{{ $fromAI('contact', `Customer's contact`, 'string') }},
{{ $fromAI('description', `Appointment description`, 'string') }},
{{ $fromAI('start_appointment_time', `Start time of the appointment (ISO datetime)`, 'string') }},
{{ $fromAI('end_appointment_time', `End time of the appointment (ISO datetime)`, 'string') }}

and the Fields should be like exact key values: full_name,contact,description,start_appointment_time,end_appointment_time

2 Likes

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