Logo Codebaker
IT

How to Integrate Artificial Intelligence and LLMs in Your Company to Extract Data from Documents

With a five-stage pipeline: intake → OCR and layout → schema-guided LLM extraction → validation with human review on uncertain cases → automatic writing into your ERP via API. Not by uploading PDFs into a chatbot.

How to integrate AI and LLMs to extract data from documents

You integrate them by building an Intelligent Document Processing pipeline in five stages: document intake and classification; OCR with layout analysis; field extraction with an LLM guided by a schema, returning structured data rather than free text; validation with confidence scores, arithmetic checks and human review on uncertain cases only; automatic writing of the data into the management system or ERP via API. It is the fifth stage that produces the saving: data extracted but not written into your systems has merely moved the manual work, not removed it.

The counter-intuitive part is that the language model is the least critical piece of the whole. Projects do not fail because the LLM reads badly: they fail because nobody defined what happens when confidence is low, because the extracted data ends up in a file instead of the management system, or because the question of document confidentiality was raised once the project was finished. Codebaker, a software house based in Bologna and founded in 2019, designs these pipelines starting from the constraints — volumes, confidentiality, systems to feed — and builds the proprietary product Data Alchemy, dedicated to exactly this: Intelligent Document Processing with LLMs.

structured-field-extraction-from-documents-with-llm

yellow dot
structured output

Fields, not answers

This is where an experiment and a production system part ways. Asking a model «what is the total on this invoice?» produces a natural-language answer that somebody then has to interpret and that changes shape every time. Asking the model instead to return a structured object with fields defined in advance — document number, date, supplier VAT number, line items with quantity and price, net amount, VAT, total — produces data another piece of software can consume without ambiguity. The schema also acts as a safety net: if a mandatory field is missing or has the wrong type, the anomaly surfaces immediately, before it reaches the management system. It is the same discipline we apply when designing APIs, applied to the output of a language model: you agree the data contract first, and the model honours it.

gdpr-and-confidentiality-in-document-processing-projects

yellow dot
confidentiality

Where your documents travel

The documents a company would most like to process automatically are often the most sensitive: contracts, invoices carrying customer and supplier data, certificates, CVs, documents covered by trade secrecy. The question «where do these files end up» must therefore be asked at the beginning, because it shapes the architecture and cannot be fixed afterwards. There are three routes: models running on EU cloud infrastructure under contracts that exclude the use of your data for training; models running locally on company hardware, so documents never leave the perimeter; or a mixed architecture that sends outside only what is not sensitive. We design GDPR by design: minimisation of what is sent, deletion of temporary files, logs of who saw what, and a local execution option when sensitivity demands it.

The five-stage pipeline

Each stage has a precise job and a control point: that is what makes the system reliable enough to let it write into your management system.

yellow dot

1. Intake and classification

Documents arrive from a dedicated mailbox, a scanner, an upload area or an existing flow, and are classified by type: invoice, delivery note, order, certificate. Nobody has to change how they receive them.

yellow dot

2. OCR and layout analysis

The document becomes text with the coordinates of every element, so tables, columns and rows survive as structure rather than scattered words. This stage determines the quality of everything downstream.

yellow dot

3. Schema-guided LLM extraction

The model is asked for structured output with fields defined in advance, not free text. That way «Net total» and «Total net amount» land in the same field, with no need for a template per supplier.

yellow dot

4. Validation and human review

Per-field confidence scores, arithmetic checks (line items sum to the total, VAT adds up) and reconciliation against master data. Only documents below threshold enter a review queue: the rest pass through.

yellow dot

5. Writing into the ERP via API

Validated data enters the management system, the ERP or the document system through APIs, with the original document archived and linked to the record. This is the stage that turns extraction into hours saved.

yellow dot

Across all stages: measurement and traceability

Every processed document leaves a trace: what was extracted, with what confidence, who corrected what. That is what makes it possible to track accuracy over time and to answer an audit or a dispute.

