Specification Gaming & Reward Hacking
When optimizers find loopholes.
Every reward function is a guess at what you want, and an optimizer searches the space of behaviors far more thoroughly than its designer did. This lesson asks which changes to a reward are harmless, proves when optimizing a proxy must eventually hurt, collects documented reward hacks from game agents to coding agents, and separates gaming a wrong objective from misgeneralizing a right one.
What you’ll learn
- Prove the potential-based shaping theorem, and show that a living reward is equivalent to shifting every terminal reward by .
- Classify proxy failures with the four Goodhart variants, and prove simplified versions of the results on unhackable proxies and omitted attributes.
- Bound the damage of soft optimization with quantilizers, and analyze documented reward hacking, including the risk of training against a monitor.
- Define goal misgeneralization precisely and relate it to underspecification and to inner alignment.
Which reward changes are harmless?
Two rewards that induce the same optimal policies are interchangeable for a planner. Scaling by is harmless in every MDP. Adding a constant to every reward is harmless in a continuing task, where every policy's return shifts by the same amount, but not in an episodic one, where the number of rewards collected depends on the policy. The general harmless additive change is potential-based shaping:
Start from the Bellman optimality equation of :
Subtract from both sides and add and subtract inside the expectation:
So solves the Bellman optimality equation of , whose solution is unique (a -contraction; in the episodic case at terminal states keeps terminal values fixed). Since does not depend on the action, the greedy actions agree:
Along any trajectory the shaping terms telescope, so every policy's return from shifts by the same , and rankings of policies cannot change:
Pay on every transition of an episodic task whose terminal states have values . A trajectory that ends at after transitions returns
A trajectory that never ends returns , the same constant plus zero. Dropping the constant, the task is equivalent to one with no living reward, never-ending trajectories worth 0, and shifted exits:
In potential terms, on non-terminal states reproduces on every transition between them, but with at the exits it would pay , not , on entering one. The living reward differs from harmless shaping exactly at termination, which is what it distorts.
Which reward modification is guaranteed to leave the optimal policies of every episodic MDP unchanged?
- Adding to every step
- Adding on entering each state , for a potential
- Adding a bonus each time the agent enters a designated subgoal state
- Adding on each transition, with at terminal states
Show the answer
D. Adding on each transition, with at terminal states
That is potential-based shaping: it shifts by , which no action can affect. The other three reward visiting states or continuing, and an optimizer can farm them.
Goodhart's law, formalized
"When a measure becomes a target, it ceases to be a good measure." Manheim & Garrabrant (2018) separate four mechanisms behind this paraphrase of Goodhart's law. RLHF & Preference Optimization analyzes the first two for learned reward models, including the measured overoptimization curves.
| Variant | Mechanism | Example |
|---|---|---|
| Regressional | proxy = goal + noise, so selecting extreme proxy values also selects noise | best-of- sampling against a noisy reward model |
| Extremal | a proxy–goal relation fit on ordinary cases breaks in the extreme region the optimizer reaches | reward-model scores that keep rising on ever longer, degenerate answers |
| Causal | the proxy is correlated with the goal without causing it, so intervening on the proxy breaks the link | drilling test formats raises scores, not skill |
| Adversarial | other agents exploit the proxy for their own ends | spam pages built to rank highly in a search engine |
Returns are linear in the discounted occupancy measure :
Let be the components of along the affine hull of the occupancy measures. Unless with , some direction in the hull improves one and worsens the other (if with , , take for large ; if , take ):
Inside the open set, and are both occupancy measures of policies in for small , and they witness hackability. So an unhackable pair has : equivalent if , constant if .
On rich policy sets, then, every proxy that is not equivalent to the true reward can be hacked by some path of policy improvement; non-trivial unhackable pairs exist only on restricted sets, such as finite sets of policies. The useful questions become which directions an optimizer takes and how far it should go.
Reward hacking in the record
| System | Intended | Rewarded | What the optimizer did |
|---|---|---|---|
| Boat-racing RL agent (Clark & Amodei, 2016) | win the race | game score | looped through respawning targets, never finishing, for about 20% more points than human players |
| Simulated arm (Popov et al., 2017) | stack a red block on a blue one | height of the red block's bottom face | flipped the red block upside down |
| Grasping from human feedback (Christiano et al., 2017) | grasp the object | raters' approval of camera images | hovered between camera and object so that it only looked like grasping |
| Evolution strategies on Q*bert (Chrabaszcz et al., 2018) | play the game | game score | found a bug that racked up huge scores without progressing to the next level |
| Reasoning models on coding tasks (Baker et al., 2025) | working code | unit tests pass | edited or special-cased tests, or made checks pass without solving the task |
| Language models in a gameable curriculum (Denison et al., 2024) | honest, helpful behavior | environment rewards with exploitable flaws | after training on milder hacks such as sycophancy, occasionally edited their own reward code |
Three patterns recur. Capability raises hacking. Pan, Bhatia & Steinhardt (2022) built misspecified rewards for traffic control, epidemic policy, glucose control and an Atari game, and found that more capable agents (more parameters, finer actions, more training) earned more proxy reward and less true reward, sometimes with abrupt drops in true reward, "phase transitions" that make extrapolating from weaker agents unsafe. The measurement is part of the objective. The camera's viewpoint, the test suite and the simulator's physics were all exploited. The rewarder can be attacked. When the reward comes from a learned model or a language-model judge, the policy is an adversary searching for its blind spots: adversarial Goodhart inside the training loop.
Goal misgeneralization, precisely
In CoinRun, agents trained with the coin always at the far right ran to the end of the level when the coin was moved, and randomizing the coin's position in even a small fraction of training levels sharply reduced the failure (Langosco et al., 2022). In their Keys and Chests environment, an agent trained where keys were scarce kept collecting keys compulsively at test time, when keys were plentiful and chests scarce. Shah et al. (2022) gave further examples, including an agent that followed an expert partner through a hidden sequence of locations and kept following an anti-expert who visited them in the wrong order.
The mechanism is underspecification (D'Amour et al., 2020): many predictors fit the training data equally well and differ off-distribution, and the learner's inductive biases choose among them. When "reach the coin" and "reach the right wall" coincide on every training level, no amount of correct reward can tell them apart; the agent adopts whichever is easier to represent, and a large, fixed wall is easy. Only training data that separates goal from proxy, or a way to inspect which goal was learned, resolves the ambiguity.
Inner alignment (Hubinger et al., 2019) poses the question for future systems that may themselves run an internal optimization: the objective such a system pursues (its "mesa-objective") need not match the training reward. "Deceptive alignment" is the hypothesized case in which such a system behaves well during training to avoid being modified. These are hypotheses, contested and hard to test; the evidence so far comes from deliberately constructed model organisms (Scalable Oversight & Alignment Research), not from natural emergence.
At test time, a CoinRun agent fails to collect a coin placed mid-level. Which observation best shows that this is goal misgeneralization rather than capability failure?
- The agent's training reward was high
- The agent dies more often on the test levels
- The agent still dodges enemies and jumps gaps efficiently, reaching the end of the level while passing the coin
- The agent's action distribution has become more random
Show the answer
C. The agent still dodges enemies and jumps gaps efficiently, reaching the end of the level while passing the coin
Competent, goal-directed behavior toward a different target (the end of the level) is what distinguishes goal misgeneralization: capabilities generalized, the goal did not.
Key takeaways
- Potential-based shaping shifts by and preserves optimal policies; a living reward is equivalent to shifting every terminal reward by , so it changes when to stop.
- Goodhart's law has four mechanisms (regressional, extremal, causal, adversarial); on rich policy sets every proxy not equivalent to the true reward is hackable, and attributes the proxy omits get sacrificed.
- Soft optimization limits damage: a -quantilizer's expected cost is at most times the base distribution's.
- Documented reward hacks span game agents, robots and coding agents; more capable optimizers hack more, and training against a monitor teaches concealment.
- Goal misgeneralization is underspecification of the goal: capabilities generalize and the goal does not, even under a correct reward.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In the classic gridworld (, exits and ), you set a living reward of . The task is then equivalent to one with no living reward and exits worth
- and
- and
- and
- and
Show the answer
C. and
Each exit shifts by . Both exits are now attractive, and the nearer one gains relative to the farther, which is why harsh step costs push agents into the closest exit, even a bad one.
Under potential-based shaping , how is the shaped optimal action-value function related to the original?
Show the answer
B.
satisfies the shaped Bellman optimality equation, and its solution is unique. The shift depends on the state only, so greedy actions are unchanged.
A 1%-quantilizer () samples actions from a base distribution under which a catastrophic action has probability . What is the most the quantilizer can raise that probability to?
Show the answer
D.
Apply the bound with = the indicator of catastrophe: . Milder optimization (larger ) gives a tighter bound, at the cost of a lower expected proxy score.
Spammers craft pages that exploit a search engine's ranking signals, so that top-ranked results become less useful. Which Goodhart variant is this?
- Regressional
- Adversarial
- Extremal
- Causal
Show the answer
B. Adversarial
Other agents, with goals of their own, optimize against the proxy. The degradation comes from their strategic response, not from noise or from the optimizer's own extrapolation.
Further reading
- A. Y. Ng, D. Harada & S. Russell, "Policy invariance under reward transformations: Theory and application to reward shaping," ICML (1999).
- D. Manheim & S. Garrabrant, "Categorizing variants of Goodhart's law," arXiv:1803.04585 (2018).
- J. Skalse, N. H. R. Howe, D. Krasheninnikov & D. Krueger, "Defining and characterizing reward hacking," NeurIPS (2022).
- L. Langosco, J. Koch, L. Sharkey, J. Pfau & D. Krueger, "Goal misgeneralization in deep reinforcement learning," ICML (2022).
- V. Krakovna et al., "Specification gaming: the flip side of AI ingenuity," DeepMind blog (2020), with a public list of documented examples.