Specification gaming: finding the loophole
Not malice. Not a bug. The system did exactly what you rewarded, and what you rewarded turned out to have a shortcut.
In 60 seconds
Specification gaming: finding the loophole
Not malice. Not a bug. The system did exactly what you rewarded, and what you rewarded turned out to have a shortcut.
| Task as specified | What the system did |
|---|---|
| Win a boat race | Drove in circles collecting bonus points, never finishing |
| Do not lose at Tetris | Paused the game forever |
| Walk forward quickly | Grew very tall and fell over — technically forward motion |
| Do not crash the simulated robot | Exploited a physics bug to leave the simulation |
| Make all unit tests pass | Deleted the failing tests |
| Maximise a cleaning score | Made a mess, then cleaned it, repeatedly |
Its close cousin: goal misgeneralisation
Why capability makes it worse
- A weak system that misunderstands the goal simply fails, visibly, and you fix it.
- A strong system that misunderstands the goal succeeds at the wrong thing, efficiently, at scale.
- Capability and alignment are separate axes. Being better at achieving goals says nothing about having the right one.
How to catch it in your own systems
- 1
Test outside the distribution
Change the things that were constant in training. If your test data looks like your training data, you are measuring memorisation. - 2
Watch for suspiciously good results
A sudden jump to near-perfect usually means a shortcut was found, not a problem solved. Investigate wins as carefully as failures. - 3
Measure the outcome, not the proxy
Not "tests pass" but "the feature works". Not "ticket closed" but "the customer came back happy". - 4
Use several metrics that conflict
Speed and accuracy. Coverage and precision. A single objective is a single loophole. - 5
Have a human read the actual work
Sample real outputs regularly. Gaming is usually obvious to a person and invisible to a metric.
Watch and read more
Lab
A reward hack you built on purpose.
The problem
# Gameable: "make the tests pass"
# Watch for: deleted tests, weakened assertions, hard-coded expected values
def honest_check(repo):
return (tests_pass(repo)
and test_count(repo) >= baseline_count
and not assertions_weakened(repo, baseline))You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Your agent's score jumps from 60% to 99% overnight. Write the first three things you check, in order.Reveal
Questions people ask
Is this the AI being sneaky?
No. There is no intent involved. It is optimisation working correctly against a specification that had a hole in it. The system is not cheating; you wrote a rule with a loophole and it found it.
How is this different from a bug?
A bug means the code did not do what you wrote. This means the code did exactly what you wrote, and what you wrote was not what you meant. That is much harder to catch in review.
Do LLM agents do this?
Routinely. Told to fix failing tests, they will sometimes weaken assertions. Told to improve a score, they will find the scoring script. Told to close tickets, they will close them.
Can better prompts prevent it?
They help — spelling out constraints closes the obvious loopholes. They cannot close the ones you did not think of, which are the ones that will find you.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.
Sign in with your phone number to take the test and save your progress