How it works
When you build a GOBL document, it’s processed through a validation rules engine that checks each struct in a document against a set of assertions. Every assertion has three parts:- A unique validation code that identifies the rule.
- One or more tests that evaluate to true or false.
- A human-readable message that surfaces when a test fails.
Three layers of rules
Rules are organized into three layers, applied in order:Core rules
Core rules apply to every GOBL document, regardless of country or configuration. They enforce the basic structure each document type requires. An invoice, for example, always needs atype, issue_date, currency, and supplier.
Core rules live alongside the structs they validate in the GOBL source, and are listed under the Validation Rules section on each schema’s reference page.
Regime rules
Tax regimes add country-specific requirements on top of core rules. When a document specifies a regime — Portugal, Mexico, France, and so on — that regime’s rules are also evaluated. A Portuguese rule might require invoices to include a specific extension, or that the series code follows a particular format. These rules only kick in when the document’s regime is set to Portugal.Addon rules
Addons layer further validation on top of regime rules. When a document has an addon enabled such as Mexico CFDI or Peppol’s EU EN 16931, its rules are checked as well. Addon rules typically enforce the requirements of a specific standard or reporting system. The Mexico CFDI addon, for instance, requires certain tax extensions and customer fields depending on whether the invoice is global or domestic.Validation codes
Every assertion gets a unique code built from the package, struct, and a sequence number:GOBL-BILL-INVOICE-01— core rule onbill.InvoiceGOBL-PT-SAFT-V1-BILL-INVOICE-04— Portugal SAF-T addon rule onbill.InvoiceGOBL-MX-CFDI-V4-BILL-INVOICE-01— Mexico CFDI addon rule onbill.Invoice
Error collection
Validation never stops at the first failure. The engine runs every applicable rule across all three layers — and collects every fault it finds. The full list of errors is returned together in a single response, so you can see and fix all problems at once rather than going through them one at a time.Calculated fields
Some fields are marked as calculated in the validation tables. These fields are automatically populated by GOBL during the build step, before validation runs. For example, an invoice’stotals are computed from the line items, taxes, and discounts — you never need to provide them yourself.
A validation rule that requires a calculated field to be present does not mean you must supply it as input. GOBL will fill it in during calculation, and validation will then confirm the result is correct.
In the validation tables, calculated fields are labeled with calculated beneath the field name.