• Case Study

Extracting Financial Data from Company Filings with AI: A Practical Pipeline

How we designed an API that fetches UK company accounts, reads the PDF with an AI model and returns clean structured data, while keeping cost and errors under control.

The problem

Company accounts are public, but they are published as PDFs in many layouts: native text, scanned images, short filings, long annual reports. Anyone who wants revenue, employee numbers or director details across thousands of companies cannot read them by hand. We built an extraction service that takes a UK company registration number, retrieves the latest accounts filing from Companies House and returns structured, validated JSON. It sits behind a sales intelligence platform that needs up-to-date company facts.

The pipeline in four steps

  • Look up the company's filing history and find the latest accounts.
  • Fetch the document metadata and download the PDF.
  • Pre-process the document and send the relevant parts to an AI model with a specialist extraction prompt.
  • Validate the response against a strict schema and return it with cost and token information.

Do not send everything to the model

The biggest design decision was to avoid sending whole documents to the AI model. A 90-page report contains only a few pages that matter, usually the income statement and a few notes. By detecting and keeping only the relevant pages, we cut the amount of text sent to the model dramatically, which lowers cost and also improves accuracy because there is less noise. Pre-processing is cheaper than inference, so do as much as you can before the model is called.

Skip what cannot yield an answer

Many small companies file abridged, dormant or micro-entity accounts that contain no revenue figure at all. We check the filing description before downloading anything, and we also look for exemption wording inside the document. When a filing cannot contain the data we want, we skip it entirely: no download, no OCR, no model call. This saves money and avoids inventing numbers that are not there.

Handling scanned documents

Some filings are image-only scans with no text layer. Running OCR and filtering pages by noisy keywords can drop the very page you need. For those documents we detect that no embedded text exists and send the full original PDF so the model can read the page images directly. It is slower per document but far more reliable, and it avoids a separate OCR step.

Validation, retries and cost tracking

AI output must never be trusted blindly. Every response is validated against a schema, and if extraction fails we retry once with a reinforced prompt. Each response also reports approximate token usage and cost, so we can compare models and budget large batches. The service exposes endpoints for a single company, a batch of companies and a CSV upload, and it is packaged with Docker, a non-root user and a health check.

Lessons

  • Reduce the input before you call the model.
  • Know when to skip, and treat a missing value as a valid answer.
  • Use different strategies for text and scanned documents.
  • Validate every output and track cost from day one.
  • Make the service simple to call, with clear single and batch endpoints.

Need something similar?

If you have documents, reports or forms that need turning into structured data, we can design a pipeline for your case. Get in touch to discuss it.

Talk to Fortune Digital Services

Have a software, web application or infrastructure project in mind? Tell us about it and we will get back to you.

Contact us