Quick overview
This workflow watches a Gmail label for invoice emails with PDF attachments, extracts the PDF text, uses OpenAI to pull structured invoice fields, validates totals and VAT logic, and then appends clean invoices to an Invoices tab in Google Sheets while routing failures to an Exceptions tab.
How it works
- Triggers every minute when a new Gmail message arrives under a specified label and has attachments, downloading the attachments for processing.
- Filters the message to keep only PDF attachments.
- Converts the PDF attachment into plain text.
- Sends the extracted text to OpenAI to extract structured invoice data (supplier, invoice number, dates, currency, totals, VAT, and line items) using a strict schema.
- Validates the extracted values by checking required fields, total reconciliation (net + VAT ≈ gross), line-item sums, allowed VAT rates, and flags negative totals.
- Appends validated invoices to the Invoices sheet in Google Sheets and sends any non-reconciling results (with problem details) to an Exceptions sheet.
Setup
- Add Gmail credentials and set the Gmail label ID used to identify supplier invoice emails.
- Add an OpenAI API credential for the extraction model used by the workflow.
- Add Google Sheets credentials and replace the spreadsheet URL, ensuring it contains Invoices and Exceptions tabs with columns that match the extracted fields.