arXiv:2610.22942cs.CLOct 2026

Manuscript Offprint

arXiv:2610.22942

Aligning Language Models Towards Counterfactual Invariance

Basar Demir, Emily Shen, Ksheeraj Sai Vepuri, Sourabh Kulkarni, Harihar Subramanyam, Ankit Jain, Nan Jiang, Chirag Nagpal

ABSTRACT

Small variations in prompt characteristics can meaningfully alter the semantics, tone, and contextual assumptions of large language model outputs. Such characteristics can involve group variables such as demographics or other sensitive latent attributes. Sensitivity to such input variables is undesirable when demographic information is causally irrelevant to the task, but might still be relevant for generation of semantically coherent responses. This makes the task of enforcing counterfactual invariance while preserving model utility difficult. To study this problem, we first show that standard model alignment recipes (such as reinforcement learning) increase differences in response quality across demographics, while improving overall response quality, ultimately amplifying what is known as counterfactual bias. To address this, we develop a policy gradient technique involving a group-level reward function that operates on matched pairs of counterfactual prompts. For completeness, we build a dataset of controlled counterfactual prompt pairs and design an evaluation that separately measures cases where demographic information is causally relevant to the answer. Finally, we validate our findings on several fairness benchmarks. We demonstrate that our methods reduce counterfactual differences while preserving overall response quality and that the models continue to adapt appropriately when such sensitive information is relevant.

1 INTRODUCTION

The behavior of a language model depends on more than just the substance of the request it receives. Formatting, phrasing, and user signals can change the semantics, tone, or assumptions of a response (Sclar et al., 2024; Poole-Dayan et al., 2026). As model capabilities and context expand, language models synthesize larger amounts of personalized user information as relevant when responding to a request. However, more information is not always better: an aligned model should possess the discretion to know when sensitive context is relevant and adapt its responses accordingly. Under-utilizing context can result in decreased helpfulness due to overly general or non-helpful responses. Over-indexing on context can result in a model that is sycophantic (producing a deferential response flattering to power), oblivious (producing an impolite, overly familiar response), or reinforcing of latent biases in its training data (producing a paternalistic response assuming diminished capabilities). When features of the input (information supplied directly in the prompt, or attributes stored in persistent memory) do not have causal relevance to the request, the LLM's response should not depend upon them. This requirement can be defined as counterfactual invariance: downstream model outputs should be blind to non-causal input features.

Standard model alignment approaches do not encourage this property. Preference models used for post-training LLMs favor responses that match a user's stated views (Sharma et al., 2024), and reward models shift their scores when a demographic self-identification is added to a response (Kumar et al., 2025), so preference optimization can reward the policy for conditioning on user cues even when

Views expressed are authors' own.

Figure

Figure 1: Sensitive context such as demographics can subtly affect the quality of the open-ended response. Such dependence might be relevant in certain instances, but actively harmful in other situations and lead to diminished response quality or stereotyping. This paper studies the amplification of such harms as a side effect of training language models with reinforcement learning.

they are irrelevant to the task. Training for invariance directly would address this, but requires an objective that connects disparate arms to measure and mitigate the corresponding performance gaps.

Counterfactual invariance can be measured through classification, where we can check whether the classifier's prediction remains the same across counterfactual inputs (Garg et al., 2019). Fairness benchmarks for language models largely adopt this view. BBQ (Parrish et al., 2022) and Difference Awareness (Wang et al., 2025a) pose multiple-choice questions, and DiscrimEval (Tamkin et al., 2023) elicits a yes/no decision across demographic variants of the same scenario. While these existing forced-choice evaluation benchmarks are useful signals to sanity check the bias in a given model, they cannot detect differences that appear only in open-ended responses, which is how most people use generative models and where more real-world harm can be done. Two responses can use entirely different wording to convey the same advice, or read fluently while diverging in their implicit assumptions and tone, as Figure 1 illustrates. Measuring invariance requires looking beyond surface-level textual identity such as exact token matching to whether responses remain aligned under perturbations that are not deemed causal from the perspectives of a domain expert.

In this paper, we argue that generative language models are not currently aligned to use demographic information with the appropriate discretion. We articulate the gap in selective counterfactual invariance in the open-ended generation setting and propose methods for its mitigation which integrate with common post-training regimes and existing helpfulness reward models. First, we build a dataset of counterfactual prompt pairs that differ only in race or gender, and label each pair by whether this difference matters for the task. For pairs where it does not, we train the model with GRPO (Shao et al., 2024) to respond consistently to both prompts. To mitigate counterfactual bias in invariant open-ended LLM responses, we propose Reward Expectation Matching, which compares responses to the two prompts by their reward scores rather than their wording, so harmless paraphrases are not penalized. Comparing these scores directly is unreliable, because the reward model may score the same answer differently depending on the demographic information in the prompt. Instead, we score the answers to both prompts under the same prompt, so any remaining gap reflects differences between the answers rather than the reward model's sensitivity to the prompt. Overall, through a series of experiments involving novel algorithmic approaches and datasets, our contributions can be summarized as follows:

