Context-Aware Hierarchical Learning: A Two-Step Paradigm towards Safer LLMs

Tengyun Ma, Jiaqi Yao, Daojing He, Shihao Peng, Yu Li +2 more
12/3/2025
cs.CRcs.AI

Official code: S2AILab/CAHL (0 stars, last commit 2026-03-17).

Abstract

Large Language Models (LLMs) have emerged as powerful tools for diverse applications. However, their uniform token processing paradigm introduces critical vulnerabilities in instruction handling, particularly when exposed to adversarial scenarios. In this work, we identify and propose a novel class of vulnerabilities, termed Tool-Completion Attack (TCA), which exploits function-calling mechanisms to subvert model behavior. To evaluate LLM robustness against such threats, we introduce the Tool-Completion benchmark, a comprehensive security assessment framework, which reveals that even state-of-the-art models remain susceptible to TCA, with surprisingly high attack success rates. To address these vulnerabilities, we introduce Context-Aware Hierarchical Learning (CAHL), a sophisticated mechanism that dynamically balances semantic comprehension with role-specific instruction constraints. CAHL leverages the contextual correlations between different instruction segments to establish a robust, context-aware instruction hierarchy. Extensive experiments demonstrate that CAHL significantly enhances LLM robustness against both conventional attacks and the proposed TCA, exhibiting strong generalization capabilities in zero-shot evaluations while still preserving model performance on generic tasks. Our code is available at https://github.com/S2AILab/CAHL.

View on arXivView PDF

Code Implementations(1)

S2AILab/CAHLOfficial100%
00Jinja, PythonFeb 27, 20267 months ago

Similar Papers

Cite this paper

@article{ma2025contextaware,
  title  = {Context-Aware Hierarchical Learning: A Two-Step Paradigm towards Safer LLMs},
  author = {Tengyun Ma and Jiaqi Yao and Daojing He and Shihao Peng and Yu Li and Shaohui Liu and Zhuotao Tian},
  year   = {2025},
  eprint = {2512.03720},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2512.03720v1},
  journal = {NEURIPS 2025 2025}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2512.03720.svg)](https://codeofpaper.com/paper/2512.03720)

Discussion