Simple Algorithm
Artificial Intelligence · Deep Layer · 26 min

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 cc is equivalent to shifting every terminal reward by −c/(1−γ)-c/(1-\gamma).
  • 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 a>0a>0 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:

DerivationProof of sufficiency
  1. QM∗(s,a)=Es′[R(s,a,s′)+γmax⁡a′QM∗(s′,a′)]Q^*_M(s,a)=\E_{s'}\Big[R(s,a,s')+\gamma\max_{a'}Q^*_M(s',a')\Big]

    Start from the Bellman optimality equation of MM:

  2. QM∗(s,a)−Φ(s)=Es′[R(s,a,s′)+γΦ(s′)−Φ(s)⏟R+F+γmax⁡a′(QM∗(s′,a′)−Φ(s′))]Q^*_M(s,a)-\Phi(s)=\E_{s'}\Big[\underbrace{R(s,a,s')+\gamma\Phi(s')-\Phi(s)}_{R+F}+\gamma\max_{a'}\big(Q^*_M(s',a')-\Phi(s')\big)\Big]

    Subtract Φ(s)\Phi(s) from both sides and add and subtract γΦ(s′)\gamma\Phi(s') inside the expectation:

  3. QM′∗=QM∗−Φ⟹arg max⁡aQM′∗(s,a)=arg max⁡aQM∗(s,a)Q^*_{M'}=Q^*_M-\Phi\quad\Longrightarrow\quad\argmax_aQ^*_{M'}(s,a)=\argmax_aQ^*_M(s,a)

    So Q^=QM∗−Φ\hat Q=Q^*_M-\Phi solves the Bellman optimality equation of M′M', whose solution is unique (a γ\gamma-contraction; in the episodic case Φ=0\Phi=0 at terminal states keeps terminal values fixed). Since Φ(s)\Phi(s) does not depend on the action, the greedy actions agree:

  4. ∑t=0T−1γt(γΦ(st+1)−Φ(st))=γTΦ(sT)−Φ(s0) ⟶ −Φ(s0)□\sum_{t=0}^{T-1}\gamma^t\big(\gamma\Phi(s_{t+1})-\Phi(s_t)\big)=\gamma^T\Phi(s_T)-\Phi(s_0)\ \longrightarrow\ -\Phi(s_0)\qquad\square

    Along any trajectory the shaping terms telescope, so every policy's return from s0s_0 shifts by the same −Φ(s0)-\Phi(s_0), and rankings of policies cannot change:

DerivationA living reward moves every exit
  1. c 1−γk1−γ+γkRT=c1−γ+γk(RT−c1−γ)c\,\frac{1-\gamma^k}{1-\gamma}+\gamma^kR_T=\frac{c}{1-\gamma}+\gamma^k\Big(R_T-\frac{c}{1-\gamma}\Big)

    Pay cc on every transition of an episodic task whose terminal states have values RTR_T. A trajectory that ends at TT after kk transitions returns

  2. RT ⟼ RT−c1−γR_T\ \longmapsto\ R_T-\frac{c}{1-\gamma}

    A trajectory that never ends returns c/(1−γ)c/(1-\gamma), 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:

  3. In potential terms, Φ≡−c/(1−γ)\Phi\equiv-c/(1-\gamma) on non-terminal states reproduces cc on every transition between them, but with Φ=0\Phi=0 at the exits it would pay c/(1−γ)c/(1-\gamma), not cc, on entering one. The living reward differs from harmless shaping exactly at termination, which is what it distorts.

Check your understanding

Which reward modification is guaranteed to leave the optimal policies of every episodic MDP unchanged?

  1. Adding +1+1 to every step
  2. Adding Φ(s′)\Phi(s') on entering each state s′s', for a potential Φ\Phi
  3. Adding a bonus each time the agent enters a designated subgoal state
  4. Adding γΦ(s′)−Φ(s)\gamma\Phi(s')-\Phi(s) on each transition, with Φ=0\Phi=0 at terminal states
Show the answer

D. Adding γΦ(s′)−Φ(s)\gamma\Phi(s')-\Phi(s) on each transition, with Φ=0\Phi=0 at terminal states

That is potential-based shaping: it shifts Q∗Q^* by −Φ(s)-\Phi(s), 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.

VariantMechanismExample
Regressionalproxy = goal + noise, so selecting extreme proxy values also selects noisebest-of-nn sampling against a noisy reward model
Extremala proxy–goal relation fit on ordinary cases breaks in the extreme region the optimizer reachesreward-model scores that keep rising on ever longer, degenerate answers
Causalthe proxy is correlated with the goal without causing it, so intervening on the proxy breaks the linkdrilling test formats raises scores, not skill
Adversarialother agents exploit the proxy for their own endsspam pages built to rank highly in a search engine
DerivationProof
  1. JR(π)=∑s,aηπ(s,a) R(s,a)=⟨R,ηπ⟩J_R(\pi)=\sum_{s,a}\eta_\pi(s,a)\,R(s,a)=\langle R,\eta_\pi\rangle

    Returns are linear in the discounted occupancy measure ηπ(s,a)=∑tγtPr⁡(st=s,at=a)\eta_\pi(s,a)=\sum_t\gamma^t\Pr(s_t=s,a_t=a):

  2. ⟨r1,h⟩>0>⟨r2,h⟩\langle r_1,\mathbf h\rangle>0>\langle r_2,\mathbf h\rangle

    Let r1,r2r_1,r_2 be the components of R1,R2R_1,R_2 along the affine hull of the occupancy measures. Unless r2=λr1r_2=\lambda r_1 with λ≥0\lambda\ge0, some direction h\mathbf h in the hull improves one and worsens the other (if r2=λr1+wr_2=\lambda r_1+\mathbf w with w⊥r1\mathbf w\perp r_1, w≠0\mathbf w\neq0, take h=r1−sw\mathbf h=r_1-s\mathbf w for large ss; if λ<0\lambda<0, take h=r1\mathbf h=r_1):

  3. Inside the open set, η\eta and η+th\eta+t\mathbf h are both occupancy measures of policies in Π\Pi for small t>0t>0, and they witness hackability. So an unhackable pair has r2=λr1r_2=\lambda r_1: equivalent if λ>0\lambda>0, constant R2R_2 if λ=0\lambda=0. □\square

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

SystemIntendedRewardedWhat the optimizer did
Boat-racing RL agent (Clark & Amodei, 2016)win the racegame scorelooped 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 oneheight of the red block's bottom faceflipped the red block upside down
Grasping from human feedback (Christiano et al., 2017)grasp the objectraters' approval of camera imageshovered between camera and object so that it only looked like grasping
Evolution strategies on Q*bert (Chrabaszcz et al., 2018)play the gamegame scorefound a bug that racked up huge scores without progressing to the next level
Reasoning models on coding tasks (Baker et al., 2025)working codeunit tests passedited or special-cased tests, or made checks pass without solving the task
Language models in a gameable curriculum (Denison et al., 2024)honest, helpful behaviorenvironment rewards with exploitable flawsafter training on milder hacks such as sycophancy, occasionally edited their own reward code
Lehman et al. (2020) collect dozens of similar anecdotes from evolutionary computation, many exploiting bugs in physics simulators.

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.

Check your understanding

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?

  1. The agent's training reward was high
  2. The agent dies more often on the test levels
  3. The agent still dodges enemies and jumps gaps efficiently, reaching the end of the level while passing the coin
  4. 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 γΦ(s′)−Φ(s)\gamma\Phi(s')-\Phi(s) shifts Q∗Q^* by −Φ(s)-\Phi(s) and preserves optimal policies; a living reward cc is equivalent to shifting every terminal reward by −c/(1−γ)-c/(1-\gamma), 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 qq-quantilizer's expected cost is at most 1/q1/q 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.

Question 1

In the classic gridworld (γ=0.9\gamma=0.9, exits +1+1 and −1-1), you set a living reward of c=−0.5c=-0.5. The task is then equivalent to one with no living reward and exits worth

  1. 0.50.5 and −1.5-1.5
  2. 1.51.5 and −0.5-0.5
  3. 66 and 44
  4. −4-4 and −6-6
Show the answer

C. 66 and 44

Each exit shifts by −c/(1−γ)=0.5/0.1=+5-c/(1-\gamma)=0.5/0.1=+5. 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.

Question 2

Under potential-based shaping F(s,a,s′)=γΦ(s′)−Φ(s)F(s,a,s')=\gamma\Phi(s')-\Phi(s), how is the shaped optimal action-value function related to the original?

  1. QM′∗(s,a)=QM∗(s,a)Q^*_{M'}(s,a)=Q^*_M(s,a)
  2. QM′∗(s,a)=QM∗(s,a)−Φ(s)Q^*_{M'}(s,a)=Q^*_M(s,a)-\Phi(s)
  3. QM′∗(s,a)=QM∗(s,a)+γΦ(s)Q^*_{M'}(s,a)=Q^*_M(s,a)+\gamma\Phi(s)
  4. QM′∗(s,a)=QM∗(s,a)−Φ(s)/(1−γ)Q^*_{M'}(s,a)=Q^*_M(s,a)-\Phi(s)/(1-\gamma)
Show the answer

B. QM′∗(s,a)=QM∗(s,a)−Φ(s)Q^*_{M'}(s,a)=Q^*_M(s,a)-\Phi(s)

QM∗−ΦQ^*_M-\Phi satisfies the shaped Bellman optimality equation, and its solution is unique. The shift depends on the state only, so greedy actions are unchanged.

Question 3

A 1%-quantilizer (q=0.01q=0.01) samples actions from a base distribution under which a catastrophic action has probability 10−310^{-3}. What is the most the quantilizer can raise that probability to?

  1. 10−510^{-5}
  2. 10−310^{-3}
  3. 11
  4. 0.10.1
Show the answer

D. 0.10.1

Apply the bound with cc = the indicator of catastrophe: Pr⁡quantilizer≤10−3/0.01=0.1\Pr_{\text{quantilizer}}\le10^{-3}/0.01=0.1. Milder optimization (larger qq) gives a tighter bound, at the cost of a lower expected proxy score.

Question 4

Spammers craft pages that exploit a search engine's ranking signals, so that top-ranked results become less useful. Which Goodhart variant is this?

  1. Regressional
  2. Adversarial
  3. Extremal
  4. 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.