Advanced AI Document Parsing, Classification, and Invoice Extraction with LlamaParse - n8n Workflow

Use this comprehensive n8n workflow to automatically monitor Gmail attachments, parse documents using LlamaParse, classify content via AI, extract structured JSON invoice data, and save everything to Google Sheets and Drive.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Who Should Use This n8n Template?

Accounting & Finance Teams: Automating the capture of structured data from complex invoices, statements, and receipts.
Operations Specialists: Seeking highly efficient, AI-powered solutions to manage high volumes of incoming documents.
n8n Developers: Looking for advanced examples of integrating external asynchronous AI services (like LlamaParse) using webhooks and managing conditional logic.
Business Analysts: Needing reliable and structured data for reporting and integration into BI tools via Google Sheets.

Overview

This powerful n8n workflow provides a comprehensive, two-stage system for document intelligence, starting with the Gmail Trigger n8n node and ending with structured data storage. It solves the critical challenge of converting complex file formats (PDFs, images) into usable, structured JSON data. By leveraging the deep parsing abilities of LlamaParse, the workflow achieves superior text extraction fidelity. The subsequent AI processing, using a LangChain LLM n8n node, automatically classifies the document and extracts precise financial details according to a strict JSON schema. This allows users to deploy robust n8n templates that streamline financial processing, ensuring accurate, automated record-keeping in Google Sheets and secure archiving in Google Drive. This entire n8n workflow demonstrates how to build resilient, enterprise-grade automations using core n8n features combined with specialized AI services.

How it Works

This n8n workflow operates in two main phases: Ingestion/Submission and Webhook Callback Processing.

Phase 1: Ingestion and Submission (Gmail Trigger)


  1. Monitor Emails: The Gmail Trigger n8n node continuously monitors the inbox for new emails, specifically looking for messages containing attachments, which acts as the starting n8n trigger.

  2. File Validation: The workflow checks the attached file's extension against LlamaParse's currently supported formats using an initial HTTP Request and an If Supported File Extensions n8n node.

  3. Save & Submit: If the file is supported, the document is saved to Google Drive (Save Document to Google Drive), and the job is submitted to LlamaParse via an HTTP Request n8n node. A temporary record containing the LlamaParse jobId and the Google Drive URL is logged in Google Sheets (Save LlamaParse ID and Summary to Google Sheets).

  4. Email Summarization: The email body itself is summarized using a LangChain Summarize Email n8n node and an OpenAI model.

Phase 2: Webhook Processing (LlamaParse Callback)


  1. Receive Callback: A dedicated Webhook n8n trigger listens for LlamaParse to complete the document parsing. The response contains the high-quality parsed document content in Markdown format.

  2. Archiving: The raw parsed Markdown is saved to Google Drive.

  3. Document Classification: The parsed content is passed to the Classify Parsed Document LangChain n8n node, which classifies it as either an 'invoice' or 'not invoice'.

  4. Conditional Routing:

If 'not invoice': The document goes to the Summarize Document n8n node for executive summary creation, which is then sent via Telegram.
If 'invoice': The workflow routes the content to the Extract Invoice Details as JSON LangChain n8n node. This highly specific n8n node uses a robust prompt instructing the LLM to output precise financial data (including taxes, fees, and subtotals) strictly conforming to a predefined JSON schema.

  1. Final Update: The extracted structured data is used to locate the initial record in Google Sheets using the LlamaParse jobId and updates it with all the final financial and summary information (Update Google Sheet by LlamaParse ID). A final notification is sent via a Telegram n8n node.

This robust architecture ensures efficient, reliable AI processing within your n8n workflow.

Installation Guide

To deploy this advanced n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and import it directly into your n8n instance.

  2. Configure Credentials: Set up the following credentials using the appropriate n8n node:

Gmail OAuth2: For the Gmail Trigger and Get Message n8n node.
OpenAI API: For the LangChain LLM nodes (Classification and Extraction).
Google Sheets OAuth2: For reading and writing data.
Google Drive OAuth2: For storing original and parsed documents.
HTTP Header Auth (LlamaParse): For authenticating with the LlamaParse API.
Telegram API: For sending notifications (requires TELEGRAMCHATID environment variable set).

  1. Setup Webhook URL: The LlamaParse submission HTTP Request n8n node uses a dynamic webhook URL (=https://[YOUR-N8N-URL]/webhook/parse). Ensure you replace [YOUR-N8N-URL] with the base URL of your live n8n instance.

  2. Customize Sheets and Prompts: Configure the Google Sheets n8n nodes to point to your specific spreadsheet (Document ID and Sheet Name). Review the prompt in the Extract Invoice Details as JSON LangChain n8n node and update the schema to perfectly match your target data requirements.

  3. Activate: Save the n8n workflow and set the Gmail Trigger n8n node to active.

Node Details

This n8n workflow utilizes several key nodes for its complex operations:

Gmail Trigger: The primary starting n8n trigger. Key Configuration: Filters are set for messages containing attachments (has:attachment).
Webhook (n8n node): Acts as the listener for the LlamaParse callback when the document parsing is complete.
HTTP Request (LlamaParse Submission): Used to send the attached binary file to the LlamaParse API. Key Configuration: Method is POST, Content Type is multipart-form-data, and includes webhook_url parameter for the callback.
Google Sheets (Append/Update): Used both early on to log the job ID, and later to update the row with extracted data. Key Configuration: Operation: updateOrAppend, matching column is jobid.
LangChain Text Classifier (Classify Parsed Document): An essential AI n8n node that routes the n8n workflow. Key Configuration: Defines categories like invoice and not invoice to determine subsequent processing.
LangChain LLM Chain (Extract Invoice Details as JSON): The core AI extraction n8n node. Key Configuration: Uses a highly prescriptive system prompt to ensure the output is a valid JSON object conforming to a detailed financial schema (including tracking container deposits, multiple tax types, and transaction details).
Set (Invoice Details & Prepare Data): Standard n8n node used for reorganizing and mapping data fields between steps before final saving or notification.
Telegram (n8n node): Sends status updates and the final summary/extracted financial data to the configured chat ID for real-time monitoring.

Related n8n Workflows

Free

Nodes: 17 Nodes
Updated: December 26 2025
View all
Created by
Joseph LePage
Joseph LePage

As an AI Automation consultant based in Canada, I partner with forward-thinking organizations to implement AI solutions that streamline operations and drive growth.

Featured*