Project Overview: AI-Powered Medical Assistant Workflow

:brain: Project Overview: AI-Powered Medical Assistant Workflow

Hello n8n Community,

I’m developing an AI-powered medical assistant named Médi using n8n. The assistant interacts with users via Telegram, collects structured information, and stores it in Supabase. The workflow is designed to handle three types of structured data:

  • patient
  • praticien
  • rendez_vous

Each of these corresponds to a specific form filled out by the user during the interaction.


:hammer_and_wrench: Workflow Architecture

The workflow follows this structure:

  1. Telegram Interaction: User engages with Médi via Telegram.
  2. AI Agent Processing: Médi processes the conversation and, upon gathering sufficient information, generates a structured JSON object corresponding to one of the three types mentioned above.
  3. IF Node: Checks if the output from the AI Agent is a complete JSON object.
  • If true: Proceeds to the Switch node.
  • If false: Returns to the conversation for further data collection.
  1. Switch Node: Determines the type of form (patient, praticien, or rendez_vous) based on the formulaire field in the JSON.
  2. Supabase Insertion: Inserts the structured data into the appropriate table in Supabase.

:dart: Objective of the IF Node

The IF node is intended to:

  • Pass through the data if the AI Agent’s output is a complete JSON object.
  • Block the data if the output is incomplete or not a JSON object (e.g., a string or null), prompting further interaction with the user.

:x: Issue Encountered

Despite configuring the IF node to check for an object, it doesn’t behave as expected:

  • When the AI Agent outputs a complete JSON object, the IF node still routes the data through the false branch.
  • Attempts to check for the existence of specific fields (e.g., formulaire) result in type errors, such as:

csharp

CopyEdit

Wrong type: true is a string but was expecting an object.
  • Using expressions like {{$json}} in the IF node’s condition doesn’t resolve the issue.

:camera_flash: Example of AI Agent’s Output

Here’s a sample JSON object generated by the AI Agent:

json

CopyEdit

{
  "formulaire": "praticien",
  "telegram_id": "123456789",
  "nom": "Mitoni",
  "prenom": "Bobo",
  "specialite": "Dentiste",
  "email": "[email protected]",
  "telephone": "98038737793",
  "adresse": "7, Paris, France",
  "disponibilites": "Lundi 9h",
  "piece_id_url": "https://...",
  "diplome_url": "https://...",
  "num_ordre_medical": "M7895"
}

Despite this structured output, the IF node doesn’t recognize it as an object.


:test_tube: Troubleshooting Steps Taken

  • Configured the IF node to check if the data type is an object.
  • Attempted to verify the existence of specific fields within the JSON.
  • Used expressions like {{$json}} to reference the entire JSON object.
  • Reviewed n8n documentation and community discussions related to the IF node’s behavior.

:bulb: Desired Outcome

I seek guidance on:

  • Correctly configuring the IF node to detect whether the input is a complete JSON object.
  • Ensuring that the IF node routes complete JSON objects through the true branch and incomplete or non-object data through the false branch.
  • Alternative approaches or best practices within n8n to achieve this conditional logic.

:pray: Request for Assistance

Any insights, suggestions, or examples from the community would be immensely helpful. If needed, I can provide the current workflow’s JSON export for a more in-depth review.

Thank you in advance for your support!

This is a cool project, I am trying to use the AI agent also to collect 4 pieces of data but the AI agent will not ask the questions and just moves on to the next process in the workflow. Would you mind sharing more on how you configured yours to collect the data?

1 Like

you have to setup a prompt in the prompt system field, if you need more help find me on whatsapp

Hi, on my end, there are no issues. Are you sure the AI’s output structure is never incorrectly formatted?

1 Like

Can you share your IF and Switch nodes in a code block please.

This clearly shows that your data was isValid = false, which means the if logic will result in a false output. what the logic of that code node block function?
You told that the example output from AI like this:

{
  "formulaire": "praticien",
  "telegram_id": "123456789",
  "nom": "Mitoni",
  "prenom": "Bobo",
  "specialite": "Dentiste",
  "email": "[email protected]",
  "telephone": "98038737793",
  "adresse": "7, Paris, France",
  "disponibilites": "Lundi 9h",
  "piece_id_url": "https://...",
  "diplome_url": "https://...",
  "num_ordre_medical": "M7895"
}