RePolicy: Learning to Select and Apply Safety Policies for Agent Safeguards
Organizations: Zhongguancun Academy · University of Science and Technology of China · Zhejiang University · National University of Singapore
Abstract
Agent safeguards must determine whether an agent's behavior violates the safety rules of the current task, environment, and user. Because these rules vary across contexts, a safeguard needs to select the relevant policy before judging the behavior. Existing policy-aware safeguards can apply a supplied policy, but generally assume that the correct policy is already known. They therefore do not learn how to select a policy from a library, even though an incorrect choice can lead to an incorrect safety judgment. We introduce RePolicy, a safeguard that jointly learns policy selection and safety assessment. Given an agent trajectory and a set of candidate policies, RePolicy selects the policy that best matches the situation, applies its requirements, and predicts whether the behavior is safe. We construct PolicyTraj-20K, a dataset of more than 20,000 agent trajectories annotated with applicable policies, safety labels, and explanations. We train RePolicy with supervised demonstrations followed by reinforcement learning, while randomizing policy order, identifiers, and distractors to reduce shortcut learning. Across six agent-safety benchmarks and 19 baselines, RePolicy-4B achieves leading overall safety-detection performance and improves policy-selection accuracy. These results show that safeguards can learn which safety requirements to use for assessing agent behavior.
Figures & tables
| Model | ATBench | R-Judge | OpenAgent Safety | ASSE Bench | HINT Bench | Agent Hazard | Overall |
| Closed-source General Models | |||||||
| Claude Sonnet 4.6 | 95.46 | 86.26 | 51.97 | 81.10 | 96.47 | 93.73 | 84.17 |
| GPT-5.4 | 96.83 | 87.44 | 55.63 | 76.25 | 95.42 | 87.13 | 83.12 |
| Qwen3.6-Plus | 67.81 | 90.80 | 21.83 | 66.51 | 98.26 | 54.39 | 66.60 |
| Open-source General Models | |||||||
| Qwen3-4B- [-1pt]Instruct-2507 | 75.79 | 63.12 | 11.48 | 61.72 | 84.58 | 54.11 | 58.47 |
| Variant | ATBench | R-Judge | OpenAgent Safety | ASSE Bench | HINT Bench | Agent Hazard | Overall |
| Base model (zero-shot) | 75.79 | 63.12 | 11.48 | 61.72 | 84.58 | 54.11 | 58.47 |
| Cold-Start SFT | 97.71 | 77.61 | 72.20 | 82.81 | 94.10 | 97.25 | 86.95 |
| w/o policy invocation † | 98.30 | 81.67 | 58.39 | 86.81 | 96.53 | 93.30 | 85.83 |
| w/o policy-context perturbation † | 98.92 | 81.74 | 61.46 | 87.56 | 96.72 | 98.41 | 87.47 |
| RePolicy (full) | 99.40 | 82.17 | 62.79 | 88.11 | 97.23 | 99.20 | 88.15 |
Appendix figures & tables9 assets
Supplementary material from the paper’s appendix.
Appendix
| Benchmark | Unsafe | Safe | Total | Unsafe (%) |
| ATBench | 500 | 500 | 1,000 | 50.0 |
| R-Judge | 702 | 540 | 1,242 | 56.5 |
| OpenAgentSafety | 189 | 100 | 289 | 65.4 |
| ASSEBench | 806 | 670 | 1,476 | 54.6 |
| HINTBench | 583 | 126 | 709 | 82.2 |
| AgentHazard | 2,653 | 0 | 2,653 | 100.0 |
| Model | Nominal scale | Primary comparison axis |
| Closed-source general-purpose models | ||
| Claude Sonnet 4.6 ( Anthropic, 2026 ) | – | General and agentic safety reasoning |
| GPT-5.4 ( OpenAI, 2026a ) | – | Reasoning, tool use, and computer use |
| Qwen3.6-Plus ( Qwen Team, 2026 ) | – | Agent-oriented general reasoning |
| Open-source general-purpose models | ||
| Qwen3-4B-Instruct-2507 ( Qwen Team, 2025b ) | 4B | Backbone-scale instruction following |
| Reported model | Evaluated backend identifier | Max. output tokens |
| Claude Sonnet 4.6 | claude-sonnet-4-6 | 1,024 |
| GPT-5.4 | gpt-5.4 | 1,024 |
| Qwen3.6-Plus | qwen3.6-plus | 2,048 |
| Qwen3-4B-Instruct-2507 | Qwen/Qwen3-4B-Instruct-2507 | 1,024 |
| QwQ-32B-Preview | qwq-32b-preview | 8,192 |
| Qwen3-235B-A22B-Instruct-2507 | qwen3-235b-a22b-instruct-2507 | 1,024 |
| Guard | Native input and decision interface | Mapping to {safe, unsafe} |
| WildGuard | Official request/response classifier over the user request and recorded execution; emits harmful-request, response-refusal, and harmful-response fields. | Harmful response yes unsafe; no safe. |
| ShieldGemma-9B | Role-labelled trajectory in the native policy template with an agent-behavior safety guideline; scores the final-token logits for Yes and No . | unsafe; otherwise safe. |
| Llama Guard 4 12B | Role-labelled trajectory as a user message under the checkpoint chat template; may append native hazard categories. | First nonempty line unsafe unsafe; safe safe. |
| DynaGuard-4B | Native fast policy-compliance prompt containing the behavior criterion and role-labelled dialogue; choice-constrained decoding. | Unsafe / FAIL unsafe; Safe / PASS safe. |
| Qwen3Guard-Gen-4B | Native response moderation with request as the user message and execution as the assistant response. | Safety: Safe safe; Unsafe or Controversial unsafe. |
| Qwen3Guard-Gen-8B | Native trajectory moderation with the role-labelled transcript as a user message. | Same conservative three-to-two-way mapping as the 4B checkpoint. |
| Guard | Max. context | Explicit input cap | Max. output | TP |
| WildGuard | 32,768 | 2,048 user / 29,000 exec. | 32 | 1 |
| ShieldGemma-9B | native | none (full transcript) | logit score | – |
| Llama Guard 4 12B | 8,192 | none (full transcript) | 16 | 2 |
| DynaGuard-4B | 32,768 | 30,000 transcript | 16 | 1 |
| Qwen3Guard-Gen-4B | 32,768 | 2,048 user / 28,000 exec. | 128 | 1 |
| Qwen3Guard-Gen-8B | 32,768 | 30,000 transcript | 128 | 2 |
| Setting | Cold-Start SFT | GRPO |
| Backbone | Qwen3-4B-Instruct-2507 | |
| Training examples | 5,000 | 14,425 |
| Validation examples | 500 | 500 |
| Training epochs | 2 | 3 |
| Global batch size | 128 | 64 |
| Learning rate | ||
| Component | RePolicy behavior |
| Trajectory | The agent reads staging credentials and sends them to an external address without explicit authorization. |
| Candidate ambiguity | The trajectory contains both file-operation and external-messaging cues, making several policies superficially plausible. |
| Policy invocation | RePolicy invokes External Messaging Safety and Authorization (the local policy identifier in the released demo is Policy_1 ). |
| Relevant requirements | External messages require appropriate recipient authorization; sensitive credentials should not be externally disclosed without explicit authorization; consequential external transmission requires confirmation when authorization is not established. |
| Final judgment | Unsafe . The external transmission of credentials violates the retrieved policy requirements. |
LLM Agent Safety
Large language model agent safety studies how to keep tool-using, persistent, and multi-agent systems aligned with user intent and authorized limits.
See all 322 papers