mlsanityData to 7 Oct 2026

Bias Testing and Mitigation in LLM-based Code Generation

arXiv 2309.14345 ↗First posted 3 Sep 2023cs.SE cs.AIcited by 53

Not on the map. Why?

Abstract (arXiv)

As the adoption of LLMs becomes more widespread in software coding ecosystems, a pressing issue has emerged: does the generated code contain social bias and unfairness, such as those related to age, gender, and race? This issue concerns the integrity, fairness, and ethical foundation of software applications that depend on the code generated by these models but are underexplored in the literature. This paper presents a novel bias testing framework that is specifically designed for code generation tasks. Based on this framework, we conduct an extensive empirical study on the biases in code generated by five widely studied LLMs (i.e., PALM-2-CodeChat-bison, Claude-instant-1, GPT-3.5-turbo, GPT-4-turbo, and GPT-4). Our findings reveal that biases are prevalent. For example, 13.47% to 49.10% of the codes generated by these LLMs have biased behaviors towards gender. Moreover, we study five bias mitigation prompt strategies that are commonly used in current code generation scenarios, i.e., zero-shot, one-shot, few-shot, and two Chain-of-Thought (CoT) prompts, with and without provided feedback-driven refinement. Our evaluation results illustrate that using direct prompt engineering strategies has limited effectiveness in mitigating bias, but our test execution feedback can help to reduce the ratio of code biases to a large extent (e.g., from 59.88% to 4.79% for GPT-4).

Key facts. Cited by 53 papers in the map (data through 7 Oct 2026). Builds on 92 of its 144 references that are in the map. First posted on arXiv 3 Sep 2023.

Builds on

92 of 144 references.

References · 92

  1. 2020Language Models are Few-Shot Learnerscited by 32,199
  2. 2023GPT-4 Technical Reportcited by 18,132
  3. 2022Training language models to follow instructions with human feedbackcited by 15,712
  4. 2019Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformercited by 14,491
  5. 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
  6. 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
  7. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  8. 2022Self-Consistency Improves Chain of Thought Reasoning in Language Modelscited by 5,601
  9. 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
  10. 2022Flamingo: a Visual Language Model for Few-Shot Learningcited by 4,337
  11. 2021Program Synthesis with Large Language Modelscited by 3,509
  12. 2023Code Llama: Open Foundation Models for Codecited by 2,105
38 more
  1. 2019A Survey on Bias and Fairness in Machine Learningcited by 1,911
  2. 2022Competition-Level Code Generation with AlphaCodecited by 1,427
  3. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
  4. 2023Gorilla: Large Language Model Connected with Massive APIscited by 1,302
  5. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  6. 2023Large Language Models are not Fair Evaluatorscited by 1,050
  7. 2022Atlas: Few-shot Learning with Retrieval Augmented Language Modelscited by 940
  8. 2020StereoSet: Measuring stereotypical bias in pretrained language modelscited by 911
  9. 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 890
  10. 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 876
  11. 2023StarCoder: may the source be with you!cited by 790
  12. 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 728
  13. 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
  14. 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 492
  15. 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 468
  16. 2021Retiring Adult: New Datasets for Fair Machine Learningcited by 443
  17. 2022DS-1000: A Natural and Reliable Benchmark for Data Science Code Generationcited by 442
  18. 2021Unified Pre-training for Program Understanding and Generationcited by 361
  19. 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
  20. 2023RepoBench: Benchmarking Repository-Level Code Auto-Completion Systemscited by 346
  21. 2023CodeT5+: Open Code Large Language Models for Code Understanding and Generationcited by 327
  22. 2020Unsupervised Translation of Programming Languagescited by 262
  23. 2023Large Language Model as Attributed Training Data Generator: A Tale of Diversity and Biascited by 230
  24. 2018A comparative study of fairness-enhancing interventions in machine learningcited by 208
  25. 2023SantaCoder: don't reach for the stars!cited by 169
  26. 2022Multi-lingual Evaluation of Code Generation Modelscited by 158
  27. 2021A survey on datasets for fairness-aware machine learningcited by 157
  28. 2023In-Context Impersonation Reveals Large Language Models' Strengths and Biasescited by 154
  29. 2021RedditBias: A Real-World Resource for Bias Evaluation and Debiasing of Conversational Language Modelscited by 149
  30. 2018The Frontiers of Fairness in Machine Learningcited by 139
  31. 2022Efficient Few-Shot Learning Without Promptscited by 135
  32. 2022Few-shot training LLMs for project-specific code-summarizationcited by 128
  33. 2022Text and Patterns: For Effective Chain of Thought, It Takes Two to Tangocited by 128
  34. 2022Bias Mitigation for Machine Learning Classifiers: A Comprehensive Surveycited by 125
  35. 2023CodeGen2: Lessons for Training LLMs on Programming and Natural Languagescited by 124
  36. 2022Large Language Models are Few-shot Testers: Exploring LLM-based General Bug Reproductioncited by 110
  37. 2022Repository-Level Prompt Generation for Large Language Models of Codecited by 106
  38. 2021Jigsaw: Large Language Models meet Program Synthesiscited by 103

50 most cited of 92 All 92 (JSON)

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2023: 1; 2024: 11; 2025: 24; 2026: 17.

53 papers.

Sort:

