Why Potential-Based Reward Shaping Preserves Policy Rankings
A shaped agent learns faster, the curve looks great, and the final policy is subtly wrong. The shaping term did not speed up learning; it quietly rewrote…

Key topics
A shaped agent learns faster, the curve looks great, and the final policy is subtly wrong. The shaping term did not speed up learning; it quietly rewrote the objective.
That failure is common enough that "potential-based reward shaping preserves the optimal policy" gets repeated like a safety certificate. It is a real theorem with a real proof, but the proof leans on specific assumptions, and the slogan hides them. This article derives the result, isolates the boundary term that makes it work, and shows the ways the guarantee breaks.
I assume you already know discounted returns, MDP notation, and the sparse-versus-shaped tradeoff. If not, start with the reward shaping comparison first; here we go straight to the mechanism.
The Claim, and Why It Sounds Too Good
The result, due to Ng, Harada, and Russell, is precise: if you add a shaping reward of the form
to a base reward , where is a bounded potential function and is the same discount factor used in the return, then the set of optimal policies is unchanged. The optimal value function shifts by a constant offset, but the ranking of policies does not.
The common misconception is weaker and wrong: that any "helpful" or "small" shaping reward is safe. It is not. Arbitrary shaping can reorder policies, and a small shaping term can still flip which policy wins if the base rewards are close together. The guarantee is not about magnitude. It is about structure.
Why bother with the theorem at all? Because it lets you densify a sparse signal without silently rewriting the objective. You get a richer learning signal and keep the same success condition. That trade is worth having, but only if you know what you traded away to get it.
Knowledge check
Check your understanding
Answer this question before you continue.
Notation and the Two Reward Functions
Fix an MDP . For an episodic task, trajectories terminate at a terminal state; for a continuing task, they run indefinitely with discounting. The distinction matters later, so keep it in view.
The base reward is . The shaped reward is
The potential maps states to real numbers and must be bounded. The discount factor inside must match the used in the return. That last requirement is not cosmetic; it is the arithmetic that makes the cancellation work.
Define the two returns as expectations over trajectories generated by a policy :
"Policy ranking is preserved" now has a precise meaning: for any two policies ,
Everything below is an argument about that equivalence.
Knowledge check
Check your understanding
Answer this question before you continue.
The Telescoping Derivation
Write the discounted sum of shaping terms along a finite trajectory of length :
Expand the sum term by term:
Look at what happens to any interior state with . It appears once as from the positive term of step , and once as from the negative term of step . The two cancel exactly. Every interior potential vanishes.
What survives is the first and last term:
That is the whole mechanism. The shaping term telescopes, and the extra return depends only on where the trajectory starts and where it ends, not on the actions taken in between.
A small numeric check makes the cancellation visible. Take three states with , , , and . A trajectory has shaping rewards:
Discounted sum: .
The boundary formula gives . Same number. The interior potential of left no trace.
Knowledge check
Check your understanding
Answer this question before you continue.
From Boundary Term to Policy Ranking
Now apply the identity to the return. For a fixed start state , the term is a constant across every policy being compared. It shifts all returns by the same amount and cannot change the ranking.
The load-bearing part is . For the ranking to be preserved, this boundary contribution must be policy-independent. Two conditions deliver that:
- Zero terminal potential. If on every terminal or absorbing state, the term vanishes regardless of when the episode ends. This is the cleanest sufficient condition.
- Equal terminal potential under a fixed horizon. If every episode runs exactly steps, is the same constant for every policy, but that alone is not enough: must also be equal across the terminal states that different policies can reach. If all policies terminate in the same state, or if every reachable terminal state shares the same potential value, the boundary term shifts all returns by the same amount.
Either condition is sufficient. Neither is automatic. The invariance condition, stated cleanly: policy ordering is preserved when the boundary contribution is the same for every policy being compared.
The value function shifts accordingly. For a policy ,
The optimal policy is unchanged, but the numbers are not. If you compare two runs by raw shaped return, you are comparing the shaping term, not the task.
Note: The offset is why a shaped agent can report a higher return while behaving identically. The policy is the same; the accounting changed.
Knowledge check
Check your understanding
Answer this question before you continue.
Where the Guarantee Breaks
The theorem is only as strong as its assumptions. Audit your shaping function against these failure modes before trusting it.
Arbitrary shaping. If is not a potential difference, it has no telescoping structure. Each step's shaping reward accumulates independently, so the extra return depends on the actions taken, and policies can reorder. This is the failure the theorem exists to prevent, and it is the one people reintroduce by hand-tuning rewards without checking the form.
Terminal mismatch. If is nonzero on absorbing states and episodes end at different times under different policies, the surviving term differs across policies. The ranking can flip. The fix is to set on terminal states, or to ensure the terminal potential is equal across all reachable terminal states under a fixed horizon.
Discount mismatch. Using a different inside than in the return breaks the cancellation arithmetic. The interior terms no longer cancel; the proof collapses. This is easy to do accidentally when the shaping function is written in a different module from the return computation.
Time-varying potentials. The static proof assumes does not change during learning. If you learn or adapt online, the guarantee needs the difference taken at the times the states were actually visited: . Otherwise the potentials you subtract were never the ones in force when the reward was issued.
A practical audit rule: write your shaping as , confirm is zero at termination or that all reachable terminal states share the same potential under a fixed horizon, and confirm matches the return. If any of those three checks fails, the guarantee does not apply, and you are running an experiment with an unknown objective.
What This Buys You in an Experiment
The theorem constrains the objective, not the learning speed. Sample-efficiency gains from shaping are empirical and depend on initialization, potential scale, and the structure of the base reward. A well-chosen potential can help a lot; a badly scaled one can hurt. The theorem says nothing about which.
Because the optimal policy is preserved, a shaped run and an unshaped run are comparable on final policy quality. They are not comparable on raw return magnitude, because the shaped return includes the boundary offset. Evaluate both by the base reward.
That evaluation rule is not optional. If you rank runs by shaped return, you are ranking them by the shaping term, and the run with the most aggressive potential will look best regardless of how well it solves the task.
Keep the potential bounded and log it. When a shaped run produces a suspicious policy, you want to trace the result back to the shaping signal rather than blame the algorithm. A logged potential is the difference between a diagnosis and a guess.
The Decision Rule
Before trusting any shaping term, run it through four checks. Write it as . Confirm is zero at termination, or that all reachable terminal states share the same potential under a fixed horizon. Confirm matches the return. Evaluate on the base reward, never the shaped reward.
If all four hold, the policy ranking is preserved and you can use the shaping signal to densify a sparse reward without rewriting the objective. If any fails, you have an arbitrary reward function wearing the costume of a safe one.
The next step is to run the comparison yourself: take a small task, implement the base reward, a potential-based shaping signal, and a deliberately unsafe arbitrary shaping signal, and watch which one preserves the final policy. The derivation tells you what should happen. The experiment tells you whether your implementation actually does it.
Knowledge check
Final check
Finish the article by checking the ideas you just learned.
References
Build a stronger RL mental model
Use structured resources to connect equations, algorithms, and observable agent behavior.


