NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Do Androids Dream of Electric Fences? Safety-Aware Reinforcement Learning with Latent Shielding

Chloe He, Borja G. León, Francesco Belardinelli

Abstract

Reinforcement learning (RL) agents often encounter catastrophic failures during the learning process, limiting their applicability in safety-critical real-world domains. Traditional shielding techniques mitigate this by overriding unsafe actions based on formal environmental models, but these models are difficult to construct for high-dimensional or stochastic tasks. We propose latent shielding, a framework that learns a world model from experience to "imagine" potential futures and proactively block actions leading to safety violations. Our method, Approximate Bounded Prescience Shielding (ABPS), utilizes a Safety Recurrent State-Space Model (RSSM) and a novel Shield Introduction Schedule (SIS) to ensure safe exploration. Evaluated on visual and stochastic benchmarks, latent shielding achieves a seven-fold reduction in violations compared to unshielded agents and outperforms symbolic baselines in complex environments.

Introduction

Reinforcement learning is powerful but notoriously "crash-prone" during the learning phase. In real-world applications such as autonomous driving or robotic surgery, agents cannot afford to learn through catastrophic mistakes. A popular solution is shielding, where a monitor intercepts and overrides actions that violate safety specifications. However, traditional shielding requires a human-provided, symbolic model of environment dynamics, which is often impossible to create for pixel-based or highly stochastic tasks. This paper introduces a method for agents to learn their own internal safety abstractions, bridging the gap between high-dimensional inputs and formal safety requirements.

Methodology: Latent Shielding and ABPS

The proposed framework, Approximate Bounded Prescience Shielding (ABPS), integrates three core components to enable safety without handcrafted models:

  1. Safety RSSM (Recurrent State-Space Model): Building on the Dreamer architecture, a specialized "violation prediction" head is added to the agent's world model. This neural network learns to classify latent states as "safe" or "unsafe" based on historical experience.
  2. Latent Shielding: The shield uses the learned world model to simulate short-term trajectories into the future. If the probability of entering an unsafe state exceeds a threshold, the shield intervenes, forcing a safe alternative action.
  3. Shield Introduction Schedule (SIS): To prevent inaccurate early-stage models from stifling exploration, SIS gradually enables the shield only after the world model reaches a reliability threshold.
The Safety RSSM architecture integrates a violation prediction head into the latent state-space model.

Experimental Setup

The approach was evaluated on two distinct benchmarks:

  • Visual Grid World (VGW): A 64x64 pixel navigation task requiring the agent to reach a target while avoiding "lava" squares in both fixed and procedurally generated layouts.
  • Cliff Driver (CD): A symbolic task with continuous actions and stochastic dynamics (e.g., "stuck throttle" probability), where the agent must drive near a cliff edge without falling.

Results and Discussion

Key Insights

  • Learning the Abstraction: Agents can learn safety-relevant features directly from pixels, removing the need for manual definitions of "danger."
  • Probabilistic Safety: By estimating risk across multiple imagined futures, the stochastic world model is more robust to environmental noise than deterministic symbolic shields.
  • The Exploration-Safety Paradox: The Shield Introduction Schedule is critical; enabling the shield too early can trap the agent in local optima because it never learns the boundaries of the state space.

Performance Evaluation

Latent shielding demonstrated superior safety and efficiency across benchmarks. In the Visual Grid World, the latent shielded agent achieved a seven-fold reduction in test-time violations. Notably, in the stochastic Cliff Driver task, the latent shield actually outperformed Bounded Prescience Shielding (BPS)—which uses the true underlying simulator—suggesting that learned models can better capture complex, noisy dynamics than discretized symbolic ones.

Comparison of Reward and Violations across different shielding methods. Latent shielding (orange) maintains high reward while significantly reducing violations compared to unshielded agents.

Conclusion

Latent shielding provides a path toward safe RL in complex environments without requiring manual modeling. While it lacks the formal guarantees of symbolic shielding and requires at least one initial violation to learn "danger," it significantly reduces the real-world cost of training. Future work will explore more sophisticated shield schedules and the application of formal verification to learned latent representations.

Summary updated

BibTeX
@inproceedings{he2022do,
  author = {Chloe He and Borja G. León and Francesco Belardinelli},
  title = {{Do Androids Dream of Electric Fences? Safety-Aware Reinforcement Learning with Latent Shielding}},
  booktitle = {SafeAI @ AAAI},
  year = {2022},
  url = {https://openreview.net/forum?id=gKSo7WVe_7},
}
Figure