Social Bias in LLM-Generated Code: Benchmark and Mitigation
Not on the map. Why?
Abstract (arXiv)
Large Language Models (LLMs) are increasingly deployed to generate code for human-centered applications where demographic fairness is critical. However, existing evaluations focus almost exclusively on functional correctness, leaving social bias in LLM-generated code largely unexamined. Extending our prior work on Solar, we conduct a comprehensive empirical study using SocialBias-Bench, a benchmark of 343 real-world coding tasks spanning seven demographic dimensions. We evaluate four prominent LLMs and find severe bias across all models, with Code Bias Scores reaching up to 60.58%. We further show that standard prompt-level interventions, such as Chain-of-Thought reasoning and fairness persona assignment, inadvertently amplify bias rather than reduce it. We then investigate whether structured multi-agent software process frameworks can improve fairness, finding that structured pipelines reduce bias when early roles correctly scope what the code should and should not consider. However, adding explicit fairness instructions to all agent roles produces worse outcomes than providing none, suggesting that diffused responsibility goes unaddressed. To address these limitations, we propose the Fairness Monitor Agent (FMA), a modular component that plugs into any existing code generation pipeline without modifying it. FMA analyzes the task description to determine which attributes should be considered or restricted, then detects and corrects violations through an iterative review process, without requiring an executable test suite. Evaluated on all 343 tasks, FMA reduces bias by 65.1% compared to a developer agent alone and improves functional correctness from 75.80% to 83.97%, outperforming all other studied approaches.
Key facts. Cited by 1 paper in the map (data through 14 Oct 2026). Builds on 42 of its 64 references that are in the map. First posted on arXiv 1 May 2026.
Builds on
42 of 64 references.
References · 42
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2023Reflexion: Language Agents with Verbal Reinforcement Learningcited by 4,276
- 2021Program Synthesis with Large Language Modelscited by 3,637
- 2023Self-Refine: Iterative Refinement with Self-Feedbackcited by 3,442
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2016Man is to Computer Programmer as Woman is to Homemaker? Debiasing Word Embeddingscited by 1,312
- 2020StereoSet: Measuring stereotypical bias in pretrained language modelscited by 924
- 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 885
- 2023StarCoder: may the source be with you!cited by 799
- 2020CrowS-Pairs: A Challenge Dataset for Measuring Social Biases in Masked Language Modelscited by 710
- 2021BBQ: A Hand-Built Bias Benchmark for Question Answeringcited by 701
- 2018Gender Bias in Coreference Resolution: Evaluation and Debiasing Methodscited by 659
30 more
- 2023Bias and Fairness in Large Language Models: A Surveycited by 639
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
- 2024Agentless: Demystifying LLM-based Software Engineering Agentscited by 421
- 2021BOLD: Dataset and Metrics for Measuring Biases in Open-Ended Language Generationcited by 412
- 2017Algorithmic decision making and the cost of fairnesscited by 403
- 2021Towards Understanding and Mitigating Social Biases in Language Modelscited by 296
- 2023Self-collaboration Code Generation via ChatGPTcited by 258
- 2019Counterfactual Data Augmentation for Mitigating Gender Stereotypes in Languages with Rich Morphologycited by 200
- 2017Fairness Testing: Testing Software for Discriminationcited by 126
- 2023Keep the Conversation Going: Fixing 162 out of 337 bugs for 0.42 each using ChatGPTcited by 125
- 2020Towards Controllable Biases in Language Generationcited by 112
- 2021An Empirical Survey of the Effectiveness of Debiasing Techniques for Pre-trained Language Modelscited by 97
- 2019Does Gender Matter? Towards Fairness in Dialogue Systemscited by 89
- 2020Hate Speech Detection and Racial Bias Mitigation in Social Media based on BERT modelcited by 87
- 2020Metamorphic Testing: A New Approach for Generating Next Test Casescited by 75
- 2023Evaluating the Code Quality of AI-Assisted Code Generation Tools: An Empirical Study on GitHub Copilot, Amazon CodeWhisperer, and ChatGPTcited by 71
- 2023LLMSecEval: A Dataset of Natural Language Prompts for Security Evaluationscited by 62
- 2023BiasAsker: Measuring the Bias in Conversational AI Systemcited by 53
- 2023Bias Testing and Mitigation in LLM-based Code Generationcited by 53
- 2024SOEN-101: Code Generation by Emulating Software Process Models Using Large Language Model Agentscited by 34
- 2022Unified Detoxifying and Debiasing in Language Generation via Inference-time Adaptive Optimizationcited by 33
- 2020Do Neural Ranking Models Intensify Gender Bias?cited by 29
- 2023Uncovering and Quantifying Social Biases in Code Generationcited by 25
- 2024Bias Unveiled: Investigating Social Bias in LLM-Generated Codecited by 25
- 2024An Exploratory Study on Fine-Tuning Large Language Models for Secure Code Generationcited by 9
- 2022TESTSGD: Interpretable Testing of Neural Networks Against Subtle Group Discriminationcited by 7
- 2025A Multi-Language Perspective on the Robustness of LLM Code Generationcited by 6
- 2024Specification-Driven Code Translation Powered by Large Language Models: How Far Are We?cited by 5
- 2025Secure-Instruct: An Automated Pipeline for Synthesizing Instruction-Tuning Datasets Using LLMs for Secure Code Generationcited by 2
- 2025BabelCoder: Agentic Code Translation with Specification Alignmentcited by 1
Built on by
Citing papers per year: 2026: 1.
1 paper.
Similar, not cited
Close in wording, no citation either way
- 2026How Reasoning Shapes Social Bias in LLM-Generated Code?
- 2026Fairness in Multi-Agent Systems for Software Engineering: An SDLC-Oriented Rapid Review
- 2025FairCoder: Probing LLM Bias in High-Stakes Decision Making via Coding Tasks
- 2026Measuring and Mitigating Bias in Code Generated by Large Language Models
- 2026When Who You Are Can Change the Code You Get: A Study of Persona-Induced Bias in LLM Code Generation
- 2026Cognitive Biases in LLM-Assisted Software Development
- 2024Towards Implicit Bias Detection and Mitigation in Multi-Agent LLM Interactions
- 2025BigCodeArena: Unveiling More Reliable Human Preferences in Code Generation via Execution