Automated Medical Fax and PDF Data Extraction using Google Gemini - n8n Workflow

Use this powerful n8n workflow to automatically process uploaded medical faxes or complex PDFs. Leverage Google Gemini 2.0 for data extraction, structure the output using the LLM Chain n8n node, and store the final results in Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Healthcare administrators and clerks who need to digitize patient information from scanned forms (faxes or PDFs).
Automation specialists looking for advanced examples of multi-stage AI processing within an n8n workflow.
Developers needing to implement robust document processing n8n templates that handle complex, unstructured input.
Users aiming to use the Google Gemini API effectively within an n8n node environment.

Overview

Processing scanned documents like medical faxes or complex administrative PDFs is notoriously difficult due to variable formats, handwriting, and low image quality. This advanced n8n workflow solves this by utilizing Google's powerful Gemini 2.0 Flash model in a two-stage process.

First, the document is sent to Gemini with a highly detailed prompt instructing the AI to act as an expert document analyzer, focusing on extracting specific medical and administrative fields (like Patient ID, Prognosis, Allergies, and Date Signed). Second, a subsequent AI call (using the LLM Chain n8n node) enforces a strict JSON schema, ensuring that the extracted text is converted into clean, usable, structured data. Finally, this data is reliably appended to a Google Sheet, making it an essential n8n template for reliable data entry from unstructured sources. This n8n workflow dramatically reduces manual data entry time and errors.

How it Works

This automation initiates when a user uploads a PDF file using the integrated Form Trigger n8n node, making it a flexible and accessible n8n trigger point.


  1. File Upload and Storage: The On form submission n8n trigger receives the fax/PDF file. The file is immediately uploaded and saved to a specified Google Drive folder, followed by a quick download step to retrieve the binary data.

  2. Prompt Configuration: The Define Prompt n8n node injects a detailed, multi-point instruction set, guiding the Gemini model on exactly what medical and administrative fields to extract from the complex document.

  3. Initial AI Extraction: The Call Gemini 2.0 Flash HTTP Request node sends the PDF binary and the detailed prompt to the Gemini API. The AI performs the primary OCR and semantic extraction, returning the data as unstructured text.

  4. Data Cleaning: A Code n8n node cleans the raw text output, removing common markdown artifacts (like * or ) left by the AI, preparing it for strict structuring.

  5. Structured Parsing (LLM Chain): The Basic LLM Chain n8n node, powered by the Google Gemini Chat Model and the Structured Output Parser, takes the cleaned text. It applies a strict JSON schema, forcing the extracted data (Patient Name, DOB, Allergies, etc.) into a predetermined, reliable JSON format.

  6. Finalization: The Append row in sheet n8n node maps the keys from the structured JSON output directly to corresponding columns, appending the clean data as a new row in Google Sheets. This completes the end-to-end n8n workflow.

Installation Guide

To set up this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and import it into your n8n instance as a new workflow.

  2. Credentials Setup:

Configure your Google Drive credentials and link them to the 'Upload file' and 'Google Drive' n8n nodes.
Configure your Google Sheets credentials and link them to the 'Append row in sheet' n8n node.
* Set up your Google Gemini API credentials (referred to as Google Palm API in the workflow) and link them to the 'Call Gemini 2.0 Flash' HTTP Request node and the 'Google Gemini Chat Model' n8n node.

  1. Google Drive Configuration: Update the 'Upload file' n8n node to specify the Folder ID where you want the original fax documents to be stored.

  2. Google Sheets Configuration: Update the 'Append row in sheet' n8n node with your specific Document ID. Ensure the column mapping defined in the node matches the header row names in your target spreadsheet (e.g., 'Patient Name', 'Allergies').

  3. Activation: Once all credentials and configurations are set, activate the n8n workflow and access the form URL from the 'On form submission' n8n trigger to begin testing.

Node Details

This n8n template utilizes several advanced and custom n8n nodes:

On form submission (n8n Trigger):
Function: Acts as the entry point, allowing users to upload the fax/PDF file via a simple web form.
Key Configuration: Configured to accept a single file upload named 'Upload File'.
Define Prompt (Set n8n node):
Function: Prepares the highly specific instruction set for the AI, detailing required extractions from a medical form (patient data, medical codes, instructions, etc.).
Key Configuration: Contains a multi-line string value defining the role of the AI as an "expert document analyzer".
Call Gemini 2.0 Flash (HTTP Request n8n node):
Function: Executes the core extraction by sending the binary PDF data and the defined prompt to the specialized Gemini model endpoint.
Key Configuration: Uses a POST method to the Gemini API, injecting application/pdf inline data along with the prompt.
Code (n8n node):
Function: Cleans the raw text response from the initial AI call, removing markdown artifacts and ensuring a clean extractedText property.
Basic LLM Chain (Langchain n8n node):
Function: Enforces structured output. It uses the cleaned text and coordinates the Google Gemini Chat Model with the Structured Output Parser to strictly match a defined JSON schema.
Key Configuration: The prompt includes a mandatory schema definition for fields like PatientID, DateOfBirth, and Prognosis.
Append row in sheet (Google Sheets n8n node):
Function: The final action, which saves the strictly parsed data into a spreadsheet for permanent storage and accessibility.
* Key Configuration: Uses 'Append' operation and maps multiple extracted fields (e.g., 'Safety Measures', 'Allergies') to specific sheet columns.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by

Workflow automation can help automate your routine activities and help saves $$$, as well as hours of time. As a boutique tech consulting company, Intuz help businesses with custom AI/ML, AI Workflow Automations, and software development. Automate your business workflow for: Sales Marketing Accounting Finance Operations E-Commerce Customer Support Admin & Backoffice Logistics & Supply Chain

Featured*