When Who You Are Can Change the Code You Get: A Study of Persona-Induced Bias in LLM Code Generation
Authors: Anubhav Gupta, Mayara Costa Figueiredo, Leticia Santos Machado, Tanner Wright, Ivan Beschastnikh, Cleidson R. B. de Souza, Gema Rodríguez-Pérez
Large Language Models (LLMs) are widely used as programming assistants, yet it remains unclear whether and how user's demographic information impacts the technical quality of generated code. We conduct a large-scale empirical study of persona-induced bias in LLM-based code generation, focusing a proprietary model (Gemini 2.5 Pro) and an open-weight model (GPT-OSS-120B). Using 18 demographic personas spanning nationality, gender, and experience level, we compare persona-induced prompts against a neutral baseline. Across 35,000+ generated programs, we analyze demographic marker leakage in reasoning and responses, as well as differences in functional correctness, maintainability, code style, and security. Our results show that demographic cues are frequently reflected in LLM reasoning and outputs. Demographic markers appear in up to 65% of responses and 70% of reasoning traces, despite being semantically irrelevant to the tasks. On LiveCodeBench, persona prompting were associated with lower correctness scores of the Gemini model by an average of 1.54 percentage points, with one persona exhibiting a decrease of 3.6% (odds ratio = 0.51). In contrast, the accuracy of the GPT-OSS model improved by 3.4 - 5.7% across all personas (odds ratios = 1.8 - 3.0). Maintainability and code style metrics show statistically significant but negligible effect sizes (all Cliff's δ < 0.15), and security vulnerabilities exhibit no systematic persona-specific patterns. Overall, our results show that the presence of demographic information about users is associated with measurable variation in LLM reasoning and code quality even in purely technical tasks, and that these effects hold across models. Our work highlights an under-examined risk in LLM-assisted software development.
Figures & tables
Figure 1: Illustration showing demographic persona prompts (left) and observed demographic markers in the LLM’s internal reasoning process (right).
Figure 2: Overview of our study design.
Variant
Structure
Persona Placement / Intended Effect
Leakage Strength
Decision
A: Context Line
Neutral context block placed before the task.
Provides subtle demographic information without implying stylistic changes; tests low-intervention exposure.
Low
Rejected
B: First-Person Disclosure
First-person phrasing (“For context: I am …”).
Increases persona salience through narrative voice; tests whether self-description alters tone or style.
Table 3: Statistical tests and procedures summary.
Figure 6: Demographic marker prevalence analysis: (A) Comparison of marker prevalence between THOUGHTS and RESPONSE sections, (B) Overall prevalence appearing in either, and (C) Distribution of marker counts stratified by problem difficulty.
Figure 7: Persona-specific demographic marker leakage patterns: (A) Aggregate leakage scores by persona attributes, (B) Spider charts by nationality.
Figure 8: Difficulty effects on demographic marker leakage: (A) All five markers show declining prevalence from easy to hard problems, and (B) Nationality-difficulty interaction shows Brazil and Spain exhibit steeper declines than India.
Persona
Persona Acc.
Diff (%)
OR
p -value
in_nb_junior
0.6398
−3.60
0.513
0.000659
br_nb_junior
0.6502
−2.56
0.591
0.011170
br_m_junior
0.6502
−2.56
0.630
0.017153
br_w_junior
0.6502
−2.56
0.640
0.019061
in_w_junior
0.6540
−2.18
0.635
0.030180
br_m_senior
0.6540
−2.18
0.676
0.043723
Table 4: McNemar’s test results. A comparison of functional correctness of demographic personas against the neutral baseline.
Persona
Mean
Mean Diff
pcorr
δ
Effect Size
sp_w_junior
65.84
-9.74
<.001 ***
-0.520
Large
br_w_junior
66.75
-8.84
<.001 ***
-0.480
Large
sp_m_junior
67.04
-8.55
<.001 ***
-0.462
Medium
br_m_junior
67.15
-8.44
<.001 ***
-0.452
Medium
br_nb_junior
68.44
-7.15
<.001 ***
-0.407
Medium
in_m_junior
69.34
-6.25
<.001 ***
-0.392
Medium
Table 5: Pairwise comparisons – each persona vs. neutral baseline (maintainability index).
Persona
Mean
Mean Diff
U
pcorr
δ
Sig.
Significant Comparisons (Better than Neutral)
sp_m_senior
4.97
+0.83
629,786
<.001 ***
+0.132
Yes
sp_w_senior
4.94
+0.80
624,617
<.001 ***
+0.125
Yes
br_w_senior
4.78
+0.65
616,731
<.001 ***
+0.109
Yes
sp_nb_senior
4.71
+0.57
612,218
<.001 ***
+0.102
Yes
sp_m_junior
4.75
+0.62
606,110
.005**
+0.090
Yes
Table 6: Pairwise comparisons – each persona vs. neutral baseline (Pylint score).
Figure 9: Demographic marker prevalence analysis for GPT-OSS-120B: (A) Comparison of marker prevalence between THOUGHTS and RESPONSE sections, (B) Overall prevalence appearing in either, and (C) Distribution of marker counts stratified by problem difficulty.
Figure 10: Persona-specific demographic marker leakage patterns for GPT-OSS-120B: (A) Aggregate leakage scores by persona attributes, (B) Spider charts by nationality.
Figure 11: Difficulty effects on demographic marker leakage for GPT-OSS-120B: (A) Most markers show declining prevalence from easy to hard problems, and (B) Nationality-difficulty interaction shows a consistent decline across all 3 nationalities.
Persona
Persona Acc.
Diff (%)
OR
p-value
in_nb_senior
0.4237
+5.69
3.000
0.000000
sp_w_senior
0.4237
+5.69
2.818
0.000000
sp_nb_senior
0.4218
+5.50
2.657
0.000000
in_w_junior
0.4180
+5.12
2.500
0.000002
sp_nb_junior
0.4180
+5.12
2.500
0.000002
sp_w_junior
0.4180
+5.12
2.459
0.000003
Table 7: McNemar’s test results (GPT-OSS-120B). A comparison of functional correctness of demographic personas against the neutral baseline.
Persona
Mean
Mean Diff
pcorr
δ
Effect Size
in_m_junior
76.85
+1.21
0.187
+0.075
Negligible
br_nb_junior
76.67
+1.03
0.283
+0.071
Negligible
br_w_junior
76.75
+1.11
0.304
+0.070
Negligible
sp_w_senior
76.69
+1.05
0.414
+0.066
Negligible
sp_nb_junior
76.49
+0.86
0.437
+0.066
Negligible
br_nb_senior
76.58
+0.94
0.654
+0.061
Negligible
Table 8: Pairwise comparisons: – each persona vs. neutral baseline (maintainability index - GPT-OSS-120B).
Persona
Mean
Mean Diff
U
pcorr
δ
Sig.
Significant Comparisons (Better than Neutral)
None
Non-Significant Comparisons
br_w_senior
6.65
+0.01
310,171
1.000
+0.036
No
in_m_junior
6.67
+0.03
311,716
1.000
+0.031
No
in_w_senior
6.68
+0.04
318,894
1.000
+0.028
No
Table 9: Pairwise comparisons – each persona vs. neutral baseline (PyLint score - GPT-OSS-120B).
Demographic bias in language models studies how identity cues shape model outputs, decisions, and representations, and how to detect and reduce resulting disparities.