# Using AI to build payroll software? Don't turn the official worked examples straight into tests

> Three official UK payroll guides have worked examples that do not match the calendar or the arithmetic. What is wrong in each, and how I use examples now.

- Author: Sam Brown (Payroll Explained)
- Published: 2026-11-23
- Tags: AI, payroll software, testing, HMRC guidance, statutory maternity pay
- Canonical: https://payrollexplained.uk/blog/when-the-worked-example-is-wrong/

---

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](/blog/the-missing-22-days-in-regulation-16/),
where the page was out of date. Here the example itself is wrong.

<div class="facts">
<div><strong>Tuesday</strong><span>what 5 May 2026 is. HMRC's guide says Wednesday</span></div>
<div><strong>£250</strong><span>what £1,500 minus £1,250 comes to. The levy guidance prints £1,250</span></div>
<div><strong>1 week</strong><span>how early the maternity pay example puts the qualifying week</span></div>
<div><strong>11 Nov 2026</strong><span>when the guide with the wrong dates was last republished</span></div>
</div>

## 1. Dates that aren't on the calendar

[CWG2][cwg2] is HMRC's further guide to PAYE and National Insurance for
employers. [Section 1.8][cwg2-18] 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"][cwg2-may] | 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)"][cwg2-year] | 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"][cwg2-xmas] | Two different dates for the same thing, one sentence apart. 19 December is a Saturday |

<payday-check-demo>Interactive: pick a payday between 6 April 2025 and 5 April 2027, or one of the dates from HMRC's guide, and see its day of the week, tax year, tax month, tax week and whether it is a banking day in England and Wales. For the guide's own dates it shows what CWG2 section 1.8 says next to what the calendar says: 5 May 2026 is a Tuesday in tax month 1, not a Wednesday in tax month 2; 3 April 2026 is in tax year 2025 to 2026; 6 April 2026 is Easter Monday; 19 December 2026 is a Saturday (web version only).</payday-check-demo>

<div class="note mine">
<span class="label">My working</span>

- 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][bank-holidays]. Easter Monday isn't a bank holiday in Scotland, so up
  there the example's Monday does work.

</div>

## 2. Sums that don't add up

HMRC has a page of [Apprenticeship Levy guidance for software developers][levy].
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][levy-liq], month 1 | "Levy payable to month 1 is £1,250 (£1,500 - £1,250)" | £250 |
| [Example 5][levy-5], 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][levy-5], 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][levy-3], 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][levy-5] 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][levy-monthly] says it is "rounded to 2
decimal places". Example 5 splits its £5,000 over 12 months and prints
£416.66.

<div class="note mine">
<span class="label">My working</span>

- £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".

</div>

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][smp] gives
[the rule][smp-qw]. 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][smp-weekly] 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.

<smp-week-demo>Interactive: enter the date a baby is due and see the week the baby is due, the qualifying week (the 15th week before, Sunday to Saturday), the last Friday payday in the qualifying week and the relevant period for average earnings. For a baby due 23 March 2025 the qualifying week is Sunday 8 December to Saturday 14 December 2024 and the relevant period for a Friday payday is 19 October to 13 December 2024. GOV.UK's example gives 1 to 6 December 2024 and 12 October to 6 December 2024 (web version only).</smp-week-demo>

<div class="note mine">
<span class="label">My working</span>

- 23 March 2025 is a Sunday, so the week the baby is due starts that day.
- [HMRC's own table of dates][smp-table] 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.

</div>

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][smp-monthly] 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:

<pre class="w-mono">
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
</pre>

## Sources

All checked on 23 November 2026.

