Customs Automation with AI: How We Digitized the DUA
The problem: 47 minutes per declaration
Preparing a DUA (Documento Unico Administrativo — the EU customs declaration form) by hand takes an average of 47 minutes per declaration. A mid-sized freight forwarder in Spain processes 30 to 80 declarations daily. The math is straightforward: 23 to 63 person-hours per day spent on document preparation alone.
The classic process is manual, repetitive, and error-prone: a customs agent receives documentation from the exporter or importer (commercial invoice, packing list, certificates of origin, transport documents), manually extracts relevant data, looks up the correct tariff code in the TARIC, calculates duties and taxes, and fills in the 54 fields of the DUA. An error in the tariff code can result in goods being held, a fine, or both.
Automating this process was not an academic exercise. It was an operational necessity for our logistics clients.
The solution architecture
The system has four chained phases. Each solves a specific problem.
Phase 1: document extraction (OCR + NLP)
Documents arrive in every imaginable format: scanned PDFs of varying quality, phone photos of documents, Excel files, and yes, faxes (still alive in international trade in 2025). The first step is extracting structured data from unstructured documents.
We use a combination of OCR (Tesseract for good-quality documents, a pipeline with image preprocessing for low quality) and NLP models specific to commercial documentation. The extraction model is trained on 12,000 real international trade documents and recognizes key fields: exporter/importer name and tax ID, goods description, weights, values, incoterms, country of origin, and transport data.
Extraction accuracy varies by document quality: 94% for native PDFs, 87% for good-quality scans, 71% for phone photos. Fields with low confidence are flagged for human review. We do not aim to automate 100%. We aim to have the customs agent review and correct instead of type from scratch.
Phase 2: tariff classification
The TARIC has more than 15,000 tariff headings. Choosing the correct one requires technical product knowledge, international trade experience, and sometimes interpretation of complex legal notes. It is the most critical step in the process and the one that generates the most errors.
Our tariff classifier uses a model trained on 280,000 pairs of (product description, tariff heading) extracted from real historical declarations. The model receives the product description (extracted in Phase 1 or provided by the user) and returns the 3 most likely headings with confidence levels.
For confidence above 92%, the classification is accepted automatically. Between 75% and 92%, it is presented to the agent with the recommendation. Below 75%, the system flags it for human intervention. In production, 64% of classifications are accepted automatically, 28% are accepted with the system’s recommendation, and 8% require manual classification.
A critical detail: the model retrains monthly with agent corrections. Every human correction is training data. This means the system improves continuously. The automatic acceptance rate has risen from 48% to 64% over 14 months.
Phase 3: compliance validation
Before generating the DUA, the system automatically validates:
- Sanctions: the entity (exporter, importer, consignee) is checked against EU, OFAC, and UN sanctions lists. If there is a positive or partial match, the declaration is blocked and immediately escalated.
- Licenses: certain products require import or export licenses (dual-use goods, phytosanitary products, pharmaceuticals). The system identifies these products based on the tariff classification and verifies that the required documentation is present.
- Values: the declared value is compared against historical ranges for the same tariff heading and country of origin. Deviations exceeding 30% are flagged for review (they may indicate undervaluation or errors).
- Tariff preferences: if an applicable trade agreement exists (EU-Canada, EU-Japan, etc.), the system verifies that the origin documentation is correct and that the product meets rules of origin.
This phase is purely rule-based, not AI. Compliance rules are deterministic and change with every new regulation. We maintain a rule repository updated weekly with TARIC changes, sanctions lists, and trade agreements.
Phase 4: DUA generation
With data extracted, classified, and validated, the system generates the DUA in EDI format for transmission to the Spanish customs authority (AEAT). All 54 document fields are populated automatically. The customs agent reviews the complete draft, makes corrections if needed, and authorizes transmission.
The net result: average preparation time drops from 47 to 13 minutes per declaration. A 73% reduction. For a forwarder processing 50 declarations daily, this frees up 28 person-hours per day.
What we learned
Edge cases are infinite. International trade has a casuistry that no model covers 100%. Goods in transit, reimportations, temporary admissions, customs warehouses, inward/outward processing. Each regime has its own rules. Designing the system to handle common cases automatically and escalate edge cases to humans was the most important architectural decision.
Trust is earned through transparency. Customs agents are professionals with years of experience. They will not blindly trust an AI. Every system recommendation includes the explanation: why it suggests that tariff heading, which compliance rule applies, what historical value range it used as reference. Explainability is not a nice-to-have. It is what makes professionals adopt the tool.
Historical data is gold. Every processed declaration, every human correction, every new regulation feeds the system. After 14 months in production, the model is significantly better than on launch day. Clients who have been on the platform longest get the best results because their historical data is richer.
Customs automation is an example of how applied artificial intelligence solves concrete operational problems. It is not about replacing the customs agent. It is about eliminating mechanical work so the professional can focus on the decisions that truly require their judgment. For a comprehensive view of logistics automation with AI, see our logistics automation guide.
About the author
abemon engineering
Engineering team
Multidisciplinary engineering, data and AI team headquartered in the Canary Islands. We build, deploy and operate custom software solutions for companies at any scale.
