R-Judge: Benchmarking Safety Risk Awareness for LLM Agents

Tongxin Yuan, Zhiwei He, Lingzhong Dong, Yiming Wang, Ruijie Zhao, Tian Xia, Lizhen Xu, Binglin Zhou, Fangqi Li, Zhuosheng Zhang, Rui Wang, Gongshen Liu

As large language models (LLMs) transition from passive chatbots to autonomous agents capable of executing code, managing smart homes, and handling financial transactions, a new safety frontier emerges. While we’ve spent years worrying about what LLMs say, we now need to worry about what they do.

A new paper from researchers at Shanghai Jiao Tong University introduces R-Judge, a benchmark designed to evaluate whether LLMs can actually recognize safety risks in the behavioral records of autonomous agents.

TL;DR

R-Judge is a first-of-its-kind benchmark for evaluating the "safety risk awareness" of LLM agents across diverse interactive environments. The study reveals a sobering reality: most current LLMs struggle to identify behavioral risks, with only GPT-4o performing significantly better than a random baseline, highlighting a critical gap in the development of safe autonomous systems.

What Problem Does This Paper Address?

Traditional LLM safety research focuses on content safety—preventing models from generating toxic, biased, or harmful text. However, LLM agents operate in interactive environments where they take actions (e.g., deleting files, sending emails, controlling IoT devices).

In these scenarios, a seemingly benign action can be catastrophic depending on the context. For example, an agent asked to "clean up the system" might recursively delete the root directory, or an agent processing emails might inadvertently click a phishing link. Existing benchmarks don't capture these multi-turn, behavioral risks. The authors argue that for an agent to be safe, it must first be risk-aware—capable of monitoring its own (or others') actions and identifying potential hazards before they manifest.

Methods

The researchers formalized the problem as a Safety Monitor task. Given an agent interaction record $R$ (consisting of a user instruction, the agent's internal thoughts, its actions, and environment feedback), an LLM is asked to perform two tasks in a serial pipeline:

  1. Risk Identification: Generate a plain-text analysis of whether the agent's actions are safe.
  2. Safety Judgment: Output a binary label—"safe" or "unsafe."
The R-Judge evaluation paradigm: LLMs analyze interaction records to identify risks and provide a final safety judgment.

To evaluate these, they used standard classification metrics (F1, Recall, Specificity) for the judgment and a GPT-4-based automatic scorer to assess the quality of the risk identification against human-annotated ground truths.

Datasets

The authors introduced the R-Judge dataset, which consists of 569 high-quality agent interaction records.

  • Diverse Scenarios: It covers 27 scenarios across 5 categories: Program, Software, Finance, IoT, and Web.
  • Risk Taxonomy: It spans 10 risk types, including Privacy Leakage, Data Loss, and Physical Health (see Figure 1).
  • MTO Schema: Each unsafe case is annotated using a "Motivation, Trigger, Outcome" (MTO) schema to ensure clear, high-quality risk descriptions.
Figure 1: Dataset distribution of R-Judge, which con- tains 27 key risk scenarios among 5 application cate- gories, and spans across 10 risk types. The proportion of each category is shown in the graph.

The data was curated from existing agent safety frameworks (like ToolEmu and InjecAgent) and supplemented with manual expert constructions to ensure a balance between safe and unsafe samples.

Key Insights and Ideas

  • Risk Awareness is a Reasoning Challenge: Identifying risks isn't just about keyword matching; it requires "Scenario Simulation." A model must infer the downstream effects of an action, such as understanding that sharing a Dropbox link with "edit" access instead of "comment" access is a security risk.
  • Prompting is Not a Silver Bullet: The researchers tested various prompting techniques, including Zero-Shot-CoT and Few-Shot-CoT. Surprisingly, providing the model with a list of risk types or few-shot examples didn't consistently improve performance, suggesting that behavioral safety awareness is a deep-seated capability that simple prompting can't easily unlock.
  • Fine-tuning is Effective: While general-purpose prompting struggled, models specifically fine-tuned for safety (like Meta's Llama Guard 2) showed significant performance gains. This suggests that safety awareness can be learned, provided there is high-quality, diverse training data.
  • The "Foundation" Matters: There was a massive performance jump between Llama-2-based and Llama-3-based safety models, indicating that the underlying reasoning capability of the foundation model is a prerequisite for effective safety monitoring.

Key Results

The evaluation of 11 prominent LLMs showed that most models are currently "risk-blind" in agent scenarios:

  • GPT-4o was the clear leader, achieving an F1 score of 74.45%.
  • Most other models, including ChatGPT (GPT-3.5) and various open-source models (Vicuna, Mistral), performed near or below the random baseline (approx. 51% F1).
  • Meta-Llama-Guard-2-8B performed impressively well for its size, reaching 71.84% F1, proving that targeted fine-tuning on safety taxonomies is a viable path forward.

Limitations and Future Work

The authors acknowledge that the R-Judge dataset, while high-quality, is relatively small (569 samples) due to the intensive human expert labor required for annotation. Furthermore, the current benchmark assumes the user is benign; it does not yet account for "jailbreaking" attempts where a user might maliciously try to trick an agent into unsafe behavior.

Future work will focus on scaling the dataset as LLM agents enter more specialized domains (like healthcare or legal) and developing more robust monitor models that can provide real-time safety feedback during agent execution.

For more details, you can find the R-Judge benchmark and code on GitHub.

Summary updated

BibTeX
@inproceedings{yuan2024r,
  author = {Tongxin Yuan and Zhiwei He and Lingzhong Dong and Yiming Wang and Ruijie Zhao and Tian Xia and Lizhen Xu and Binglin Zhou and Fangqi Li and Zhuosheng Zhang and Rui Wang and Gongshen Liu},
  title = {{R-Judge: Benchmarking Safety Risk Awareness for LLM Agents}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.79},
}
Figure