Automated Invoice OCR, LLM Data Extraction, and Google Sheets Logging - n8n Workflow

Use this powerful n8n workflow to automatically process scanned invoices from Google Drive using OCR.space and OpenAI/LLM for structured data extraction into Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Who Needs This n8n Template?

Accounting Teams: Automating tedious data entry from thousands of invoices.
Small Businesses & Freelancers: Needing a cost-effective system to digitize expenses.
n8n Automation Developers: Seeking advanced examples of using conditional logic, OCR, and LLMs within a single n8n workflow.
Users of n8n: Looking for a practical, real-world application utilizing multiple n8n node types.

Overview

Handling large volumes of scanned documents, such as invoices, is a time-consuming administrative burden. This sophisticated n8n workflow solves this by creating a fully automated pipeline. It monitors a Google Drive folder for new files, intelligently routes them based on file type (image or PDF), performs optical character recognition (OCR) where necessary, and then uses a powerful large language model (LLM) via the specialized n8n node for LangChain to extract key structured data (company name, total, invoice number). The final extracted data is cleanly organized and appended to a Google Sheet, providing an exceptional example of what is possible with advanced n8n templates. This entire process is driven by the robust Google Drive n8n trigger, ensuring real-time processing of new documents.

How it Works

This n8n workflow operates in two main modes: a manual batch execution for existing files, and an automated execution driven by the Google Drive n8n trigger.


  1. Trigger & Retrieval: The Check for new invoices n8n trigger starts the process when a new file appears in the designated Google Drive folder. The file is then downloaded using a Google Drive n8n node.

  2. Item Loop: The Loop Over Items node processes each document individually, and the Set file identity n8n node saves crucial metadata (ID, name) for later referencing.

  3. MIME Type Check: The Switch Mime Type node determines if the file is an image (image/) or a PDF (application/pdf).

  4. PDF Path Logic: If it's a PDF, the workflow attempts to use the Extract from File n8n node to pull text directly. The Identify CamScanner condition checks if the resulting text is corrupted or if the PDF metadata indicates poor quality (like those from CamScanner). If the PDF quality is poor, the document is rerouted to the OCR path.

  5. Image/OCR Path Logic: If the file is an image or a poorly scanned PDF, it is sent to the Analyze Image (HTTP Request) n8n node, which connects to the OCR.Space API. This node reads the image and returns recognized text.

  6. AI Extraction: The resulting extracted text (from either successful PDF extraction or OCR) is fed into the Information Extractor n8n node. This node, using an underlying OpenAI Chat Model, is configured to parse the unstructured text and reliably output structured JSON containing the company name, total, date, and invoice number.

  7. Final Logging: Finally, the Append row in sheet n8n node takes the structured data and logs a new row in the specified Google Sheet, including a direct link back to the source file using the stored file ID. This complete n8n workflow ensures data accuracy and streamlined financial record-keeping.

Installation Guide

To install this robust n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and paste it into your n8n instance using the 'New' -> 'Import from JSON' feature.

  2. Google Drive Setup: Configure the Google Drive n8n trigger (Check for new invoices) and Google Drive n8n node (Download file and Fetch 50 docs) credentials. Specify the ID of the Google Drive folder where invoices are uploaded.

  3. OCR Setup: Set up credentials for the HTTP Request n8n node (Analyze Image) to connect to the OCR.Space API, providing your API key as a header authentication.

  4. OpenAI Setup: Ensure the OpenAI Chat Model credential is configured with your OpenAI API key.

  5. Google Sheets Setup: Configure the Google Sheets n8n node (Append row in sheet) credentials. Specify the Document ID and Sheet Name where the extracted data should be stored.

  6. Activate: Save and activate the n8n workflow. The scheduled n8n trigger will now run automatically.

Node Details

This n8n template relies on a combination of built-in and integration-specific nodes:

Google Drive Trigger (Check for new invoices): The primary n8n trigger, polling the 'Scanned invoices' folder for new file additions, initiating the automated data pipeline.
Google Drive Node (Download file): Downloads the file contents based on the file ID provided by the trigger.
Switch Node (Switch Mime Type): This core control flow n8n node determines the document type (image or PDF) to route processing correctly.
Extract From File Node (Extract from File): Attempts to extract readable text directly from PDF documents before resorting to external OCR services.
If Node (Identify CamScanner): A crucial conditional n8n node that checks PDF quality. If poor, it reroutes the file to the more reliable image OCR path.
HTTP Request Node (Analyze Image): Sends image files or poorly extracted PDFs to OCR.Space for character recognition, configured to use Engine 2 for better accuracy.
LangChain Information Extractor Node: This powerful n8n node utilizes the connected OpenAI Chat Model to perform structured data extraction based on defined attributes (company name, total, currency, etc.) from the raw text provided. This is a key feature of this advanced n8n workflow.
Google Sheets Node (Append row in sheet): The final step of the n8n workflow, taking the structured data and writing it to the spreadsheet, completing the automation cycle.

Related n8n Workflows

Free

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

I save my customers huge amounts of time and money by designing and delivering AI automations and AI-powered applications. With over 20 years in technical and management roles, I’ve led teams, launched products, and steered complex projects across industries and technologies. If you’re looking to harness AI for real business impact - not just experimentation - let’s connect.

Featured*