When Who You Are Can Change the Code You Get: A Study of Persona-Induced Bias in LLM Code Generation
Abstract
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
| 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. | Medium | Rejected |
| C: Metadata Block | YAML-like structured profile ( age:, gender:, nationality:, ... ). | Tests whether structured context reduces style bleed while maintaining demographic salience. | Low-Medium | Rejected |
| D: Context After Task | Same structure as Variant A, but placed after the task. | Tests order sensitivity in planning and whether demographic cues influence late-stage decision-making. | Low | Rejected |
| E: Role Assignment | Persona embedded in a role-binding instruction (“You are assisting a developer with this background: …”). | Strongest identity binding; tests whether task framing with persona context increases demographic leakage. | High | Selected |
| Difficulty | Count | Percentage | Persona | Count | Percentage |
|---|---|---|---|---|---|
| Easy | 22 | 0.6% | |||
| Medium | 970 | 24.7% | |||
| Hard | 2,936 | 74.7% | |||
| Number and total percentage of omitted data by persona | |||||
| neutral | 275 | 7.0% | br_nb_junior | 209 | 5.3% |
| br_w_senior | 228 | 5.8% | in_m_senior | 207 | 5.3% |
| Test | Purpose | Decision Criterion |
|---|---|---|
| Shapiro-Wilk | Test normality | → non-normal |
| Levene’s | Test equal variance | → heterogeneous |
| Kruskal-Wallis | Omnibus comparison | → significant |
| Mann-Whitney U | Pairwise comparison | → sign. |
| Bonferroni | Control FWER | |
| Holm-Bonferroni | Stepwise FWER control |
| Persona | Persona Acc. | Diff (%) | OR | -value |
|---|---|---|---|---|
| in_nb_junior | 0.6398 | 0.513 | 0.000659 | |
| br_nb_junior | 0.6502 | 0.591 | 0.011170 | |
| br_m_junior | 0.6502 | 0.630 | 0.017153 | |
| br_w_junior | 0.6502 | 0.640 | 0.019061 | |
| in_w_junior | 0.6540 | 0.635 | 0.030180 | |
| br_m_senior | 0.6540 | 0.676 | 0.043723 |
| Persona | Mean | Mean Diff | Effect Size | ||
|---|---|---|---|---|---|
| sp_w_junior | 65.84 | -9.74 | *** | -0.520 | Large |
| br_w_junior | 66.75 | -8.84 | *** | -0.480 | Large |
| sp_m_junior | 67.04 | -8.55 | *** | -0.462 | Medium |
| br_m_junior | 67.15 | -8.44 | *** | -0.452 | Medium |
| br_nb_junior | 68.44 | -7.15 | *** | -0.407 | Medium |
| in_m_junior | 69.34 | -6.25 | *** | -0.392 | Medium |
| Persona | Mean | Mean Diff | Sig. | |||
|---|---|---|---|---|---|---|
| Significant Comparisons (Better than Neutral) | ||||||
| sp_m_senior | 4.97 | +0.83 | 629,786 | *** | +0.132 | Yes |
| sp_w_senior | 4.94 | +0.80 | 624,617 | *** | +0.125 | Yes |
| br_w_senior | 4.78 | +0.65 | 616,731 | *** | +0.109 | Yes |
| sp_nb_senior | 4.71 | +0.57 | 612,218 | *** | +0.102 | Yes |
| sp_m_junior | 4.75 | +0.62 | 606,110 | .005** | +0.090 | Yes |
| 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 |
| Persona | Mean | Mean Diff | 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 |
| Persona | Mean | Mean Diff | U | 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 |
Demographic Bias in Language Models
Demographic bias in language models studies how identity cues shape model outputs, decisions, and representations, and how to detect and reduce resulting disparities.
See all 135 papers