A while ago I started looking at Italian electronic invoices (FatturaPA) and needed test files. It turned out to be harder than I expected.

Real invoices are out. They're full of names, tax codes and IBANs, so you can't just drop them in a repo or a CI job. Writing the XML by hand works for two or three files, but then you're only testing the cases you already had in mind.

So I wrote a generator, and I'm sharing a free sample of what it produces: 36 valid invoices and 13 broken ones. Here's what's in it.

Passing the XSD doesn't mean much

FatturaPA has an official schema, and every file has to pass it. But the schema only checks structure, so it accepts an invoice where:

  • a line says 3 × €10.00 = €32.00
  • the VAT summary says 22% of €100 is €20
  • a 0% line has no Natura code (the field that explains why there's no VAT)
  • an exempt invoice over €77.47 is missing the €2 stamp duty

None of these is a schema error: they're arithmetic and tax rules, and they need their own checks.

The cases that break things

It's easy to write code around the "normal" invoice: one supplier, one customer, 22% VAT, total = amount to pay. Italian invoices have quite a few ways of not being normal. The sample covers nine:

  • ordinary B2B, but with several VAT rates and discounts on the same invoice
  • professionals with withholding tax: there's a 20% withholding (RT01) and a 4% pension contribution (TC22), so the amount the customer pays is not the document total
  • flat-rate regime (forfettario, RF19): no VAT at all, Natura N2.2, stamp duty
  • deferred invoices (TD24) that reference delivery notes
  • reverse charge in construction (N6.3), where the customer pays the VAT
  • credit notes (TD04) linked to the original invoice
  • private customers: tax code only, recipient code 0000000
  • services to EU customers (N2.1), recipient code XXXXXXX
  • split payment, where a public body pays the VAT straight to the State

If your importer treats "total" and "amount due" as the same thing, the withholding and split payment cases will show it.

The broken ones

Each of the 13 defective files is a valid invoice with exactly one thing wrong. One per file on purpose: when a test fails, you know which rule you missed.

Defect What's wrong
missing_natura 0% line with no Natura code
natura_with_vat_rate 22% line that also has a Natura code
wrong_vat_amount VAT in the summary doesn't match taxable × rate
wrong_line_total line total ≠ unit price × quantity
wrong_document_total document total ≠ sum of the summaries
missing_vat_summary a rate used in the lines has no summary
missing_withholding lines subject to withholding, but no withholding block
missing_stamp_duty exempt amount over €77.47, no stamp duty
invalid_customer_vat_number wrong check digit in the VAT number
invalid_tax_code wrong check character in the tax code
invalid_iban two digits swapped
due_date_before_invoice payment due before the invoice date
invalid_document_type document type the schema doesn't allow

The dataset also gives you the error code each one should trigger, if you want to be strict about it.

Using it

I put it on Hugging Face so it loads in one line. Every row has the full XML plus the values it should be read as:

from datasets import load_dataset ds = load_dataset("fm-datalab/fatturapa-sample-invoices") for row in ds["valid"]: inv = my_parser(row["xml"]) assert inv.total == row["total"], row["file"] assert inv.amount_due == row["amount_due"], row["file"] for row in ds["defective"]: assert my_validator(row["xml"]), f'{row["file"]}: {row["defect_description"]}' 

(my_parser and my_validator being whatever you're testing.)

If you're not into Python, the same files are on GitHub as plain XML with a CSV index. And if you're doing OCR or LLM extraction, the known values work as ground truth: extract the fields and compare.

How it's made

Everything is synthetic, but the check digits are computed properly (tax codes, VAT numbers, IBANs), so a validator can't tell them from real ones just by the format. Every valid invoice passes the official XSD and then a second set of checks I wrote separately from the generator, so the generator isn't the only thing checking itself. The defects get added at the end, one per file.

Don't send these to SdI: they're for testing only.

Links

If there's a case you run into that isn't covered, tell me in the comments. I'd like to add the ones people actually run into.