Social Bias in LLM-Generated Code: Benchmark and Mitigation

Fazle Rabbi, Lin Ling, Song Wang, Jinqiu Yang · 2026

Read Social Bias in LLM-Generated Code: Benchmark and Mitigation by Fazle Rabbi, Lin Ling, Song Wang, Jinqiu Yang (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2605-00382.txt.

Introduction

Fazle Rabbi and 3 co-authors measure social bias in code written by language models, an angle most evaluations skip in favor of correctness alone. Their benchmark holds 343 real-world coding tasks across seven demographic dimensions. Four prominent models were tested, and every one showed severe bias, with bias scores reaching high levels on their scale.

Common prompt-level fixes made things worse: chain-of-thought reasoning and fairness personas amplified the bias instead of reducing it. Structured multi-agent pipelines helped only when early roles scoped the task correctly, and spreading fairness instructions across all roles backfired. The authors' answer is a Fairness Monitor Agent that plugs into an existing pipeline, checks which attributes a task may use, and corrects violations in review rounds. It cut bias by about two-thirds while also improving functional correctness.

Catalog record

CREATORFazle Rabbi, Lin Ling, Song Wang, Jinqiu Yang
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE77 KB
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2605.00382

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Social Bias in LLM-Generated Code: Benchmark and Mitigation Fazle Rabbi, Lin Ling, Song Wang, Jinqiu Yang Abstract 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 code generation largely unexamined. Extending our prior work on Solar, an automated fairness testing framework, we conduct a comprehensive empirical study to expose and mitigate social bias in LLM-generated code using SocialBias-Bench, a benchmark of 343 real-world coding tasks spanning seven demographic dimensions. We first 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 software process models can be leveraged to improve fairness in code generation. Using a well-established multi-agent software process framework, FlowGen, we find that structured pipelines reduce bias when early development roles correctly define and scope what the code should and should not consider. However, enforcing fairness through role-level instructions does not work: adding explicit fairness instructions to all agent roles produces worse outcomes than providing no fairness instruction at all, suggesting that spreading the responsibility across multiple agents may cause it to go unaddressed by any of them. To address these limitations, we propose the Fairness Monitor Agent ( FMA ), a modular system that can be plugged into any existing code generation pipeline without modifying it. FMA analyzes the task description to determine which attributes should be considered or restricted while generating the code logic, then detects and corrects any violations through an iterative review process, all without requiring an executable test suite. Evaluations on all 343 tasks show that FMA reduces bias by 65.1% compared to a developer agent alone, outperforming all other studied approaches, including multi-agent workflows, while simultaneously improving functional correctness from 75.80% to 83.97%, by preventing bias before generation and correcting any remaining violations afterward. ∎ 1 Introduction LLMs pre-trained and fine-tuned on code-specific datasets have led to significant advances in automated software development, including Codex ( Chen et al. 2021 ) , CodeGen ( Nijkamp et al. 2022 ) , StarCoder ( Li et al. 2023 ) , Code Llama ( Roziere et al. 2023 ) , and GitHub Copilot. With LLMs increasingly integrated into professional software development workflows, the quality of generated code extends beyond functional correctness to fairness, particularly in human-centered tasks where code outcomes affect people. Current benchmark evaluations such as HumanEval ( Chen et al. 2021 ) and MBPP ( Austin et al. 2021 ) focus exclusively on functional correctness and do not assess whether code treats different demographic groups equitably. Prior studies confirm that LLMs exhibit social biases in NLP tasks ( Bai et al. 2023 ; Zhao et al. 2023 ; Meade et al. 2021 ; Gallegos et al. 2023 ) , but these findings do not transfer directly to code generation due to the structural and semantic constraints of programming languages. Figure 1 : Overview of the Solar fairness evaluation framework. Recent works ( Liu et al. 2023 ; Huang et al. 2023 ) took initial steps to study social bias in code generation, but both rely on simplified prompt designs and do not cover the full range of real-world, human-centered coding tasks. Neither work explores agentic or multi-agent mitigation strategies. This paper makes the following contributions: (1) We develop Solar , a fairness evaluation framework that automatically generates executable metamorphic test cases to quantify social bias in LLM-generated code, and curate SocialBias-Bench , a benchmark of 343 human-centered coding tasks spanning seven demographic dimensions. (2) We conduct an empirical study of social bias across four prominent LLMs, showing that all models exhibit severe bias and that standard prompt-level interventions such as Chain-of-Thought and positive role-playing amplify rather than reduce it. (3) We investigate social bias in multi-agent code generation workflows using FlowGen, examining how workflow structure, fairness-aware role instructions, and role composition affect bias in the generated code. (4) We propose FMA , a modular, oracle-free fairness agent system that intercepts any existing code generation pipeline to detect and repair social bias through static LLM-based analysis and iterative guided rewriting, without requiring access to any test oracle or dataset-specific configuration. To systematically understand how social bias manifests in LLM-generated code, how it is affected by development workflows, and how it can be mitigated without relying on test oracles, we formulate the following research questions: • RQ1: How severe is social bias in LLM-generated code, and how does it vary across models, demographic dimensions, and generation temperature? • RQ2: Can prompt-level interventions such as Chain-of-Thought reasoning and fairness persona assignment effectively mitigate social bias in LLM-generated code? • RQ3: How do structured software process models affect social bias in LLM-generated code, and does role-based fairness prompting improve fairness outcomes? • RQ4: Can a Fairness Monitor Agent ( FMA ) reduce social bias in LLM-generated code without relying on test oracles? The remainder of this paper is organized as follows. Section 2 introduces key concepts of fairness, metamorphic testing, and the FlowGen framework. Section 3 presents Solar and SocialBias-Bench , including the framework design, test case generation, and evaluation metrics. Section 4 describes the FMA pipeline and all its agent components. Section 5 details the subject LLMs and shared experimental settings across all RQs. Section 6 presents the empirical results for all four research questions: bias characterization across models and temperatures (RQ1), the failure of prompt-level interventions (RQ2), the impact of structured software process models on bias (RQ3), and the evaluation of FMA (RQ4). Section 7 interprets these results and discusses their broader implications. Section 8 discusses threats to validity, and Section 9 situates our contributions within prior research. Finally, Section 10 concludes the paper and outlines directions for future work. We make our code and dataset publicly available 1 1 1 https://github.com/frabbisw/solar_comprehensive . 2 Background 2.1 Code Bias We define social bias in code generation as unjustified disparities in code output caused by a protected (sensitive) attribute, one that should not logically affect the outcome for a given task ( Galhotra et al. 2017 ; Corbett-Davies et al. 2017 ) . A fair code snippet should produce the same result for any two individuals who differ only in a protected attribute ( Chen et al. 2024 ) . Let f(x) represent a code snippet, where x contains both protected attributes p and non-protected attributes np . Bias is present for a protected attribute p_{i} if: f(np,\ldots,p_{i},\ldots)\neq f(np,\ldots,p_{i}^{\prime},\ldots) (1) where p_{i} and p_{i}^{\prime} are different values of the same protected attribute. For example, if p_{i} is gender, f(\cdot,\text{male},\cdot) should equal f(\cdot,\text{female},\cdot) to be considered fair. 2.2 Demographics and Bias Direction We evaluate bias across seven demographic dimensions ( Díaz et al. 2018 ; Zhang et al. 2023 ; Liu et al. 2019 ; Wan et al. 2023 ) summarized in Table 1 . One code snippet may exhibit bias along multiple dimensions simultaneously (intersectional bias). Beyond detecting whether bias exists, we also characterize its direction , whether the code systematically favors specific demographic values ( Sheng et al. 2020

Read the complete text