Stage 5 rests on the same skills as integrating your management system with other software via APIs: which is why an AI document project succeeds or fails more on the integration than on the model.

OCR, templates, LLMs or RAG: which technology for which problem

They are often conflated, but they solve different problems. Picking the wrong one is the fastest way to spend money well on a problem you did not have.

TechnologyWhat it doesWhen it is the right choiceWhere it breaks
OCRConverts images and scans into textAlways, as the base stage underneath everything elseOn its own it grasps no meaning: words, not fields
Template extractionMaps fixed page positions to fieldsFew documents, always identical, layout stable over timeAs soon as a supplier changes layout: one template each
LLM with structured outputReads the document and returns the fields the schema asks forMany suppliers, variable layouts, synonyms and several languagesWithout validation and confidence scores, errors pass silently
RAGAnswers questions by searching your documentsContracts, specifications, manuals, regulations: consultationNot designed to extract fields to feed a management system
Generic chatbotConverses about a manually uploaded documentOccasional individual use, explorationNo automation, no traceability, no writing into systems

In a production pipeline OCR and LLMs work together, templates are reserved for the few genuinely stable documents, and RAG is added when the need is consultation rather than extraction. The full picture on using AI in business is on the artificial intelligence for companies page and in our AI consulting.

Which documents to automate first

The best candidates share three traits: high volume, a recurring but not identical structure, and a value that somebody currently retypes into a system by hand.

DocumentFields typically extractedWhere the data landsDifficulty
Supplier invoiceSupplier, VAT number, number, date, line items, net, VAT, total, due dateAccounts payableMedium: many suppliers, many layouts
Inbound delivery notesSender, number, date, items, quantities, order referenceWarehouse goods-inMedium
Customer orders by email or PDFCustomer, item codes, quantities, prices, requested dateOrders in the management systemMedium: requires matching against the catalogue
Quality certificatesBatch, measured parameters, outcome, issuing body, validityQuality system and batch traceabilityLow if the format recurs
Expense receiptsDate, merchant, amount, VAT, expense categoryAdministration and reimbursementsHigh on image quality, low on the fields
Contracts and specificationsParties, term, deadlines, relevant clausesDeadline tracking and consultation (RAG is needed here too)High: long, non-tabular text
CVsPersonal data, experience, skills, qualificationsRecruitment systemTechnically low, high on the GDPR side

Why Codebaker on this topic

Frequently asked questions on AI document data extraction

How can I integrate artificial intelligence and LLMs into my company's processes to extract data from documents?

You integrate them by building an Intelligent Document Processing pipeline in five stages, not by uploading PDFs into a chatbot. Stage one, intake: documents arrive from a mailbox, a scanner or an upload area and are classified by type. Stage two, OCR and layout analysis: the document becomes text with the coordinates of every element, so tables and columns remain readable. Stage three, schema-guided extraction with an LLM: the model is asked to return structured output with fields defined in advance (document number, date, VAT number, line items, net amount), not free text. Stage four, validation: every field gets a confidence score, arithmetic checks and reconciliation against master data are applied, and only uncertain documents go into a human review queue. Stage five, writing: the validated data enters the management system or ERP via API, with the original document archived and linked. It is the fifth stage that produces the saving: data extracted but not written into your systems has merely moved the manual work elsewhere.

What is the difference between OCR, templates and LLMs for document data extraction?

OCR converts an image into text but does not know what it means: on its own it does not give you the invoice total, it gives you every word on the page. Template-based systems map fixed positions to fields: they work very well on documents that are always identical and break as soon as a supplier changes layout, which in companies with hundreds of suppliers is the norm. LLMs read the document the way a person would: they understand that «Net total» and «Total net amount» are the same thing and find the value even when it has moved, without needing a template per supplier. RAG is something else again: it is not for extracting fields from a document but for answering questions over a document collection, and it is the right choice for contracts, specifications and manuals. In practice a solid pipeline uses OCR and LLMs together, and reserves templates for the few genuinely stable documents.

