Abstract
Reinforcement learning algorithms discover policies that maximize reward, but do not necessarily guarantee safety during learning or execution phases. We introduce a new approach to learn optimal policies while enforcing properties expressed in temporal logic. To this end, given the temporal logic specification that is to be obeyed by the learning system, we propose to synthesize a reactive system called a shield. The shield is introduced in the traditional learning process in two alternative ways, depending on the location at which the shield is implemented. In the first one, the shield acts each time the learning agent is about to make a decision and provides a list of safe actions. In the second way, the shield is introduced after the learning agent. The shield monitors the actions from the learner and corrects them only if the chosen action causes a violation of the specification. We discuss which requirements a shield must meet to preserve the convergence guarantees of the learner. Finally, we demonstrate the versatility of our approach on several challenging reinforcement learning scenarios.
Introduction
Reinforcement Learning (RL) is fundamentally a process of trial and error. While this paradigm has achieved remarkable success in simulated environments like games, its application to real-world physical systems—such as autonomous vehicles or industrial robotics—is limited by safety concerns. In these domains, a single "error" can be catastrophic. Traditional Safe RL methods often rely on heavy negative rewards (penalties) to discourage unsafe behavior. However, these methods provide no formal guarantees; an agent might still explore a fatal state before learning to avoid it.
This paper introduces Shielding, a framework that leverages formal methods to provide hard safety guarantees. By placing a reactive "shield" between the agent and the environment, the system ensures that safety specifications—defined via Linear Temporal Logic (LTL)—are never violated during either the learning or execution phases.
Methodology: The Shielding Framework
The core innovation is the synthesis of a Shield, a reactive system derived from a safety specification and a coarse abstraction of the environment. The shield is computed upfront by solving a "safety game," identifying a winning region from which the system can always be kept safe regardless of environmental behavior.
The authors propose two primary architectural implementations for the shield:
- Preemptive Shielding: The shield acts before the agent makes a choice. It analyzes the current state and provides the agent with a restricted list of only the "safe" actions. The agent then selects the highest-reward action from this safe subset.
- Post-posed Shielding: The agent selects an action first. The shield monitors this selection and, if the action is deemed unsafe, overwrites it with a safe alternative before it is executed in the environment.
A key design principle is minimum interference: the shield only intervenes when an action must be blocked to prevent a future safety violation. This ensures the agent retains maximum freedom to optimize for rewards. Furthermore, the framework is "algorithm-agnostic," meaning it can be used with any RL algorithm (e.g., Q-learning, SARSA, DQN) without modification.
Experimental Evaluation
The approach was evaluated across four diverse scenarios:
- Grid Worlds: Navigating a robot through obstacles and moving opponents.
- Self-Driving Simulation: Using a Deep Q-Network (DQN) to keep a car on a track.
- Atari Seaquest: Managing oxygen and diver collection from raw pixel inputs.
- Water Tank Control: Maintaining water levels within safe bounds while minimizing mechanical wear.
Key Results and Insights
The experiments yielded several critical findings:
- Absolute Safety: In all scenarios, shielded agents experienced zero safety violations during both training and execution. In contrast, unshielded agents—even those with high penalties—frequently failed.
- Accelerated Learning: Counter-intuitively, shielding often speeds up convergence. By pruning "dead-end" or catastrophic states from the exploration space, the agent focuses its learning on productive, safe regions. In a 15x9 Grid World, the shielded agent reached stable performance in 20 episodes, compared to 60 for the unshielded version.
- Scalability to Deep RL: The framework successfully integrated with high-dimensional state spaces (Atari) by using abstractions, demonstrating its potential for complex modern RL tasks.
Conclusion
Shielding provides a robust bridge between formal methods and reinforcement learning. By separating the concerns of safety (handled by the shield) and optimization (handled by the RL agent), it enables the deployment of learning systems in safety-critical environments. Future work will focus on automatically learning environment abstractions and extending the framework to handle liveness properties, ensuring agents not only stay safe but also eventually complete their tasks.
Summary updated