- [HMRC: CWG2, further guide to PAYE and National Insurance contributions, 2026 to 2027](https://www.gov.uk/government/publications/cwg2-further-guide-to-paye-and-national-insurance-contributions/2026-to-2027-employer-further-guide-to-paye-and-national-insurance-contributions) - section 1.8. Page last updated 11 November 2026.
- [GOV.UK: UK bank holidays](https://www.gov.uk/bank-holidays) - Good Friday 3 April 2026, Easter Monday 6 April 2026, early May bank holiday 4 May 2026.
- [HMRC: Apprenticeship Levy, guidance for software developers](https://www.gov.uk/government/publications/payroll-technical-specifications-apprenticeship-levy/apprenticeship-levy-guidance-for-software-developers) - 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](https://www.gov.uk/guidance/statutory-maternity-pay-manually-calculate-your-employees-payments) - the qualifying week definition and both worked examples. Last updated 6 April 2025.
- [HMRC: Statutory Maternity Pay, table of dates for employee entitlement](https://www.gov.uk/government/publications/statutory-maternity-pay-table-of-dates-for-employee-entitlement) - 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.*

[cwg2]: https://www.gov.uk/government/publications/cwg2-further-guide-to-paye-and-national-insurance-contributions/2026-to-2027-employer-further-guide-to-paye-and-national-insurance-contributions
[cwg2-18]: https://www.gov.uk/government/publications/cwg2-further-guide-to-paye-and-national-insurance-contributions/2026-to-2027-employer-further-guide-to-paye-and-national-insurance-contributions#para18
[cwg2-may]: https://www.gov.uk/government/publications/cwg2-further-guide-to-paye-and-national-insurance-contributions/2026-to-2027-employer-further-guide-to-paye-and-national-insurance-contributions#when-a-payment-is-made-on-the-first-working-day-after-the-regular-payday
[cwg2-xmas]: https://www.gov.uk/government/publications/cwg2-further-guide-to-paye-and-national-insurance-contributions/2026-to-2027-employer-further-guide-to-paye-and-national-insurance-contributions#when-a-regular-payment-is-made-early-at-christmas
[cwg2-year]: https://www.gov.uk/government/publications/cwg2-further-guide-to-paye-and-national-insurance-contributions/2026-to-2027-employer-further-guide-to-paye-and-national-insurance-contributions#when-a-regular-payday-and-actual-payday-cross-a-tax-year
[bank-holidays]: https://www.gov.uk/bank-holidays
[levy]: https://www.gov.uk/government/publications/payroll-technical-specifications-apprenticeship-levy/apprenticeship-levy-guidance-for-software-developers
[levy-liq]: https://www.gov.uk/government/publications/payroll-technical-specifications-apprenticeship-levy/apprenticeship-levy-guidance-for-software-developers#example--a-business-goes-into-liquidation
[levy-3]: https://www.gov.uk/government/publications/payroll-technical-specifications-apprenticeship-levy/apprenticeship-levy-guidance-for-software-developers#example-3--regular-pay-bill-of-35341056-each-month
[levy-5]: https://www.gov.uk/government/publications/payroll-technical-specifications-apprenticeship-levy/apprenticeship-levy-guidance-for-software-developers#example-5--a-unit-of-companies-with-equal-allowance
[levy-monthly]: https://www.gov.uk/government/publications/payroll-technical-specifications-apprenticeship-levy/apprenticeship-levy-guidance-for-software-developers#monthly-levy-allowance
[smp]: https://www.gov.uk/guidance/statutory-maternity-pay-manually-calculate-your-employees-payments
[smp-qw]: https://www.gov.uk/guidance/statutory-maternity-pay-manually-calculate-your-employees-payments#qualifying-week
[smp-weekly]: https://www.gov.uk/guidance/statutory-maternity-pay-manually-calculate-your-employees-payments#example-for-an-employee-who-is-paid-weekly
[smp-monthly]: https://www.gov.uk/guidance/statutory-maternity-pay-manually-calculate-your-employees-payments#example-for-an-employee-who-is-paid-monthly
[smp-table]: https://www.gov.uk/government/publications/statutory-maternity-pay-table-of-dates-for-employee-entitlement
