# Latent Q-Barrier Shielding for Safe In-Context Reinforcement Learning

*Minjae Kwon, Amir Moeini, Shangtong Zhang, Lu Feng*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/150569) · [Open on the map](../papers.html#p150569)

Category: [Reinforcement Learning & Games](../pcat/10.md) › [Safe Offline Reinforcement Learning](../pgroup/463.md) · Type: new method · Keywords: safe in-context reinforcement learning, latent Q-Barrier shield, action filtering, safety budget, context representation

Areas: [RL for LLMs & Agents](../areas/llm-rl.md) › Language Model Reinforcement Learning › Safe Offline Reinforcement Learning

## Summary
The paper introduces a latent Q-Barrier shield that learns context representations and cost predictions to safely filter actions in in-context reinforcement learning without test-time parameter updates.

## Explained to a 5-year-old
A robot learns to do things by watching past experiences without changing its brain. It has a safety budget that limits how much risk it can take. A special shield looks at the past and decides which actions are safe, blocking risky ones. This helps the robot get more rewards while staying safe, even in new situations. The shield works without needing to retrain the robot each time.

## Explained to a 5-year-old, longer
Imagine a robot that wants to learn how to do tasks by reading the stories of its past actions. It also has a safety budget that limits how much risk it can afford in each step. To stay safe, the robot uses a shield that looks at the past stories and decides which actions are safe. If an action might use too much of the safety budget, the shield can block it or make it softer. This way the robot can try many actions without actually changing its main learning part. The shield learns how the world works by predicting future costs from the past. It also learns to understand the context of the current situation from the history. When the robot sees a new situation it has never seen before, the shield still helps it stay safe. The robot can get more rewards because it can try good actions while avoiding dangerous ones. The shield works like a guard that watches over the robot's choices and protects it. This method lets the robot adapt to new environments without needing to retrain its whole model. As a result, the robot can be both smarter and safer in real-world tasks.

## For a technical reader
The paper addresses safe in-context reinforcement learning by introducing a shield that filters actions based on a learned cost model without updating model parameters at test time. It learns a context encoder, latent dynamics, and an ensemble cost critic during pretraining, enabling the shield to infer the current situation from interaction history. At deployment, the shield uses the remaining safety budget and predicted future costs to either block or down-weight risky actions, providing a provable bound on safety under prediction errors. Empirical evaluation on five safe ICRL benchmarks shows improved reward-safety trade-offs, achieving higher returns in most tasks while keeping episode costs at or below baseline levels. The approach offers a practical way to deploy adaptive RL agents in safety-critical domains where retraining on the fly is infeasible.

## Problem
Safe in-context reinforcement learning must control episode cost under a safety budget while adapting online from interaction history, but existing methods struggle with out-of-distribution shifts because they lack explicit action-level safety checks. This creates a trade-off between reward and safety when the remaining budget only influences frozen policy conditioning.

## Method
The approach learns a context representation, latent dynamics, and an ensemble cost critic during pretraining. At deployment, a shield infers context from history and filters or softly reweights candidate actions using the remaining safety budget and predicted future cost, without updating model parameters.

## Results
The approach achieves higher return in four of five benchmarks while matching or reducing average episode cost across all five, improving reward-safety tradeoffs over a strong baseline.

## Contributions
It introduces a latent shield that provides explicit action-level safety filtering using learned context and cost predictions, and provides a theoretical guarantee that actions satisfying the safety condition leave the latent budget state approximately safe under the learned critic, up to prediction errors. The work also demonstrates consistent improvements on multiple safe ICRL benchmarks.

## Research questions this paper is counted under

- [How can reinforcement learning agents learn policies that guarantee hard safety constraints while achieving optimal performance under uncertainty?](../q/44.md)

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/150569)