By area:

  1. 2024A Survey on Large Language Models for Code Generationcited by 646
  2. 2024ALERT: A Comprehensive Benchmark for Assessing Large Language Models' Safety through Red Teamingcited by 96
  3. 2025On the Use of Agentic Coding: An Empirical Study of Pull Requests on GitHubcited by 53
  4. 2024A Comprehensive Survey of Bias in LLMs: Current Landscape and Future Directionscited by 27
  5. 2024How (un)ethical are instruction-centric responses of LLMs? Unveiling the vulnerabilities of safety guardrails to harmful queriescited by 26
  6. 2025Large Language Models for Code Generation: A Comprehensive Survey of Challenges, Techniques, Evaluation, and Applicationscited by 26
  7. 2025A Survey of Personalization: From RAG to Agentcited by 26
  8. 2025AI Agentic Programming: A Survey of Techniques, Challenges, and Opportunitiescited by 26
  9. 2025EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Codecited by 24
  10. 2025A Study of LLMs' Preferences for Libraries and Programming Languagescited by 20
  11. 2024Few-Shot Fairness: Unveiling LLM's Potential for Fairness-Aware Classificationcited by 18
  12. 2024BiasDPO: Mitigating Bias in Language Models through Direct Preference Optimizationcited by 18
38 more
  1. 2025Afterburner: Reinforcement Learning Facilitates Self-Improving Code Efficiency Optimizationcited by 14
  2. 2025Profit Mirage: Revisiting Information Leakage in LLM-based Financial Agentscited by 13
  3. 2024Measuring the Influence of Incorrect Code on Test Generationcited by 9
  4. 2024Risks, Causes, and Mitigations of Widespread Deployments of Large Language Models (LLMs): A Surveycited by 8
  5. 2025Measuring Bias or Measuring the Task: Understanding the Brittle Nature of LLM Gender Biasescited by 8
  6. 2024A Survey on Human-AI Collaboration with Large Foundation Modelscited by 7
  7. 2025BiasFilter: An Inference-Time Debiasing Framework for Large Language Modelscited by 6
  8. 2025Towards Advancing Code Generation with Large Language Models: A Research Roadmapcited by 5
  9. 2026Reward Modeling for Reinforcement Learning-Based LLM Reasoning: Design, Challenges, and Evaluationcited by 5
  10. 2023Survey on AI Ethics: A Socio-technical Perspectivecited by 4
  11. 2025The Future of Generative AI in Software Engineering: A Vision from Industry and Academia in the European GENIUS Projectcited by 4
  12. 2025Bias after Prompting: Persistent Discrimination in Large Language Modelscited by 3
  13. 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistantscited by 3
  14. 2026A Spatio-Temporal Expert Prefetching Framework for Efficient MoE-based LLM Inferencecited by 3
  15. 2024STOP! Benchmarking Large Language Models with Sensitivity Testing on Offensive Progressionscited by 2
  16. 2025On the Reasoning Capacity of AI Models and How to Quantify Itcited by 2
  17. 2025LFTF: Locating First and Then Fine-Tuning for Mitigating Gender Bias in Large Language Modelscited by 2
  18. 2025Revisiting Disaggregated Large Language Model Serving for Performance and Energy Implicationscited by 2
  19. 2026CAGE: A Framework for Culturally Adaptive Red-Teaming Benchmark Generationcited by 2
  20. 2024White Men Lead, Black Women Help? Benchmarking and Mitigating Language Agency Social Biases in LLMscited by 1
  21. 2025Uncovering Intention through LLM-Driven Code Snippet Description Generationcited by 1
  22. 2025On LLM-Assisted Generation of Smart Contracts from Business Processescited by 1
  23. 2025LoRALib: A Standardized Benchmark for Evaluating LoRA-MoE Methodscited by 1
  24. 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AIcited by 1
  25. 2025Is Lying Only Sinful in Islam? Exploring Religious Bias in Multilingual Large Language Models Across Major Religionscited by 1
  26. 2026Controlling Distributional Bias in Multi-Round LLM Generation via KL-Optimized Fine-Tuningcited by 1
  27. 2026Social Bias in LLM-Generated Code: Benchmark and Mitigationcited by 1
  28. 2026Automated Summarization of Software Documents: An LLM-based Multi-Agent Approachcited by 1
  29. 2025SMITE: Enhancing Fairness in LLMs through Optimal In-Context Example Selection via Dynamic Validationcited by 0
  30. 2025Designing Empirical Studies on LLM-Based Code Generation: Towards a Reference Frameworkcited by 0
  31. 2025Bias Testing and Mitigation in Black Box LLMs using Metamorphic Relationscited by 0
  32. 2026LLM Security and Safety: Insights from Homotopy-Inspired Prompt Obfuscationcited by 0
  33. 2026BenchBrowser: Retrieving Evidence for Evaluating Benchmark Validitycited by 0
  34. 2026Fairness in Multi-Agent Systems for Software Engineering: An SDLC-Oriented Rapid Reviewcited by 0
  35. 2026From If-Statements to ML Pipelines: Revisiting Bias in Code-Generationcited by 0
  36. 2026Pattern over Pixels: Measuring Pattern Completion Bias in Multimodal Code Generationcited by 0
  37. 2026COMPAS: Difficulty-Aware Joint Search for Optimizing Code Generationcited by 0
  38. 2026LangChoiceBench: Measuring and Explaining Programming-Language Choice in LLMscited by 0

50 most cited of 53 All 53 (JSON)

Similar, not cited

Close in wording, no citation either way

  1. 2024Bias Unveiled: Investigating Social Bias in LLM-Generated Code
  2. 2026How Reasoning Shapes Social Bias in LLM-Generated Code?
  3. 2026Measuring and Mitigating Bias in Code Generated by Large Language Models
  4. 2025FairCoder: Probing LLM Bias in High-Stakes Decision Making via Coding Tasks
  5. 2026On the risk of coding before testing: An empirical study on LLM-based test generation workflow
  6. 2025GenderBench: Evaluation Suite for Gender Biases in LLMs
  7. 2024With a Grain of SALT: Are LLMs Fair Across Social Dimensions?
  8. 2026Bias in the Loop: Auditing LLM-as-a-Judge for Software Engineering