Using AI to build payroll software? Don't turn the official worked examples straight into tests
- A worked example is the first thing a developer, or an AI model, turns into a test. I checked the examples in three official guides and each one has mistakes.
- HMRC's employer guide calls 5 May 2026 a Wednesday in tax month 2. It is a Tuesday in tax month 1.
- HMRC's levy guidance for developers prints £1,500 minus £1,250 as £1,250. GOV.UK's maternity pay example uses a qualifying week that is a week early.
So the first thing I do with a new payroll rule is find the worked example. Somebody official has already picked the numbers and shown the answer, so you copy it into a test and write code until the test passes. AI models do exactly the same thing, just faster.
This follows on from the missing 22 days in regulation 16, where the page was out of date. Here the example itself is wrong.
1. Dates that aren’t on the calendar#
CWG2 (opens in a new tab) is HMRC’s further guide to PAYE and National Insurance for employers. Section 1.8 (opens in a new tab) covers what to do when payday lands on a weekend or a bank holiday. It matters because the date decides which tax month, and sometimes which tax year, the pay belongs to.
| What the guide says | What’s wrong |
|---|---|
| “Pay due on Wednesday 5 May 2026 (tax month 2) but paid on Thursday 6 May 2026” (opens in a new tab) | 5 May 2026 is a Tuesday. It’s the last day of tax month 1. It isn’t a bank holiday either, that was Monday 4 May |
| “Regular payday on Friday 3 April 2026 (tax year 2026 to 2027) but paid on Monday 6 April 2026 (tax year 2026 to 2027)” (opens in a new tab) | The example is about pay that crosses a tax year, but both dates are given the same year. 3 April is in 2025 to 2026. And 6 April 2026 is Easter Monday, so in England and Wales it isn’t the next working day |
| For a weekly payday of Friday 18 December, paid a week early: “must be treated as having been paid on 18 December 2026. The ‘payment date’ on the FPS should be 19 December” (opens in a new tab) | Two different dates for the same thing, one sentence apart. 19 December is a Saturday |
- A tax month runs from the 6th to the 5th. Month 1 is 6 April to 5 May, so 5 May is in month 1 and 6 May is in month 2.
- 5 May is a Wednesday in 2021 and in 2027. My guess is the example was written for another year and only the year got changed. I can’t prove that.
- Good Friday 2026 is 3 April and Easter Monday is 6 April, from GOV.UK’s bank holiday list (opens in a new tab). Easter Monday isn’t a bank holiday in Scotland, so up there the example’s Monday does work.
2. Sums that don’t add up#
HMRC has a page of Apprenticeship Levy guidance for software developers (opens in a new tab). It has six numbered examples, plus one about a business going into liquidation. They use a levy of 0.5% of the pay bill and an allowance of £15,000 a year, and work through the year month by month.
| Where on HMRC’s page | What it prints | What it should be |
|---|---|---|
| The liquidation example (opens in a new tab), month 1 | “Levy payable to month 1 is £1,250 (£1,500 - £1,250)” | £250 |
| Example 5 (opens in a new tab), month 12 | “Levy payable to month 12 is £100,000.08 (£15,000 – £5,000)” | £10,000.08. There’s a zero too many |
| Example 5 (opens in a new tab), month 1 | “Levy payable to month 1 is £833 (£1,250 – £316.66)” | The line above it gives the allowance as £416.66 |
| Example 3 (opens in a new tab), month 12 | Starts with a yearly pay bill of £4,240,926.72, then month 12 uses £4,220,926.74 | The first one. 12 × £353,410.56 is £4,240,926.72 |
Nobody is going to believe a £100,000 levy on a £3 million pay bill. The problem is that one of the actual rules is only shown in these examples.
Example 5 (opens in a new tab) is HMRC’s example of three companies sharing the £15,000 allowance equally, so £5,000 each. The page’s own rule for the monthly allowance (opens in a new tab) says it is “rounded to 2 decimal places”. Example 5 splits its £5,000 over 12 months and prints £416.66.
- £5,000 ÷ 12 = £416.666… Rounded to two places that’s £416.67. The example prints £416.66, so it has cut the number off, not rounded it.
- 12 × £416.66 = £4,999.92, which is 8p under the allowance. 12 × £416.67 would be £5,000.04, which is 4p over.
- The text straight after example 5 backs the cut-off version. It says the employer “receives 8 pence less than £5,000 in allowance for the year” and talks about “the rules on rounding down and truncating”.
So the example is the best evidence I can find for whether to round or cut off, and it’s on the same page as the typos above.
3. An example that uses the wrong week#
To work out Statutory Maternity Pay you average about eight weeks of the employee’s pay. Which eight weeks depends on one week, called the qualifying week. Get that week wrong and you average the wrong paydays.
GOV.UK’s page for working SMP out by hand (opens in a new tab) gives the rule (opens in a new tab). The qualifying week is “the 15th week (Sunday to Saturday) before the week the baby is due”. So you find the week the baby is due and count back 15.
The page’s example (opens in a new tab) is a baby due on 23 March 2025. It gives the qualifying week as “1 December 2024 to 6 December 2024”. Here’s the count.
| Weeks before | Sunday to Saturday | What it is |
|---|---|---|
| 0 | 23 to 29 March 2025 | The week the baby is due |
| 1 | 16 to 22 March 2025 | |
| 2 | 9 to 15 March 2025 | |
| 3 to 13 | … | |
| 14 | 15 to 21 December 2024 | |
| 15 | 8 to 14 December 2024 | The qualifying week |
| 16 | 1 to 7 December 2024 | The week GOV.UK’s example uses |
So the example has counted back 16 weeks, not 15. Its week is also only six days long. It stops on Friday 6 December, where a Sunday to Saturday week ends on the 7th.
- 23 March 2025 is a Sunday, so the week the baby is due starts that day.
- HMRC’s own table of dates (opens in a new tab) agrees with the count. For a baby due 23 to 29 March 2025 it lists 8 to 14 December 2024.
- For someone paid every Friday, the pay that gets averaged is 19 October to 13 December. HMRC calls this the relevant period. The example’s version is 12 October to 6 December, a week earlier.
The levy typos look wrong. An average taken over the wrong eight weeks looks completely normal, and for someone whose pay changes from week to week it gives a different answer.
The monthly example (opens in a new tab) on the same page has its own slip. It says “The relevant period is 30 October 2024 to 30 November 2024” and then, on the next line, adds up earnings “between 1 October 2024 and 29 November 2024”.
What this has to do with AI#
If you ask a model to “write tests from the worked examples”, it copies what’s printed.
| If you copy | What happens |
|---|---|
| The printed answer (£1,250) | The test fails against correct code. Then you, or the model, change the code until it passes |
| The printed dates (Wednesday 5 May, tax month 2) | Your test data is wrong before any code runs |
| The example instead of its own definition (1 to 6 December) | Nothing fails. The average is just taken over the wrong weeks |
What I do about it#
| Do | Why |
|---|---|
| Take the inputs from an example, not the answer | The inputs are a realistic case. The printed answer might be a typo |
| Work the answer out yourself, then compare | If they differ, find out which one is wrong before you write any code |
| Check every date with code | Day of the week, tax month, bank holiday. It’s one line each |
| If an example disagrees with its own definition, follow the definition | And write down that you did |
| Ask the model to recompute, not copy | Ask it to work out every example again and list the ones that don’t match. If you only ask for tests from the examples, it copies the typos too |
One from my own code. My levy test uses example 3. It only takes the monthly pay bill of £353,410.56 from it and works the year out itself, so the wrong month 12 line never got near it.
And the ledger entry for the maternity one:
rule SMP qualifying week value 15th week before the week the baby is due, Sunday to Saturday source GOV.UK "Work out your employee's payments for SMP" (the definition) backed by HMRC SMP table of dates, 2024 not using the worked example on the same page (1 to 6 December 2024) checked 23 Nov 2026 note the example matches the table row for a baby due a week earlier
Sources#
All checked on 23 November 2026.
- HMRC: CWG2, further guide to PAYE and National Insurance contributions, 2026 to 2027 (opens in a new tab) - section 1.8. Page last updated 11 November 2026.
- GOV.UK: UK bank holidays (opens in a new tab) - Good Friday 3 April 2026, Easter Monday 6 April 2026, early May bank holiday 4 May 2026.
- HMRC: Apprenticeship Levy, guidance for software developers (opens in a new tab) - the liquidation example, example 3 and example 5. The page gives its last update as 20 December 2016.
- GOV.UK: Work out your employee’s payments for Statutory Maternity Pay (opens in a new tab) - the qualifying week definition and both worked examples. Last updated 6 April 2025.
- HMRC: Statutory Maternity Pay, table of dates for employee entitlement (opens in a new tab) - the 2024 table, rows for babies due 16 to 22 March and 23 to 29 March 2025.
My reading of the published pages as at 23 November 2026. Not legal advice. HMRC may well have fixed these by the time you read this. The date widget uses England and Wales bank holidays only.
Comments