• We demonstrate how standard reinforcement learning based post-training recipes that optimize for a model’s instruction following capability perpetuate model bias as measured against existing public benchmarks. This motivates the need for explicit regularization techniques that promote counterfactual invariance in the post-training phase.

• We propose transformations of rewards that involve cross prompt reward equalization on counterfactually invariant pairs. Our proposed transformations are compatible with GRPO style reinforcement learning methods and involve equalization of the expected rewards across counterfactuals.

• Finally, we build a high-quality set of ∼\sim2,500 counterfactual prompt pairs curated from four public corpora with an automated LLM pipeline and label each pair by whether demographic information affects the requirements of a correct response following a labeling policy developed with domain experts. For completeness, we also evaluate our method on multiple forced-choice benchmarks and show that our method improves invariance while preserving response quality.

2 RELATED WORK

Counterfactual fairness A model is counterfactually fair if its output would not change had the person belonged to a different demographic group, a condition Kusner et al. (2017) formalize by changing the protected attribute in a causal model of the data. Garg et al. (2019) bring it to text, where changing the attribute amounts to swapping a word that names a group and penalize any difference between a toxicity classifier's outputs on a comment and on its swapped copy. Veitch et al. (2021) extend it to any input attribute that should not affect the prediction and show that the right regularizer depends on the causal structure, in particular whether the text causes the label or the label causes the text. Chaudhary et al. (2025) carry the question to LLMs, bounding with high confidence the probability that a model responds without bias to counterfactual prompts, as judged by a bias detector. In each case, invariance is checked through a class label, a score, or a detector's verdict. An open-ended response offers none of these. Crucially, invariance is also not always or by default desirable, since some tasks require treating groups differently (Wang et al., 2025a).

Invariance evaluation in forced-choice and open-ended settings Measuring invariance in open-ended responses is itself an open problem. Most bias evaluations reduce each response to a single choice or number, such as an answer to an ambiguous multiple-choice question (Parrish et al., 2022) or a yes/no decision such as approving a loan (Tamkin et al., 2023), and results in these formats need not carry over to free-form responses (Röttger et al., 2024; Lum et al., 2025). Evaluations of free text such as BOLD (Dhamala et al., 2021) score each text alone, for example its sentiment, toxicity, or regard, which mixes bias with the effect of the name itself. FairPair (Dwivedi-Yu, 2024) addresses this by comparing the texts generated for two names directly, but its sentiment and word-overlap measures cannot distinguish harmless rewording from substantive differences. First-Person Fairness (Eloundou et al., 2025) compares responses with an LLM rater, which can judge content, but it applies the same harmful-stereotype judgment to every task and does not specify per task whether demographic differences are warranted.

Sensitivity of reward models Training an LLM toward this invariance with reinforcement learning requires a reward model, and the reward model may itself not be invariant. Reward models change their preferences when a statement such as “I am a woman.” is prepended to otherwise identical responses (Kumar et al., 2025). GRPO does not remove this sensitivity. It normalizes rewards within each prompt (Shao et al., 2024), which cancels a shift that applies equally to all responses to that prompt but not a preference among them. A reward model that favors a warm tone when the prompt names one group and a direct list when it names another still teaches the policy to answer the two prompts differently. Prior work retrains the reward model with a penalty that makes its internal representations independent of an irrelevant attribute, such as demographic terms in the preference data (Wang et al., 2025b), or under demographic parity, equalized odds, or counterfactual fairness constraints, with a bound on how much less fair the fine-tuned policy can become (Choi et al., 2026).

Bias mitigation and consistency training Preference-based post-training has been applied to bias by training on pairs of biased and unbiased completions (Allam, 2024) or by rewarding completions with a learned bias reward model (Reddy et al., 2026), but these methods judge each response in isolation rather than against the response to the other version of the prompt. Other methods compare against a reference instead. They use a version of the prompt without the biasing information and train the model to reproduce its clean behavior, by preferring responses whose embeddings are closest to a teacher's answer to the clean prompt (Poulain et al., 2024), preferring the model's own clean reasoning in DPO (Nam & Demszky, 2026), fine-tuning on its clean reasoning (Chua et al., 2024) or clean response (Irpan et al., 2025), or matching its activations on the clean prompt (Irpan et al., 2025). This assumes that a clean prompt exists and that the model behaves well on it, and close matching also penalizes harmless changes such as a different name or pronoun. Like the reward transformations in this work, Kulkarni et al. proposed the use of GRPO style algorithms to match a language model's responses to arbitrary target distributions and connect their approach to inverse RL (Wiliński et al., 2026), but do not discuss prompt matching or counterfactuals.

Figure

Figure 2: Overview of the proposed objectives for a pair of invariant prompts (x,x′)(x, x'): The central idea in our paper involves enforcing invariance by encouraging the reward distributions across counterfactuals to be similar. Towards this goal, a natural choice involves matching the first moment, that is the expectation of the rewards.