Scalable AI Agents/chatbots working with JSON/MongoDB

Hi everyone,

I am still relatively new to n8n and would like to implement a customer support chatbot that can also create a Lead / Customer data object as JSON in a MongoDB.

But here I have the problem that I either:

  • Variant A: I receive a correctly formatted JSON, but it also outputs this as an answer in the chat
  • Variant B: I get correct chat responses, but as output to the tool / input for the MongoDB tool I only get a JSON with a field containing all the information always.

Now I want to know, what is best practice here?

Decouple Customer Support and Data Object creation with e.g. a self created (sub-workflow) using this as a tool which is parsing the String into a correct json or was my current approach already the right one and I only need to do it in the right way? :slight_smile:

Hope you get my point. Thank you for help.

Hello @mavoe,
i honestly don’t know if it’s the best option, I can suggest what I would do then evaluate you.

i would implement a Structurer Output Parser (Structured Output Parser node documentation | n8n Docs) to define the scheme and this ensures the Agent a correct output.

i would create a sub-workflow dedicated to data extraction and storage that can be triggered by the main chatbot workflow when specific conditions are met.

Please, tell me if these two indications can help you and if I understand what your doubts are.

1 Like

Yes, you’ve got it completely right. That was at least I already assumed would be the answer. Thank you for sharing your recommendation / approach.

1 Like