Bias Testing and Mitigation in LLM-based Code Generation
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
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2023GPT-4 Technical Reportcited by 18,132
- 2022Training language models to follow instructions with human feedbackcited by 15,712
- 2019Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformercited by 14,491
- 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 12,865
- 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2022Self-Consistency Improves Chain of Thought Reasoning in Language Modelscited by 5,601
- 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
- 2022Flamingo: a Visual Language Model for Few-Shot Learningcited by 4,337
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
38 more
- 2019A Survey on Bias and Fairness in Machine Learningcited by 1,911
- 2022Competition-Level Code Generation with AlphaCodecited by 1,427
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
- 2023Gorilla: Large Language Model Connected with Massive APIscited by 1,302
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2023Large Language Models are not Fair Evaluatorscited by 1,050
- 2022Atlas: Few-shot Learning with Retrieval Augmented Language Modelscited by 940
- 2020StereoSet: Measuring stereotypical bias in pretrained language modelscited by 911
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 890
- 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 876
- 2023StarCoder: may the source be with you!cited by 790
- 2023WizardCoder: Empowering Code Large Language Models with Evol-Instructcited by 728
- 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
- 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 492
- 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 468
- 2021Retiring Adult: New Datasets for Fair Machine Learningcited by 443
- 2022DS-1000: A Natural and Reliable Benchmark for Data Science Code Generationcited by 442
- 2021Unified Pre-training for Program Understanding and Generationcited by 361
- 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
- 2023RepoBench: Benchmarking Repository-Level Code Auto-Completion Systemscited by 346
- 2023CodeT5+: Open Code Large Language Models for Code Understanding and Generationcited by 327
- 2020Unsupervised Translation of Programming Languagescited by 262
- 2023Large Language Model as Attributed Training Data Generator: A Tale of Diversity and Biascited by 230
- 2018A comparative study of fairness-enhancing interventions in machine learningcited by 208
- 2023SantaCoder: don't reach for the stars!cited by 169
- 2022Multi-lingual Evaluation of Code Generation Modelscited by 158
- 2021A survey on datasets for fairness-aware machine learningcited by 157
- 2023In-Context Impersonation Reveals Large Language Models' Strengths and Biasescited by 154
- 2021RedditBias: A Real-World Resource for Bias Evaluation and Debiasing of Conversational Language Modelscited by 149
- 2018The Frontiers of Fairness in Machine Learningcited by 139
- 2022Efficient Few-Shot Learning Without Promptscited by 135
- 2022Few-shot training LLMs for project-specific code-summarizationcited by 128
- 2022Text and Patterns: For Effective Chain of Thought, It Takes Two to Tangocited by 128
- 2022Bias Mitigation for Machine Learning Classifiers: A Comprehensive Surveycited by 125
- 2023CodeGen2: Lessons for Training LLMs on Programming and Natural Languagescited by 124
- 2022Large Language Models are Few-shot Testers: Exploring LLM-based General Bug Reproductioncited by 110
- 2022Repository-Level Prompt Generation for Large Language Models of Codecited by 106
- 2021Jigsaw: Large Language Models meet Program Synthesiscited by 103
50 most cited of 92 All 92 (JSON)
Built on by
Citing papers per year: 2023: 1; 2024: 11; 2025: 24; 2026: 17.
53 papers.
Sort:
By area:
- 2024A Survey on Large Language Models for Code Generationcited by 646
- 2024ALERT: A Comprehensive Benchmark for Assessing Large Language Models' Safety through Red Teamingcited by 96
- 2025On the Use of Agentic Coding: An Empirical Study of Pull Requests on GitHubcited by 53
- 2024A Comprehensive Survey of Bias in LLMs: Current Landscape and Future Directionscited by 27
- 2024How (un)ethical are instruction-centric responses of LLMs? Unveiling the vulnerabilities of safety guardrails to harmful queriescited by 26
- 2025Large Language Models for Code Generation: A Comprehensive Survey of Challenges, Techniques, Evaluation, and Applicationscited by 26
- 2025A Survey of Personalization: From RAG to Agentcited by 26
- 2025AI Agentic Programming: A Survey of Techniques, Challenges, and Opportunitiescited by 26
- 2025EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Codecited by 24
- 2025A Study of LLMs' Preferences for Libraries and Programming Languagescited by 20
- 2024Few-Shot Fairness: Unveiling LLM's Potential for Fairness-Aware Classificationcited by 18
- 2024BiasDPO: Mitigating Bias in Language Models through Direct Preference Optimizationcited by 18
38 more
- 2025Afterburner: Reinforcement Learning Facilitates Self-Improving Code Efficiency Optimizationcited by 14
- 2025Profit Mirage: Revisiting Information Leakage in LLM-based Financial Agentscited by 13
- 2024Measuring the Influence of Incorrect Code on Test Generationcited by 9
- 2024Risks, Causes, and Mitigations of Widespread Deployments of Large Language Models (LLMs): A Surveycited by 8
- 2025Measuring Bias or Measuring the Task: Understanding the Brittle Nature of LLM Gender Biasescited by 8
- 2024A Survey on Human-AI Collaboration with Large Foundation Modelscited by 7
- 2025BiasFilter: An Inference-Time Debiasing Framework for Large Language Modelscited by 6
- 2025Towards Advancing Code Generation with Large Language Models: A Research Roadmapcited by 5
- 2026Reward Modeling for Reinforcement Learning-Based LLM Reasoning: Design, Challenges, and Evaluationcited by 5
- 2023Survey on AI Ethics: A Socio-technical Perspectivecited by 4
- 2025The Future of Generative AI in Software Engineering: A Vision from Industry and Academia in the European GENIUS Projectcited by 4
- 2025Bias after Prompting: Persistent Discrimination in Large Language Modelscited by 3
- 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistantscited by 3
- 2026A Spatio-Temporal Expert Prefetching Framework for Efficient MoE-based LLM Inferencecited by 3
- 2024STOP! Benchmarking Large Language Models with Sensitivity Testing on Offensive Progressionscited by 2
- 2025On the Reasoning Capacity of AI Models and How to Quantify Itcited by 2
- 2025LFTF: Locating First and Then Fine-Tuning for Mitigating Gender Bias in Large Language Modelscited by 2
- 2025Revisiting Disaggregated Large Language Model Serving for Performance and Energy Implicationscited by 2
- 2026CAGE: A Framework for Culturally Adaptive Red-Teaming Benchmark Generationcited by 2
- 2024White Men Lead, Black Women Help? Benchmarking and Mitigating Language Agency Social Biases in LLMscited by 1
- 2025Uncovering Intention through LLM-Driven Code Snippet Description Generationcited by 1
- 2025On LLM-Assisted Generation of Smart Contracts from Business Processescited by 1
- 2025LoRALib: A Standardized Benchmark for Evaluating LoRA-MoE Methodscited by 1
- 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AIcited by 1
- 2025Is Lying Only Sinful in Islam? Exploring Religious Bias in Multilingual Large Language Models Across Major Religionscited by 1
- 2026Controlling Distributional Bias in Multi-Round LLM Generation via KL-Optimized Fine-Tuningcited by 1
- 2026Social Bias in LLM-Generated Code: Benchmark and Mitigationcited by 1
- 2026Automated Summarization of Software Documents: An LLM-based Multi-Agent Approachcited by 1
- 2025SMITE: Enhancing Fairness in LLMs through Optimal In-Context Example Selection via Dynamic Validationcited by 0
- 2025Designing Empirical Studies on LLM-Based Code Generation: Towards a Reference Frameworkcited by 0
- 2025Bias Testing and Mitigation in Black Box LLMs using Metamorphic Relationscited by 0
- 2026LLM Security and Safety: Insights from Homotopy-Inspired Prompt Obfuscationcited by 0
- 2026BenchBrowser: Retrieving Evidence for Evaluating Benchmark Validitycited by 0
- 2026Fairness in Multi-Agent Systems for Software Engineering: An SDLC-Oriented Rapid Reviewcited by 0
- 2026From If-Statements to ML Pipelines: Revisiting Bias in Code-Generationcited by 0
- 2026Pattern over Pixels: Measuring Pattern Completion Bias in Multimodal Code Generationcited by 0
- 2026COMPAS: Difficulty-Aware Joint Search for Optimizing Code Generationcited by 0
- 2026LangChoiceBench: Measuring and Explaining Programming-Language Choice in LLMscited by 0
50 most cited of 53 All 53 (JSON)
- 2026Authority Bias in Conversational Search Engines for Academic Paper Recommendation31 Aug 2026
- 2026Same Chart, Different Story: Bias in Vision-Language Chart Interpretation12 Aug 2026
- 2026When Who You Are Can Change the Code You Get: A Study of Persona-Induced Bias in LLM Code Generation12 Aug 2026
- 2026LangChoiceBench: Measuring and Explaining Programming-Language Choice in LLMs6 Aug 2026
- 2026COMPAS: Difficulty-Aware Joint Search for Optimizing Code Generation5 Aug 2026
- 2026Pattern over Pixels: Measuring Pattern Completion Bias in Multimodal Code Generation4 Aug 2026
- 2026Automated Summarization of Software Documents: An LLM-based Multi-Agent Approach23 Jun 2026
- 2026A Spatio-Temporal Expert Prefetching Framework for Efficient MoE-based LLM Inference13 Jun 2026
- 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistants29 May 2026
- 2026Social Bias in LLM-Generated Code: Benchmark and Mitigation1 May 2026
- 2026From If-Statements to ML Pipelines: Revisiting Bias in Code-Generation23 Apr 2026
- 2026Fairness in Multi-Agent Systems for Software Engineering: An SDLC-Oriented Rapid Review10 Apr 2026
38 more
- 2026Controlling Distributional Bias in Multi-Round LLM Generation via KL-Optimized Fine-Tuning7 Apr 2026
- 2026BenchBrowser: Retrieving Evidence for Evaluating Benchmark Validity25 Feb 2026
- 2026Reward Modeling for Reinforcement Learning-Based LLM Reasoning: Design, Challenges, and Evaluation10 Feb 2026
- 2026CAGE: A Framework for Culturally Adaptive Red-Teaming Benchmark Generation9 Feb 2026
- 2026LLM Security and Safety: Insights from Homotopy-Inspired Prompt Obfuscation20 Jan 2026
- 2025Is Lying Only Sinful in Islam? Exploring Religious Bias in Multilingual Large Language Models Across Major Religions3 Dec 2025
- 2025Bias Testing and Mitigation in Black Box LLMs using Metamorphic Relations29 Nov 2025
- 2025Revisiting Disaggregated Large Language Model Serving for Performance and Energy Implications14 Nov 2025
- 2025The Future of Generative AI in Software Engineering: A Vision from Industry and Academia in the European GENIUS Project3 Nov 2025
- 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AI20 Oct 2025
- 2025Profit Mirage: Revisiting Information Leakage in LLM-based Financial Agents9 Oct 2025
- 2025Designing Empirical Studies on LLM-Based Code Generation: Towards a Reference Framework4 Oct 2025
- 2025On the Use of Agentic Coding: An Empirical Study of Pull Requests on GitHub18 Sep 2025
- 2025LoRALib: A Standardized Benchmark for Evaluating LoRA-MoE Methods14 Sep 2025
- 2025Bias after Prompting: Persistent Discrimination in Large Language Models9 Sep 2025
- 2025Measuring Bias or Measuring the Task: Understanding the Brittle Nature of LLM Gender Biases4 Sep 2025
- 2025SMITE: Enhancing Fairness in LLMs through Optimal In-Context Example Selection via Dynamic Validation25 Aug 2025
- 2025AI Agentic Programming: A Survey of Techniques, Challenges, and Opportunities15 Aug 2025
- 2025On LLM-Assisted Generation of Smart Contracts from Business Processes30 Jul 2025
- 2025Uncovering Intention through LLM-Driven Code Snippet Description Generation18 Jun 2025
- 2025Afterburner: Reinforcement Learning Facilitates Self-Improving Code Efficiency Optimization29 May 2025
- 2025BiasFilter: An Inference-Time Debiasing Framework for Large Language Models28 May 2025
- 2025LFTF: Locating First and Then Fine-Tuning for Mitigating Gender Bias in Large Language Models21 May 2025
- 2025EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Code19 May 2025
- 2025A Survey of Personalization: From RAG to Agent14 Apr 2025
- 2025A Study of LLMs' Preferences for Libraries and Programming Languages21 Mar 2025
- 2025Large Language Models for Code Generation: A Comprehensive Survey of Challenges, Techniques, Evaluation, and Applications3 Mar 2025
- 2025On the Reasoning Capacity of AI Models and How to Quantify It23 Jan 2025
- 2025Towards Advancing Code Generation with Large Language Models: A Research Roadmap20 Jan 2025
- 2024A Comprehensive Survey of Bias in LLMs: Current Landscape and Future Directions24 Sep 2024
- 2024STOP! Benchmarking Large Language Models with Sensitivity Testing on Offensive Progressions20 Sep 2024
- 2024Measuring the Influence of Incorrect Code on Test Generation14 Sep 2024
- 2024Risks, Causes, and Mitigations of Widespread Deployments of Large Language Models (LLMs): A Survey1 Aug 2024
- 2024BiasDPO: Mitigating Bias in Language Models through Direct Preference Optimization18 Jul 2024
- 2024A Survey on Large Language Models for Code Generation1 Jun 2024
- 2024White Men Lead, Black Women Help? Benchmarking and Mitigating Language Agency Social Biases in LLMs16 Apr 2024
- 2024ALERT: A Comprehensive Benchmark for Assessing Large Language Models' Safety through Red Teaming6 Apr 2024
- 2024A Survey on Human-AI Collaboration with Large Foundation Models7 Mar 2024
50 newest of 53 All 53 (JSON)
- 2025On the Use of Agentic Coding: An Empirical Study of Pull Requests on GitHubcited by 53
- 2025AI Agentic Programming: A Survey of Techniques, Challenges, and Opportunitiescited by 26
- 2025Profit Mirage: Revisiting Information Leakage in LLM-based Financial Agentscited by 13
- 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistantscited by 3
- 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AIcited by 1
- 2026Automated Summarization of Software Documents: An LLM-based Multi-Agent Approachcited by 1
- 2026Fairness in Multi-Agent Systems for Software Engineering: An SDLC-Oriented Rapid Reviewcited by 0
- 2026Automated Summarization of Software Documents: An LLM-based Multi-Agent Approach23 Jun 2026
- 2026What Breaks When LLMs Code? Characterizing Operational Safety Failures of Agentic Code Assistants29 May 2026
- 2026Fairness in Multi-Agent Systems for Software Engineering: An SDLC-Oriented Rapid Review10 Apr 2026
- 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AI20 Oct 2025
- 2025Profit Mirage: Revisiting Information Leakage in LLM-based Financial Agents9 Oct 2025
- 2025On the Use of Agentic Coding: An Empirical Study of Pull Requests on GitHub18 Sep 2025
- 2025AI Agentic Programming: A Survey of Techniques, Challenges, and Opportunities15 Aug 2025
- 2024ALERT: A Comprehensive Benchmark for Assessing Large Language Models' Safety through Red Teamingcited by 96
- 2024How (un)ethical are instruction-centric responses of LLMs? Unveiling the vulnerabilities of safety guardrails to harmful queriescited by 26
- 2026CAGE: A Framework for Culturally Adaptive Red-Teaming Benchmark Generationcited by 2
- 2026CAGE: A Framework for Culturally Adaptive Red-Teaming Benchmark Generation9 Feb 2026
- 2024ALERT: A Comprehensive Benchmark for Assessing Large Language Models' Safety through Red Teaming6 Apr 2024
- 2024How (un)ethical are instruction-centric responses of LLMs? Unveiling the vulnerabilities of safety guardrails to harmful queries23 Feb 2024
- 2025A Survey of Personalization: From RAG to Agentcited by 26
- 2025A Survey of Personalization: From RAG to Agent14 Apr 2025
- 2024A Survey on Large Language Models for Code Generationcited by 646
- 2024A Comprehensive Survey of Bias in LLMs: Current Landscape and Future Directionscited by 27
- 2025Large Language Models for Code Generation: A Comprehensive Survey of Challenges, Techniques, Evaluation, and Applicationscited by 26
- 2025EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Codecited by 24
- 2025A Study of LLMs' Preferences for Libraries and Programming Languagescited by 20
- 2024Few-Shot Fairness: Unveiling LLM's Potential for Fairness-Aware Classificationcited by 18
- 2024Measuring the Influence of Incorrect Code on Test Generationcited by 9
- 2024Risks, Causes, and Mitigations of Widespread Deployments of Large Language Models (LLMs): A Surveycited by 8
- 2025Measuring Bias or Measuring the Task: Understanding the Brittle Nature of LLM Gender Biasescited by 8
- 2024A Survey on Human-AI Collaboration with Large Foundation Modelscited by 7
- 2025BiasFilter: An Inference-Time Debiasing Framework for Large Language Modelscited by 6
- 2025Towards Advancing Code Generation with Large Language Models: A Research Roadmapcited by 5
12 most cited of 33 All 33 (JSON)
- 2026Authority Bias in Conversational Search Engines for Academic Paper Recommendation31 Aug 2026
- 2026When Who You Are Can Change the Code You Get: A Study of Persona-Induced Bias in LLM Code Generation12 Aug 2026
- 2026LangChoiceBench: Measuring and Explaining Programming-Language Choice in LLMs6 Aug 2026
- 2026COMPAS: Difficulty-Aware Joint Search for Optimizing Code Generation5 Aug 2026
- 2026Social Bias in LLM-Generated Code: Benchmark and Mitigation1 May 2026
- 2026From If-Statements to ML Pipelines: Revisiting Bias in Code-Generation23 Apr 2026
- 2026Controlling Distributional Bias in Multi-Round LLM Generation via KL-Optimized Fine-Tuning7 Apr 2026
- 2026BenchBrowser: Retrieving Evidence for Evaluating Benchmark Validity25 Feb 2026
- 2026LLM Security and Safety: Insights from Homotopy-Inspired Prompt Obfuscation20 Jan 2026
- 2025Is Lying Only Sinful in Islam? Exploring Religious Bias in Multilingual Large Language Models Across Major Religions3 Dec 2025
- 2025Bias Testing and Mitigation in Black Box LLMs using Metamorphic Relations29 Nov 2025
- 2025The Future of Generative AI in Software Engineering: A Vision from Industry and Academia in the European GENIUS Project3 Nov 2025
12 newest of 33 All 33 (JSON)
Similar, not cited
Close in wording, no citation either way
- 2024Bias Unveiled: Investigating Social Bias in LLM-Generated Code
- 2026How Reasoning Shapes Social Bias in LLM-Generated Code?
- 2026Measuring and Mitigating Bias in Code Generated by Large Language Models
- 2025FairCoder: Probing LLM Bias in High-Stakes Decision Making via Coding Tasks
- 2026On the risk of coding before testing: An empirical study on LLM-based test generation workflow
- 2025GenderBench: Evaluation Suite for Gender Biases in LLMs
- 2024With a Grain of SALT: Are LLMs Fair Across Social Dimensions?
- 2026Bias in the Loop: Auditing LLM-as-a-Judge for Software Engineering