Extract structured invoice data from text with OpenAI
Quick overview This workflow lets you paste invoice text and uses OpenAI Chat Completions to extract normalized, schema-based invoice fields as clean JSON, routing parse or extraction failures to a separate error output.
How it works Starts when you run the workflow manually. Loads the invoice body as plain text. Builds a strict JSON extraction prompt (including the model to use) and sends the prompt plus invoice text to the OpenAI Chat Completions API. Parses and cleans the OpenAI response into JSON, strips any code fences, validates that meaningful invoice fields were extracted, and normalizes line items to an array. Routes the result to either an error output with diagnostic details or a success output containing the structured invoice JSON.
Setup Create an OpenAI API key and add it as an HTTP Header Auth credential used by the OpenAI request. Paste your own invoice text into the invoice text field (or replace it dynamically if embedding this workflow elsewhere). Review and adjust the extraction schema, rules, and model name in the extraction prompt before running the workflow.
Requirements n8n 1.0 or later (self-hosted or Cloud) and an OpenAI API key added as an HTTP Header Auth credential. Costs a fraction of a cent per invoice. No Gmail, Google account or database required.
Customization The entire extraction schema is plain text in the Set Extraction Prompt node — add fields, tighten the rules or change the output shape without touching the HTTP node. The model is a separate field in the same node, so switching to a cheaper or newer one needs no node edits.
Additional info Fields that are not present on the document come back as null rather than as guesses, dates are normalised to YYYY-MM-DD and amounts to plain numbers, so the output drops into a sheet or database without post-processing. Parse failures route to their own branch rather than being mistaken for a valid extraction.
Related Templates
Transform Gmail Newsletters into Insightful LinkedIn Posts Using OpenAI
Who Is This For? This workflow is perfect for content creators, marketers, and business professionals who receive regu...
Compare Lists and Identify Common Items & Differences Using Custom Keys
This workflow compares two lists of objects (List A and List B) using a user-specified key (e.g. email, id, domain) and ...
AI Email Classifier & Auto-Delete for Gmail (SPAM/OFFER Cleaner)
This workflow is designed for freelancers, solopreneurs, and business owners who receive a high volume of irrelevant mes...
🔒 Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments