From If-Statements to ML Pipelines: Revisiting Bias in Code-Generation

Minh Duc Bui, Xenia Heilmann, Mattia Cerrato, Manuel Mager, Katharina von der WensearXiv 2026

TL;DR

Current benchmarks evaluate AI code-generation bias using simple if-else conditional statements, but this approach severely underestimates the risks of real-world deployment. By evaluating a more realistic task—machine learning (ML) pipeline feature selection—this paper reveals that large language models (LLMs) include sensitive attributes like race or gender in 88.3% of generated pipelines, compared to just 58.7% in explicit conditionals. This demonstrates that current safety evaluations suffer from a massive blind spot regarding covert discrimination.

What Problem Does This Paper Address?

When we evaluate whether code-generation models are biased, we usually look for overt discrimination: explicit rules like if race == 'black': deny_loan(). However, in real-world software engineering, discrimination is rarely that explicit. Instead, it manifests covertly through subtle design choices, such as feature selection in machine learning pipelines.

Including protected characteristics (like race, age, or gender) as predictive features violates a core principle of algorithmic fairness known as fairness through unawareness. Prior evaluations of code-generation bias have almost exclusively focused on simple conditional statements, creating a false sense of security. This paper addresses this gap by investigating whether LLMs exhibit systematic bias when generating end-to-end ML pipelines, and how the magnitude of this covert bias compares to previously studied overt bias.

Figure 1: Overview of our evaluation approach. We assess bias through covert discrimination in ML pipeline generation, specifically through feature selection, mov- ing beyond the overt conditional statements studied in prior work.

Methods

The authors evaluated ten state-of-the-art LLMs, including general instruction-tuned models (e.g., Llama 3.3 70B, Qwen2.5 72B, GPT-5 Mini) and code-specialized models (e.g., DeepSeek Coder 33B, Qwen2.5 Coder 32B).

For each model, they compared two code-generation conditions:

  1. Conditional Statements: Prompting the model to solve a predictive task using explicit if-else logic.
  2. ML Pipelines: Prompting the model to implement a standard ML pipeline (using models like Random Forests or Logistic Regression) where it had full discretion over feature selection.

To measure bias, the authors built an automated evaluation pipeline using an LLM (Gemma 3 27B) with Chain-of-Thought prompting to extract which features were actually utilized in the generated code. They also tested four prompt-based mitigation strategies (ranging from general instructions to avoid bias to specific prohibitions combined with Chain-of-Thought reasoning) and varied pipeline difficulty levels.

Datasets

The study grounds its evaluation across seven fairness-sensitive datasets spanning domains protected by anti-discrimination legislation:

  • Adult Income (predicting income level)
  • Employment Assessment (predicting employee performance)
  • U.S. Health Insurance (predicting insurance charges)
  • COMPAS (predicting recidivism risk)
  • Communities and Crime (predicting violent crime rates)
  • German Credit (predicting creditworthiness)
  • LSAC (predicting bar exam passage)

To ensure a rigorous test of feature selection, each dataset's prompt included a mix of sensitive attributes (e.g., race, sex, age), non-sensitive attributes, and three deliberately nonsensical/irrelevant attributes (e.g., "favorite color", "favorite prime number").

Key Insights and Ideas

  • Covert Bias Amplification: LLMs are significantly more likely to leak sensitive attributes into an ML model's feature set than they are to write them into explicit conditional logic.
  • Deliberate Choice, Not Inability to Filter: Models consistently prune out completely irrelevant features like "favorite color." This means the inclusion of sensitive attributes like "race" is a deliberate choice based on perceived predictive utility, rather than an inability to filter information.
  • The Awareness Disconnect: When explicitly asked to audit code snippets, the models are highly capable of identifying when sensitive attributes are being used. Yet, they still blindly include those same attributes during code generation.
  • The Illusion of Scale and Context: Providing more non-sensitive features causes bias to drop sharply in conditional statements, but has virtually no effect on ML pipelines; the models persistently retain sensitive features regardless of how many alternatives are available.
Figure 6: Effect of Varying Feature Number on Bias. Results averaged across all attributes on the Crime dataset.

Key Results

  • Across all models and datasets, sensitive attributes appeared in 88.3% of generated ML pipelines compared to 58.7% of conditional statements—a 24.6% relative increase in bias prevalence.
  • Out of 200 model-dataset-attribute combinations, 178 (89%) exhibited higher bias in the ML pipeline condition.
  • Traditional prompt mitigations fail to close the gap. Even the strongest mitigation strategy (Specific+CoT) still left a substantial disparity between the two tasks.
Figure 3: Bias in Code Generation for Conditional Statements and ML Pipelines. Red bars indicate bias measured in ML pipelines, while blue bars indicate bias measured via conditional statements. The x-axis denotes the sensitive attributes, and individual panels correspond to the respective datasets. Across all models and datasets, the average bias is 58.7% for conditional statements and 88.3% for ML pipelines.

Limitations and Future Work

The authors note several limitations that pave the way for future research:

  1. Code Execution: The evaluation pipeline checks for feature inclusion within the code structure but does not verify if the generated code executes successfully without syntax errors.
  2. Proxy Discrimination: The study only tracks the explicit inclusion of sensitive attributes. It does not account for proxy variables (e.g., using zip codes as a proxy for race), which is a common vector for covert discrimination in real-world systems.
  3. Causal Mechanisms: The work is primarily empirical; further study is required to understand the underlying causal mechanisms within LLMs that drive this task-dependent bias behavior.

Summary updated

BibTeX
@misc{bui2026from,
  author = {Minh Duc Bui and Xenia Heilmann and Mattia Cerrato and Manuel Mager and Katharina von der Wense},
  title = {{From If-Statements to ML Pipelines: Revisiting Bias in Code-Generation}},
  year = {2026},
  eprint = {2604.21716},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.21716},
}
Figure