Frequently asked Questions¶
Can invoice2data output UBL compliant invoices?¶
While invoice2data is excellent at extracting data from invoices, it currently cannot output fully compliant UBL (Universal Business Language) invoices. Here’s why:
Focus on Data Extraction: invoice2data is primarily designed for extracting key information like invoice number, dates, amounts, and line items. Its strength lies in parsing diverse invoice layouts and formats to capture this data.
UBL Complexity: UBL is a comprehensive XML-based standard for electronic business documents. It has a rigid structure with many required fields and specific data types for representing various business processes, including invoicing. Creating a valid UBL invoice requires adhering to these intricate specifications.
Missing Business Context: invoice2data extracts data without fully understanding the underlying business context. It doesn’t have the capability to infer or generate information like payment terms, tax codes, or detailed product descriptions, which are often essential for a compliant UBL invoice.
Limited Semantic Understanding: While invoice2data uses templates and regex to identify data, it doesn’t truly understand the semantics of an invoice. It can’t automatically map extracted information to the correct UBL elements or handle complex business rules that might influence the UBL representation.
In summary: invoice2data excels at extracting data, but generating a fully compliant UBL invoice requires a deeper understanding of the business context, semantic mapping of the data to UBL elements, and adherence to the specific rules and structures of the UBL standard.
Possible Solutions:
Post-processing: You could use invoice2data to extract the data and then use another library or tool to map this data to a UBL-compliant XML structure.
Template Enhancements: Future versions of invoice2data could potentially incorporate more advanced templates or plugins to handle some aspects of UBL generation.
Integration with UBL Libraries: invoice2data could be integrated with dedicated UBL libraries to facilitate the creation of compliant invoices.
Despite these limitations, invoice2data remains a valuable tool for automating data extraction from invoices. Its output can be a crucial first step in generating UBL invoices or integrating with other systems that require structured invoice data.
What is the easiest way to generate an invoice2data template?¶
The easiest way to generate an invoice2data template is to start with an existing one and modify it. Here’s a step-by-step guide:
Find a similar template:
Look in the
invoice2data/extract/templatesfolder within the installed package.Find a template that roughly matches the structure of your invoice (e.g., similar issuer, layout, fields).
Copy the template:
Create a new file (e.g.,
my_template.yaml) and copy the contents of the similar template into it.
Modify the template:
issuer: Change this to the company name on your invoice.keywords: Identify a unique word or phrase that consistently appears on this type of invoice.Test and refine: Use the
--debugoption with invoice2data to see how well the template works on your invoice.Adjust regex: Refine the regular expressions for each field to accurately capture the data from your invoice. You can use online regex testers to help with this.
Example:
Let’s say you have an invoice from “Acme Corp.” and you find a template for “Example Inc.” that has a similar layout.
Copy the
example_inc.yamltemplate to a new file namedacme_corp.yaml.Change the
issuerfield to “Acme Corp.”Look for a unique keyword on the Acme Corp. invoice (e.g., “Acme Invoice”).
Run
invoice2data --debug my_invoice.pdfto see the extracted text and how the template matches.Adjust the regex for fields like
invoice_number,date,amount, etc., to match the Acme Corp. invoice format.
Tips:
Start with simple fields: Focus on the most important fields first (invoice number, date, total).
Use online regex testers: These tools help you build and test regular expressions. e.g. regex101.com
The
--debugoption is your friend: It shows you exactly how invoice2data is interpreting your template.Don’t be afraid to experiment: Try different regex patterns and keywords until you get a good match.
By starting with an existing template and iteratively refining it, you can quickly create a template that accurately extracts data from your invoices.
Can an LLM help create templates?¶
Yes — and invoice2data has this built in. Point it at a sample document and it drafts a template for you:
invoice2data --new-template sample.pdf --ai --template-out acme.yml
Without --ai it uses deterministic heuristics; with --ai it asks your
configured provider (Gemini, Mistral, DeepSeek, Ollama, …) to propose the
regexes. You still get a YAML/JSON template you own and can refine by hand. You
can also let an LLM extract fields directly when no template matches, with
--ai-fallback. See AI features for setup. (You can of course also paste a sample
into any external chatbot and ask it to draft a template — the built-in commands
just automate that.)
How does invoice2data compare to other tools?¶
invoice2data occupies a specific niche: template-driven, deterministic, self-hosted invoice extraction. A rough comparison:
Tool |
Approach |
Notes |
|---|---|---|
invoice2data |
Regex/YAML templates per layout, optional LLM fallback |
Deterministic and auditable; runs offline; you own the templates; great when you see the same vendors repeatedly. |
invoice2data + AI |
LLM fallback / template generation |
Opt-in, text-only, provider-pluggable (cloud or local Ollama). See AI features. |
Pure-LLM / document-AI services (e.g. cloud “invoice parser” APIs) |
ML models, no templates |
Handle unseen layouts with zero setup, but are non-deterministic, usually paid, and send data to a third party. |
OCR libraries (tesseract, docTR, PaddleOCR) |
Image → text only |
Solve a different problem (text extraction); invoice2data uses them as backends, then structures the text. |
Camelot / pdfplumber |
Table/text extraction primitives |
Lower-level; invoice2data wraps them as plugins/backends and adds the matching + schema layer. |
Choose invoice2data when you want predictable, repeatable results you can version and run on your own infrastructure. Reach for the AI fallback (or a document-AI service) for the long tail of one-off layouts you don’t have a template for.