Share your thoughts, 1 month free Claude Pro on usSee more
WorkDL logo mark

LLM-Enhanced Hierarchical Heterogeneous Graph Representation Learning for Malicious Python Package Detection

About

Malicious Python packages have become a major threat to software supply chain ecosystems due to the widespread adoption of open-source repositories such as PyPI. Existing learning-based detection methods struggle to capture the hierarchical organization and heterogeneous interactions among different program entities. Although Large Language Models (LLMs) have demonstrated strong capabilities in code understanding and semantic reasoning, they are rarely integrated with structural program representations for fine-grained malicious behavior analysis. In this paper, we propose an LLM-enhanced hierarchical heterogeneous graph representation learning framework for malicious Python package detection. The framework constructs a hierarchical heterogeneous code graph that explicitly models heterogeneous code entities and different types of structural dependencies. LLMs are further leveraged to infer function-level semantic roles, introducing an additional layer of semantic heterogeneity. Based on this graph, we develop a hierarchical heterogeneous graph neural network that performs type-aware message passing over different node and edge categories, effectively modeling malicious behavior propagation for accurate package-level classification. The framework also incorporates a function-level attribution mechanism which, combined with LLM reasoning, automatically identifies suspicious functions and localizes fine-grained malicious behaviors without human expert intervention. Extensive experiments on real-world datasets show that our framework consistently outperforms traditional machine learning methods, graph-based detectors, and state-of-the-art LLMs across packages with varying sizes and dependency complexities, while providing accurate, robust, and interpretable malicious behavior localization.

Hang Gao, Xiaoyu Chen, Baoquan Cui, Zhen Tang, Peng Qiao, Fengge Wu, Jian Zhang• 2026

Related benchmarks

TaskDatasetResultRank
Malicious Package DetectionPyPI Malicious Package Dataset All Packages Combined (test)
Accuracy97.08
24
Malicious Package DetectionPyPI Malicious Package Dataset Small Packages N = 972 (test)
Accuracy97.31
12
Malicious Package DetectionPyPI Malicious Package Dataset Large Packages N = 1162 (test)
Accuracy96.89
12
Malicious Package DetectionPyPI Minimal Imports (test)
Accuracy96.6
12
Malicious Package DetectionPyPI Extensive Imports (test)
Accuracy95
12
Malicious Package DetectionPyPI (Extremely Small ≤1.57KB)
Accuracy95.96
12
Malicious Package DetectionPyPI (Extremely Large ≥700KB)
Accuracy96.33
12
Malicious Python package detectionPyPI-based dataset Small Import Amounts, N=1647 (test)
Accuracy97.29
12
Malicious Python package detectionPyPI-based dataset Large Import Amount, N=487 (test)
Accuracy0.9584
12
Showing 9 of 9 rows

Other info

Follow for update