All projects

Tax Audit System with Rule Extraction from Legislation

A language model reads the legislation; a deterministic service runs the audit.

  • Python (LLM)
  • Go
  • Next.js
  • MySQL
  • Redis

Source not published: the system was built for an audit firm and the code belongs to the client.

Problem

Tax audit rests on legislation, and legislation keeps changing. Hard-coding the rules means shipping a release for every amendment; asking a language model for the rules means losing reproducibility.

In audit work reproducibility is not optional. When a finding is challenged, "the model said so" is not a justification: you have to show which article, and which version of its text was in force on which date.

There is a further constraint: taxpayer data is sensitive and must not leave the system.

Solution

The language model was taken off the hot path and the flow split in two.

Offline. A collector written for the purpose pulls statutes and high-court rulings into a database; a RAG layer works over that corpus and turns articles into audit rules. Rules are stored as JSON with their article reference and validity period, and none takes effect without passing a human review gate.

Hot path. The audit run itself is a Go service applying the approved JSON rules deterministically. The same document, the same date and the same rule set always produce the same result.

Taxpayer data never leaves the system at any stage; the external language model only ever sees public legislation.

Outcome

It runs end to end: non-compliance is detected as soon as a document is uploaded, and reporting runs on the auditor's request.

What the architecture carries is not a number but a guarantee: every audit run is reproducible and justifiable. Behind any finding, the article and the version of its text in force at that date are on record.

Turning the system into a multi-tenant SaaS was worked through separately; every volume figure in that design is labelled as an assumption rather than a measurement.