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 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:
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 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.
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