Assessing AI Detectors in Identifying AI-Generated Code: Implications for Education

Wei Hung Pan, Ming Jie Chok, Jonathan Leong Shan Wong, Yung Xin Shin, Yeong Shian Poon, Zhou Yang, Chun Yong Chong, David Lo, Mei Kuan Lim

Abstract

Educators are increasingly concerned about the usage of Large Language Models (LLMs) such as ChatGPT in programming education, particularly regarding the potential exploitation of imperfections in Artificial Intelligence Generated Content (AIGC) Detectors for academic misconduct. In this paper, we present an empirical study where the LLM is examined for its attempts to bypass detection by AIGC Detectors. This is achieved by generating code in response to a given question using different variants. We collected a dataset comprising 5,069 samples, with each sample consisting of a textual description of a coding problem and its corresponding human-written Python solution codes. These samples were obtained from various sources, including 80 from Quescol, 3,264 from Kaggle, and 1,725 from LeetCode. From the dataset, we created 13 sets of code problem variant prompts, which were used to instruct ChatGPT to generate the outputs. Subsequently, we assessed the performance of five AIGC detectors. Our results demonstrate that existing AIGC Detectors perform poorly in distinguishing between human-written code and AI-generated code.

Introduction

As Large Language Models (LLMs) like ChatGPT become ubiquitous, educators in Software Engineering (SE) and Computer Science (CS) face a dilemma: how do they ensure students are actually learning to code rather than just prompting an AI? While several Artificial Intelligence Generated Content (AIGC) detectors exist, most were trained on natural language (English prose). Programming code is a different beast entirely—it follows strict structural rules and lacks the linguistic "flow" or "perplexity" found in human writing. This paper investigates whether these off-the-shelf detectors can actually distinguish between a human-written Python script and one generated by an LLM, especially when students use clever prompting to bypass detection.

Methodology

The researchers developed a workflow called DynCodeMetrics to systematically evaluate five prominent AIGC detectors: GPTZero, Sapling, GPT-2 Detector, DetectGPT, and GLTR.

The DynCodeMetrics workflow for generating AIGC and evaluating detectors.

The core of their approach was the creation of 13 prompt variants. Instead of just asking ChatGPT for a solution, they simulated various student behaviors, such as:

  • Prompt Engineering: Asking the AI to "mimic a human response" or "remove all comments."
  • Code Obfuscation: Using scripts to automatically replace variable/function names with single letters or injecting "dead code" (useless snippets) to act as noise.
  • Structural Changes: Requesting "long method" vs. "short method" versions of the same logic.

The study utilized a dataset of 5,069 unique coding problems and their corresponding human-written Python solutions sourced from Kaggle, LeetCode, and Quescol. From this base, they generated 13 sets of AI-generated counterparts using ChatGPT, resulting in a massive evaluation pool of over 70,000 code samples.

Key Results and Insights

The study revealed significant weaknesses in current detection technologies when applied to source code.

The "Text-First" Bias and Performance Floor

Most detectors look for linguistic patterns like "burstiness" or "perplexity." Because code is naturally repetitive and structured, detectors often misclassify all code as human-written simply because it doesn't look like the "smooth" text typical of LLM prose. Both the GPT-2 Detector and GPTZero hovered around 0.5 accuracy, effectively performing at random chance.

Accuracy (ACC) across 13 different code-generation variants, showing performance near random chance.

Sensitivity to Obfuscation

Interestingly, some detectors like GLTR actually became more accurate when the code was "messier" (e.g., adding dead code or removing comments). This suggests these tools are sensitive to the distribution of tokens; when the code looks less like a "perfect" textbook example, the detector's statistical model reacts more strongly. GLTR showed the highest variance, with accuracy jumping from 0.48 to 0.76 depending on the prompt variant used.

Detector Biases

  • Defaulting to "Human": GPT-2 Detector and GPTZero showed a heavy bias toward labeling samples as "Human." While this prevents false accusations, it makes them nearly useless for catching AI usage.
  • DetectGPT's Struggle: This detector frequently misclassified human code as AI-generated, a "worst-case scenario" for educators.
  • Sapling's Edge: Sapling was the most consistent, often achieving accuracy scores above 0.6, though still far below the threshold required for high-stakes academic disciplinary actions.

Conclusion

The researchers conclude that existing AIGC detectors perform poorly in distinguishing human vs. AI code, and their inherent weaknesses make them easy to bypass with simple prompt tweaks. Future work should focus on developing specialized, code-centric detectors that understand Abstract Syntax Tree (AST) structures rather than just treating code as text. In the meantime, educators should focus on "AI-resilient" assessment designs—like oral exams or in-class coding—rather than relying on flawed automated detection tools.

Summary updated

Abstract

Educators are increasingly concerned about the usage of Large Language Models (LLMs) such as ChatGPT in programming education, particularly regarding the potential exploitation of imperfections in Artificial Intelligence Generated Content (AIGC) Detectors for academic misconduct. In this paper, we present an empirical study where the LLM is examined for its attempts to bypass detection by AIGC Detectors. This is achieved by generating code in response to a given question using different variants. We collected a dataset comprising 5,069 samples, with each sample consisting of a textual description of a coding problem and its corresponding human-written Python solution codes. These samples were obtained from various sources, including 80 from Quescol, 3,264 from Kaggle, and 1,725 from LeetCode. From the dataset, we created 13 sets of code problem variant prompts, which were used to instruct ChatGPT to generate the outputs. Subsequently, we assessed the performance of five AIGC detectors. Our results demonstrate that existing AIGC Detectors perform poorly in distinguishing between human-written code and AI-generated code.
BibTeX
@inproceedings{pan2024assessing,
  author = {Wei Hung Pan and Ming Jie Chok and Jonathan Leong Shan Wong and Yung Xin Shin and Yeong Shian Poon and Zhou Yang and Chun Yong Chong and David Lo and Mei Kuan Lim},
  title = {{Assessing AI Detectors in Identifying AI-Generated Code: Implications for Education}},
  booktitle = {SEET@ICSE},
  year = {2024},
  doi = {10.1145/3639474.3640068},
}
Figure