How accurate is the extraction, and how is it controlled?

Accuracy must be measured, not promised: the correct number depends on the document type, the quality of the scans and how many different suppliers there are, and anyone quoting a percentage before seeing your documents is guessing. The serious method is to build a reference set of documents already verified by hand, measure the extraction against it field by field, and repeat the measurement after every change. In production, accuracy is governed by four mechanisms: per-field confidence scores, arithmetic checks (line items must sum to the total, VAT must add up), reconciliation against existing master data and a human review queue for documents below threshold only. The goal is not an infallible model, it is that no error reaches your systems without being intercepted.

Do my documents end up in an external service? Is this GDPR-compliant?

It depends on how the solution is designed, and it is a decision to take at the start rather than at the end. There are three options: models running on EU cloud infrastructure under contracts that exclude the use of your data for training; models running locally, on company hardware, so documents never leave the corporate perimeter; or a mixed architecture that sends only non-sensitive documents to the external model. We design solutions GDPR by design: minimisation of what is sent, deletion of temporary documents, traceability of who saw what, and the option of running everything locally when sensitivity demands it. If you process special category data or documents covered by trade secrecy, local execution is the route to evaluate first.

Which business documents are best suited to AI processing?

The best candidates share three traits: high volume, a recurring but not identical structure, and a value that somebody currently retypes into a system by hand. In practice: supplier invoices from many different vendors, inbound delivery notes, customer orders received by email or PDF, order confirmations, quality certificates and datasheets, customs documents, expense receipts and CVs. In all of these the work is transcription rather than judgement, and human error from fatigue is more likely than model error. What does not make sense is starting from rare documents, or from those where the decision matters more than the data: there, AI can help you read, not decide.

Do I need an LLM running locally, or is a cloud service fine?

It depends on confidentiality, volume and cost. Cloud is preferable when the documents are not particularly sensitive and volumes vary: there is no hardware to buy and you pay per use. Local execution is preferable when documents cannot leave the company for confidentiality or contractual reasons, when volumes are high and steady (at which point the hardware amortises), or when you need the guarantee that no data is used to train third-party models. We have written a dedicated guide to the hardware needed to run LLMs locally, with realistic configurations for a company.

How much does an AI document data extraction project cost?

A pilot project on a single document type, with simple integration into the management system, typically falls in the €5,000-15,000 band; a solution covering several document types with validation, a review interface and full integration falls in the €15,000-50,000 band; document platforms spanning several flows and sites go beyond €50,000. On top of this sits the cost of running the models, pay-per-use in the cloud or as hardware if you choose local execution. The calculation that really matters, though, is a different one: how many hours a week your company currently spends retyping data from documents, and what eliminating most of that is worth.

Where should I start?

From a single high-volume document type, having first measured what it costs you today. The path we recommend is: pick the most frequent document (often the supplier invoice or the inbound delivery note), gather about a hundred real examples including the ugly ones, define the fields to extract and the validation rules, measure accuracy against that set, and only then connect automatic writing into the management system. A pilot like this is bounded, measurable and requires no change in how the company works: operators simply stop typing and start validating exceptions.

What is Data Alchemy?

Data Alchemy is Codebaker's proprietary product for Intelligent Document Processing: it extracts structured data from business documents by combining OCR and LLMs and returns output ready to be written into management systems. It grew out of our experience on client projects and is used as a starting point when the required solution falls within its scope, cutting time and cost compared with building from scratch; when the document flow is unusual, we develop a bespoke pipeline instead. In both cases our principles hold: data handled GDPR by design and integration with the systems the company already uses.

Let's start with the document that costs you the most hours

Tell us which document arrives most often and who retypes it by hand today. With about a hundred real examples we can measure accuracy on your actual case and tell you what is genuinely automatable, before you spend a euro. The preliminary analysis and the quote are free.