SafeHarbor: Defining Precise Decision Boundaries via Hierarchical Memory-Augmented Guardrail for LLM Agent Safety

Zhe Liu, Zonghao Ying †, Wenxin Zhang, Quanchen Zou, Deyue Zhang, Dongdong Yang, Xiangzheng Zhang, Hao Peng · 2026

Read SafeHarbor: Defining Precise Decision Boundaries via Hierarchical Memory-Augmented Guardrail for LLM Agent Safety by Zhe Liu, Zonghao Ying †, Wenxin Zhang, Quanchen Zou, Deyue Zhang, Dongdong Yang, Xiangzheng Zhang, Hao Peng (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2605-05704.txt.

Introduction

An AI agent with tools can be manipulated into harmful actions, but blanket refusal rules also block harmless requests. Zhe Liu and seven co-authors propose SafeHarbor, a guardrail that draws precise decision boundaries instead. Static guidelines cannot adapt to context, so their system builds rules from experience.

A hierarchical memory stores past cases, and enhanced adversarial generation produces training confrontations that sharpen the boundary. New requests are judged against remembered near-misses, not just fixed policy text. The goal is an agent that refuses what is genuinely dangerous while staying useful for everything else.

Catalog record

CREATORZhe Liu, Zonghao Ying †, Wenxin Zhang, Quanchen Zou, Deyue Zhang, Dongdong Yang, Xiangzheng Zhang, Hao Peng
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE68 KB
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2605.05704

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

SafeHarbor: Defining Precise Decision Boundaries via Hierarchical Memory-Augmented Guardrail for LLM Agent Safety Zhe Liu, Zonghao Ying †, Wenxin Zhang, Quanchen Zou, Deyue Zhang, Dongdong Yang, Xiangzheng Zhang, Hao Peng Abstract Recent advances in foundation models have transformed LLMs from passive conversational systems into autonomous agents capable of reasoning and tool execution. While these capabilities unlock substantial practical value, they also introduce new security risks, as adversaries can manipulate agents into performing harmful actions in real-world environments. Existing defense strategies mitigate such threats but frequently struggle to balance safety and utility, resulting in over-refusal of benign user requests. To mitigate this trade-off, we propose SafeHarbor , a novel framework designed to establish precise decision boundaries for LLM agents. Unlike static guidelines, SafeHarbor extracts context-aware defense rules through enhanced adversarial generation. We design a local hierarchical memory system for dynamic rule injection, offering a training-free, efficient, and plug-and-play solution. Furthermore, we introduce an information entropy-based self-evolution mechanism that continuously optimizes the memory structure through dynamic node splitting and merging. Extensive experiments demonstrate that SafeHarbor achieves state-of-the-art performance on both ambiguous benign tasks and explicit malicious attacks, notably attaining a peak benign utility of 63.6% on GPT-4o while maintaining a robust refusal rate exceeding 93% against harmful requests. The source code is publicly available at https://github.com/ljj-cyber/SafeHarbor . † † affiliationnotice: \dagger denotes the corresponding author. 1 Introduction The landscape of LLMs has evolved significantly, shifting from passive conversational chatbots to autonomous agents capable of active tool utilization and complex reasoning ( 25 ; 16 ) . By integrating with external APIs and execution environments, these agents are revolutionizing human-computer interaction across diverse domains. Prominent examples include web agents ( 5 ; 30 ) , embodied agents ( 7 ; 5 ) , and code agents ( 24 ) . This transition endows LLMs with hands, enabling them to translate textual instructions into executable actions. However, this enhanced agency introduces severe security vulnerabilities. While early adversarial attacks on LLMs, such as jailbreaking ( 2 ) and prompt injection ( 19 ) , primarily focused on eliciting toxic or biased text generation, the threat surface for agents has expanded to actionable harm. Malicious users can now exploit these vulnerabilities to induce agents into executing dangerous operations, such as unauthorized file deletion, privilege escalation, or disseminating phishing emails via automated tools ( 8 ; 15 ) . Unlike text generation, where the harm is informational, agent-based attacks ( 22 ) can cause irreversible consequences in the real-world digital environment. Figure 1: Comparison between (a) Traditional coarse-grained guardrails and (b) Our precise, rule-based SafeHarbor framework. Most current defense strategies rely on integrating specialized auxiliary agents for runtime monitoring ( 12 ; 4 ; 21 ) or fine-tuning safety models to enforce alignment ( 1 ; 26 ) . However, these approaches typically necessitate either extensive model retraining or the deployment of resource-intensive proxies, leading to substantial latency. More critically, despite their advancements, they fundamentally suffer from boundary ambiguity. Most current defenses operate as static, approximate linear classifiers, enforcing fixed safety margins that fail to adapt to context nuances. Consequently, these coarse-grained mechanisms struggle to delineate the precise decision boundary between benign and malicious intents, often leading to severe over-refusal in ambiguous scenarios. As illustrated in Figure 1 , static guardrails essentially draw a rigid line that indiscriminately blocks legitimate complex workflows. In contrast, our approach establishes a clear, adaptive boundary by leveraging retrieval-augmented dynamic rules. Instead of relying on a pre-computed global margin, we dynamically reconstruct the safety boundary for each query, allowing for precise differentiation even in edge cases. Crucially, this adaptation is performed in real-time without the prohibitive costs of heavy LLM deployment. By efficiently leveraging the intrinsic representations of the base LLM, our framework achieves precise decision-making with minimal computational overhead, avoiding the latency bottlenecks typical of external safety agents. To achieve the optimal balance between safety robustness and inference efficiency, we propose SafeHarbor . This framework transforms the abstract concept of an adaptive boundary into a concrete, real-time defense pipeline. The process initiates with an automated adversarial rule generator, which leverages attack enhancement to synthesize a diverse spectrum of safety policies. Crucially, this mechanism maximizes the information entropy of the injected rules, ensuring that the constructed memory captures a rich variety of latent vulnerabilities rather than redundant patterns. These policies are subsequently systematically organized within a dynamic hierarchical memory. Unlike static storage, this module employs a self-organizing mechanism to ensure that rule retrieval remains scalable and efficient as the knowledge base grows. Building upon this consolidated structure, a contrastive safety projector drives the online inference. It employs a strategic fast path to instantly validate clearly benign queries, while reserving granular dual-score analysis for ambiguous contexts, thus ensuring precision without compromising speed. Our contributions are summarized as follows: • We introduce an automated adversarial rule generation framework that synthesizes robust safety rules by applying adversarial enhancement to harmful trajectories and utilizing a rule generator within an adaptive clustering process. • We design a projection mechanism based on contrastive learning that mitigates over-refusal by jointly assessing the semantic and contextual risks of tool invocations. • We implement a self-organizing hierarchical memory featuring adaptive leaf splitting, which enables scalable rule management and high-speed retrieval without model retraining. • We demonstrate that SafeHarbor achieves state-of-the-art performance, attaining a peak benign utility of 63.6% on GPT-4o while maintaining a harmful refusal rate exceeding 93%. 2 Related Work 2.1 LLM Agent Safety Current safety strategies primarily diverge into intrinsic alignment and external guardrails. AgentAlign ( 26 ) enhances intrinsic safety via supervised fine-tuning on synthetic datasets, though this post-training approach incurs high retraining costs. In contrast, external guardrails often monitor interactions without altering the base model. While Llama-Guard-3 ( 1 ) classifies content safety, it lacks agency in tool execution. To address the limitations of static classifiers, advanced frameworks have adopted dynamic validation strategies. GuardAgent ( 21 ) functions by translating natural language safety constraints into executable logic. Specifically, it analyzes the guard requests to formulate a precise task plan, which is then compiled into guardrail code and executed to enforce deterministic safety boundaries. ShieldAgent ( 4 ) utilizes retrieval-based verification but incurs prohibitive latency via real-time code execution. Moreover, its reliance on historical workflows introduces maintenance instability, risking the conflation of robust generalization with the mere memorization of patterns. Ultimately, these heavy-weight mechanisms prioritize execution rigor over boundary clarity, incurring severe latency penalties due to mandatory code generation. In contrast, our framework establishes a clear and adaptive safety boundary through lightweight embedding projection. Figure 2: The proposed SafeHarbor framework. The workflow operates in three coordinated stages: (I) adversarial rule generation, which constructs dynamic clusters of safety rules; (II) dual knowledge storage, which organizes rules and synthesized exemptions into a memory tree while training a safety projector; and (III) scoring & retrieval, which employs a gating mechanism to route queries between a fast path and rigorous LLM judgment. 2.2 LLM Memory Mechanisms Memory mechanisms are fundamental for enabling agents to handle long-horizon tasks, typically prioritizing capacity expansion and structural organization ( 27 ) . Recent advancements have largely focused on time-aware architectures, such as ( 29 ; 13 ; 11 ) , to track temporal dynamics. To further

Read the complete text