A Framework for Identifying, Categorizing, and Explaining Bias in AI-Generated Code
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.
Create a lesson
Metadata
- Categories
- cs.SE, cs.AI
- Comments
- Under Review at ACM TOSEM
Related papers
AI-Generated Code Issues: A Taxonomy from Repository Histories, AI Conversations, and Developer Interviews
Shared title terminologycs.SERosalia Tufano, Nargiz Humbatova, Daniele Bifolco et al.
Code That Works, Environments That Don't: Measuring Environment Reproducibility in AI-Generated Software
Shared title terminologycs.SEBhanu Prakash Vangala, Tanu Malik
RBioBench: an execution-based benchmark for biomedical R code generation
Shared title terminologycs.SEXihao Piao, Dong Wang, Ziwei Yang et al.
Escalate on Failure: A Single-Model Mode-Switching Cascade for Local Code Generation
Shared title terminologycs.SEBrian K. Hudes
Generating Property-Based Regression Tests from Source Code Semantics
Shared title terminologycs.SEClemens Bauer, Johann Glock, Martin Pinzger
Validating Multi-Model AI-Generated Acceptance Criteria in Requirements Engineering
Shared title terminologycs.SEMateen Ahmed Abbasi, Petri Ihantola, Tommi Mikkonen et al.