Sistemasi: Jurnal Sistem Informasi
Vol 15, No 11 (2026): Sistemasi: Jurnal Sistem Informasi

AI-Based Detection of Hallucinated and Vulnerable Code Generated by LLMs

Shayma Mustafa Mohi-Aldeen (University of Mosul -College of Computer Sciences and Mathematics- Computer Science Department)



Article Info

Publish Date
21 Nov 2026

Abstract

The adoption of Large Language Models (LLMs) for code generation has grown, but there are two risks associated with the outputs of these models: code hallucination, which occurs when a model generates code for packages, modules, methods, or attributes that do not exist, and insecure code generation, which happens when a model produces insecure programming practices. This study introduces a lightweight, dependency-free desktop application named LLM Code Auditor to detect hallucinated software references and security vulnerabilities within the generated Python code by LLMs. It takes into account code written with LLM-based coding assistants, such as ChatGPT, Claude, and GitHub Copilot. A set of five representative Python code snippets were gathered for authentication, data retrieval operations, loading of configuration files, backup operations, and utility functions. The prompts were crafted to match realistic programming tasks and include references to API usage, dependency, and security-sensitive operations related to these application scenarios. A set of collected samples has been assessed with two complementary validation mechanisms. A first application of runtime introspection was used to check whether modules are imported or attributes are referenced in the target python environment. Second, a source code parser to find insecure constructs was used to create an AST (Abstract Syntax Tree) which was then passed to a rule analyzer that mapped the found vulnerabilities to Common Weakness Enumeration (CWE) identifiers and the severity level. The evaluation used quantitative measures such as the number and distribution of the vulnerabilities detected, the hallucination findings, CWE classification, level of confidence and a composite risk score, ranging from 0 to 100. The experimental findings were shown to be able to detect 14 vulnerability findings in 5 categories of CWE and 2 hallucination findings: One Nonexistent Package and One Unsupported Method. The mean risk score for the five samples was 54.4. The results show that runtime verification and explainable static analysis are a useful tool to investigate the reliability and security issues within LLM-generated Python code prior to deployment, and that they are complementary.

Copyrights © 2026






Journal Info

Abbrev

stmsi

Publisher

Subject

Computer Science & IT Electrical & Electronics Engineering

Description

Sistemasi adalah nama terbitan jurnal ilmiah dalam bidang ilmu sains komputer program studi Sistem Informasi Universitas Islam Indragiri, Tembilahan Riau. Jurnal Sistemasi Terbit 3x setahun yaitu bulan Januari, Mei dan September,Focus dan Scope Umum dari Sistemasi yaitu Bidang Sistem Informasi, ...