A CIS deduction checker on AWS for a few dollars a month
A refurbishment contractor in Leicester paid fourteen subcontractors GBP 1,146,380 in a tax year and took every deduction at the rate HMRC gave it. The rates were right. What went wrong was the number the rates were applied to, and nobody noticed until an HMRC compliance check asked for the receipts behind three subcontractors’ materials lines.

Key takeaways
- The deduction is only as right as the base it is taken from, and the base is a materials question.
- Materials the subcontractor paid for come out of the base. Materials nobody can evidence are the contractor’s risk.
- Verification gives a rate, a verification number and a date, and all three belong on the record.
- The return, the statements and the payment come from one frozen month.
- Designed on AWS for about $3 a month.
The whole system on one page
Before any code, here is the shape of what we are designing.
- Machine learning
- Security & identity
- Analytics
Why a contractor that pays on time still gets this wrong
Because the scheme looks like a rate problem and is actually a document problem. HMRC tells you whether a subcontractor is registered, unmatched or holds gross payment status, and the percentage follows from that answer mechanically. Nobody in a well-run accounts office applies 20 per cent where they were told 30.
What the percentage is applied to is a different matter. The deduction comes off the payment after taking out VAT and whatever the subcontractor actually paid for materials, plant hire, consumables and fuel used on the job. That figure is on the subcontractor’s invoice, written by the subcontractor, and usually keyed into the ledger by somebody processing forty other invoices that week.
So the materials line gets keyed as it arrives. A groundworker who writes materials and labour with two numbers beside it gets both numbers believed, and a plasterer who forgets to split the plaster out of one lump sum gets deducted on the lot.
What runs (the inside)
- Verification. Who you are paying, the rate HMRC gave, and whether that answer is still in date. Part 2.
- The deduction. Labour, materials, plant and consumables separated, and every materials figure marked evidenced, estimated or unsupported. Part 3.
- The reverse charge. Whether the invoice should carry VAT at all, and what happens when it does and should not. Part 4.
- The close. The return, the statements and the payment, from one frozen set of numbers. Part 5.
One contractor, one tax year
- Management
- Analytics
- People
In plain words
Invoices arrive by email, and each one is read once. The read separates labour from materials, plant hire, consumables, fuel and travel, picks out the VAT line and any reverse-charge wording, finds the subcontractor’s UTR as printed, and notes whether anything attached to the same email supports the materials figure.
Before any money moves, the subcontractor is checked against the verification record. If they were on one of this contractor’s returns in the current tax year or the previous two, the rate on file stands; otherwise they are verified again. The rate, the verification number and the date are stored, and every deduction points at the exact record it used.
Then the arithmetic, which is the easy part: payment excluding VAT, less the allowable materials and costs, multiplied by the rate. It is stored with every input, so the question an inspector actually asks — why was this deduction taken on GBP 2,620 and not GBP 3,860 — is answered by a record rather than by somebody’s memory of the invoice.
Once a month the tax month closes. It ends on the 5th, the system freezes it on the 6th, and the return, the payment and deduction statements and the amount to pay HMRC are all built from the same frozen rows, ready well before the 19th.
Design rules that shaped every decision
- The rate comes from a verification record, and every deduction names the record it used.
- A materials figure is evidenced, estimated with a reason, or unsupported. Never just keyed.
- The deduction base is stored with its parts, not only the deduction.
- An invoice that charges VAT on a reverse-charge supply is held, not paid and fixed later.
- A closed tax month is frozen. A correction is a new version with a reason.
- Evidence is captured when the invoice is read, not assembled when HMRC asks.
What it does not do
It does not decide employment status. Every CIS return carries a declaration that the employment status of each subcontractor has been considered, and that is a judgement about control, substitution and the working relationship. The system records who made that decision and when; it does not make it.
It does not file the return or pay HMRC either. It produces the return figures, the statements and the amount due, and a person submits and pays, because the return carries declarations and a declaration is somebody’s decision. That division has held up well in the other compliance systems in this series and it holds up here.
And it is not a purchase ledger. It does not match invoices to orders, approve them or argue about price. It takes an approved invoice as its input and argues about exactly one thing: how much of it is labour.
The next four posts walk through each piece: verifying a subcontractor, splitting labour from materials, checking the reverse charge, and closing the tax month with the evidence behind it. One diagram per post, a cost breakdown, and an engineering reference at the end.
All posts