Invoice data extraction with LlamaParse and OpenAI n8n Workflow Template

n8n workflow template · 17 nodes · OpenAI

Invoice data extraction with LlamaParse and OpenAI is a free n8n workflow template that starts from the Gmail Trigger node and works with OpenAI, Gmail and Google Sheets. It has 17 nodes, 3 of them AI nodes (OpenAI Model, Structured Output Parser and Basic LLM Chain). The notes inside the workflow say: “Join the Discord or ask in the Forum!” To run it, you add your own credentials for Gmail OAuth2, Google Sheets OAuth2, HTTP Header Auth and OpenAI API.

At a glance

Trigger
Gmail Trigger (Receiving Invoices)
Nodes
17
Apps
OpenAI, Gmail and Google Sheets
AI nodes
3
Credentials
4 types
Category
Email automation

Apps and integrations

  • OpenAI
  • Gmail
  • Google Sheets

Node types used

  • OpenAI Model
  • Structured Output Parser
  • HTTP Request
  • Gmail Trigger
  • Google Sheets
  • Wait
  • Switch
  • Gmail
  • Edit Fields (Set)
  • Basic LLM Chain
  • If
  • Split Out
  • Aggregate
  • Merge

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Try Me Out!

This workflow does the following

  • Waits for email invoices with PDF attachments.
  • Uses the LlamaParse service to convert the invoice PDF into a markdown file.
  • Uses a LLM to extract invoice data from the Markdown file.
  • Exports the extracted data to a Google Sheet.

Follow along with the blog here

Good to know

  • You'll need to create the label "invoice synced" in gmail before using this workflow.

Need Help?

Join the Discord or ask in the Forum!

1. Watch for Invoice Emails

Read more about Gmail Triggers

The Gmail node can watch for all incoming messages and filter based on a condition. We'll set our Gmail node to wait for

  • a message from particular email address.
  • having an attachment which should be the invoice PDF
  • not having a label "invoice synced", which is what we use to avoid duplicate processing.
  • Change the email filters here!

2. Advanced PDF Processing with LlamaParse

Read more about using HTTP Requests

LlamaIndex's LlamaCloud is a cloud-based service that allows you to upload, parse, and index document. LlamaParse is a tool offered by LlamaCloud to parse for complex PDFs with embedded objects ie PDF Tables and figures.

At time of writing, you can parse 1000 pdfs/day with LlamaCloud's free plan by signing up at

Why not just use the built-in PDF convertor?

A common issue with PDF-to-text convertors are that they ignore important data structures like tables. These structures can be important for data extraction. For example, being able to distinguish between seperate line items in an invoice.

3. Use LLMs to Extract Values from Data

Read more about Basic LLM Chain

Large language models are perfect for data extraction tasks as they can work across a range of document layouts without human intervention. The extracted data can then be sent to a variety of datastores such as spreadsheets, accounting systems and/or CRMs.

Tip: The "Structured Output Parser" ensures the AI output can be inserted to our spreadsheet without additional clean up and/or formatting.

Need more attributes? Change it here!

  • Set Your Google Sheet URL here
  • Set the Name of your Sheet

Don't use GSheets? Swap this for Excel, Airtable or a Database!

4. Add Label to Avoid Duplication

Read more about working with Gmail

To finish off the workflow, we'll add the "invoice synced" label to the original invoice email to flag that the extraction was successful. This can be useful if working with a shared inbox and for quality control purposes later.

Nodes in this workflow

The 17 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. OpenAI Model (OpenAI Model)
  2. Structured Output Parser (Structured Output Parser)
  3. Upload to LlamaParse (HTTP Request)
  4. Receiving Invoices (Gmail Trigger)
  5. Append to Reconciliation Sheet (Google Sheets)
  6. Get Processing Status (HTTP Request)
  7. Wait to stay within service limits (Wait)
  8. Is Job Ready? (Switch)
  9. Add "invoice synced" Label (Gmail)
  10. Get Parsed Invoice Data (HTTP Request)
  11. Map Output (Edit Fields (Set))
  12. Apply Data Extraction Rules (Basic LLM Chain)
  13. Should Process Email? (If)
  14. Split Out Labels (Split Out)
  15. Get Labels Names (Gmail)
  16. Combine Label Names (Aggregate)
  17. Email with Label Names (Merge)

Credentials you need

  • Gmail OAuth2 – used by Add "invoice synced" Label, Get Labels Names and Receiving Invoices
  • Google Sheets OAuth2 – used by Append to Reconciliation Sheet
  • HTTP Header Auth – used by Get Parsed Invoice Data, Get Processing Status and Upload to LlamaParse
  • OpenAI API – used by OpenAI Model

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us