A Framework for Identifying, Categorizing, and Explaining Bias in AI-Generated Code

📅 2026-09-24
📈 Citations: 0
✨ Influential: 0
📄 PDF
🤖 AI Summary
This study addresses the challenge of effectively identifying, categorizing, and explaining systematic biases in code generated by large language models (LLMs). To this end, it proposes the first systematic framework for bias classification and explanation, alongside a manually annotated benchmark dataset. By leveraging in-context learning (ICL), structured similarity metrics, and multi-model comparative evaluation, the work systematically validates the effectiveness of LLMs as automated bias auditing tools. The proposed approach enables efficient detection and attribution analysis of code biases. Experimental results demonstrate that Gemini achieves a detection accuracy of 80.14%, while the open-source Qwen3 attains 82.45%. Furthermore, both explanation quality and code localization similarity exceed 80%, closely aligning with expert judgments. These findings confirm the substantial potential of LLMs for automated code bias auditing.
📝 Abstract
As Large Language Models (LLMs) become integrated into software development workflows, concerns regarding unintentional biases in AI-generated code. Although evidence suggests these biases exist, limited research has systematically identified, categorized, and explained them. This study investigates bias in AI-generated code and evaluates whether LLMs can reliably identify and explain it through a taxonomy-driven framework. We extended an existing dataset of biased AI-generated Python code and manually annotated snippets with bias categories and human-authored justifications to establish a ground-truth dataset. Using this dataset, we evaluated proprietary and open-source LLMs as automated bias detection and justification systems through ICL. Finally, we analyzed similarity between LLM-generated explanations and human-authored justifications using structured justification and code identification metrics. Our findings demonstrate that LLMs can effectively support code bias identification and explanation. Gemini achieved 80.14% classification accuracy, with 84.0% precision and 95.7% recall, while the best open-source alternative, Qwen3-coder, achieved 82.45% accuracy, 68.64% precision, and 80.22% recall. Additionally, the models achieved justification similarity scores of 80.4% and 80.14%, respectively, relative to human-authored reasoning, and code identification similarity scores of 86.0% and 87.82%. These results suggest that LLMs can detect biased logic in generated Python code and produce explanations that substantially align with expert interpretations.
Problem

Research questions and friction points this paper is trying to address.

AI-generated code
bias
Large Language Models
code bias detection
taxonomy
Innovation

Methods, ideas, or system contributions that make the work stand out.

Bias Detection
Taxonomy-driven Framework
In-Context Learning
AI-Generated Code
Large Language Models
🔎 Similar Papers
2023-09-03ACM Transactions on Software Engineering and MethodologyCitations: 17
💼 Related Jobs
No related jobs found.
M
Manaal Basha
University of British Columbia, Kelowna, Canada
A
Aimee M. Ribeiro
Federal University of Pará, Brazil
Gema Rodríguez-Pérez
Gema Rodríguez-Pérez
Assistant Professor, University of British Columbia (Okanagan)
Empirical StudiesMining software repositoryCode reviewBug-Introducing Changeshuman aspects in SE