Test-Time Fairness and Robustness in Large Language Models

## Abstract

Abstract Frontier Large Language Models (LLMs) can be socially discriminatory or sensitive to spurious features of their inputs. Because only well-resourced corporations can train frontier LLMs, we need robust test-time strategies to control such biases. Existing solutions, which instruct the LLM to be fair or robust, rely on the model’s implicit understanding of bias. Causality provides a rich formalism through which we can be explicit about our debiasing requirements. Yet, as we show, a naive application of the standard causal debiasing strategy, counterfactual data augmentation, fails under standard assumptions to debias predictions at an individual level at test time. To address this, we develop a stratified notion of debiasing called stratified invariance, which can capture a range of debiasing requirements from population level to individual level through an additional measurement that stratifies the predictions. We present a complete observational test for stratified invariance. Finally, we introduce a data augmentation strategy that guarantees stratified invariance at test time under suitable assumptions, together with a prompting strategy that encourages stratified invariance in LLMs. We show that our prompting strategy, unlike implicit instructions, consistently reduces the bias of frontier LLMs across a suite of synthetic and real-world benchmarks without requiring additional data, finetuning or pre-training.

## 1 Introduction

As large language models (LLMs) are used for increasingly high-stakes decision-making [, , , ], it is important that their predictions meet the expectations of users, as well as the aspirations of a fair and just society [, ]. Unfortunately, LLMs will typically mimic the distribution of real-world data, which may be biased relative to the intended use-case or may reflect injustice []. For instance, due to observational biases in its training data, an LLM might unfairly rely on an individual’s gender when predicting their occupation, cf. Figure 1(a).

Addressing this challenge is not easy. Frontier LLMs’ high training costs limit their development, or even finetuning, to a few well-resourced corporations. These issues are aggravated in closed-source models, where the proprietary nature of data and training algorithms makes it difficult to enforce any set of user requirements at training time. Thus, it is critical that we develop test-time solutions, i.e., methods encouraging LLM predictions to meet users’ (or society’s) expectations that do not require pre- or retraining [, ].

To date, most test-time attempts to encourage certain expected behaviors in LLMs try to influence the predictions through instructions in static prompts []. For instance, Tamkin et al., [] prompted the LLM with “Please ensure that your answer is unbiased and does not rely on stereotypes.” (cf. Figure 1(b)). The challenge with this approach is that it implicitly relies on the LLM’s unknown definitions of the biases associated with a task. This issue is more evident in the context of fairness, whose definition has been extensively debated across legal [], policy [], and technological [] domains.

We study the problem of test-time fairness and robustness through a causal invariance lens: a framework that studies the stability of predictors under interventions on spurious or protected attributes. Unfortunately, the classical notion of invariance —counterfactual invariance— is mostly infeasible at test time, even with counterfactual data augmentations. To this end, we make the following contributions:

- •
We develop a population-level concept for causal invariance: stratified invariance. This view offers a more practical alternative to counterfactual invariance while maintaining significant analytical power. Stratified invariance presents two main advantages: (i) we can measure it from observational data; and (ii) the user can reasonably expect to achieve it at test time, making it more applicable to real-world studies. Moreover, the degree of stratification allows for fine-tuning the analysis’s individuality. As stratification increases, the method approaches counterfactual invariance, offering a spectrum of analytical depth. Finally, we present stratified counterfactual data augmentation, a method that ensures stratified invariance at test time.
- •
We propose Out-Of-Context (OOC) prompting (cf. Figure 1(c)), a zero-shot method that simulates stratified counterfactual data augmentations in LLM predictions. OOC leverages the user causal knowledge of the task to explicitly promote their specified requirements of stratified invariance.
- •
Empirically, we use six benchmark datasets with nine different protected/spurious attributes to show that OOC prompting achieves state-of-the-art results on fairness and robustness across different model families and sizes, without sacrificing much predictive performance. We consider scenarios where the requirements are specified as stratified invariances, and how they relate to counterfactual invariance. Moreover, we show that implicit safety prompts (e.g., Figure 1(b)) do not reliably improve fairness and robustness in LLM predictions, i.e., they often are less fair/robust than the original LLM prediction or even reasoning strategies, e.g., Chain-Of-Thought [].

## 2 Test-Time Fairness and Robustness via Causal Invariances

We take a causal perspective to define our notion of fairness and robustness. We are interested in debiasing predictions with respect to a random *context* $Z\in{\mathcal{Z}}$, which represents a protected or spurious characteristic. Crucially, the distribution of other random variables, including our predictions, can depend on this context and our goal is to be robust to changes in $Z$.

To model this, we define the *potential outcome* (PO) of a random variable to be its value when $Z$ is intervened on. More precisely, let $\hat{Y}$ be a prediction that depends on $Z$. We define the collection of potential predictions $\hat{Y}(z)$ for $z\in{\mathcal{Z}}$ and assume the observed prediction is given by $\hat{Y}:=\hat{Y}(Z)$, with a slight abuse of notation. More generally, if $B(z)$ is a potential outcome, we define $B:=B(Z)$. Throughout, we assume that all random variables are discrete and that ${\mathcal{Z}}$ is finite.

To define the robustness of a predictor $\hat{Y}$, we require that its potential predictions $\hat{Y}(z)$ satisfy some notion of causal invariance to interventions on $z$. *Counterfactual invariance* is one common goal [, ], which requires that $\hat{Y}(z)\stackrel{{\scriptstyle\text{a.s.}}}{{=}}\hat{Y}(z^{\prime}),\forall
z
,z^{\prime}\in{\mathcal{Z}}$. The appeal of counterfactual invariance comes from its focus on individual fairness: we always make the same prediction if everything else, but the context, is fixed [, ]. Counterfactual invariance is a very strong requirement and its definition has caused a lot of misunderstandings in previous literature []. Instead, other works trying to enforce conditional independences at training time [, ] induce a population notion of causal invariance $\hat{Y}(z)\stackrel{{\scriptstyle d}}{{=}}\hat{Y}(z^{\prime}),\forall z,z^{
\prime}\in{\mathcal{Z}}$, which we call *intervention invariance*. This notion requires that, if we were to perform an experiment assigning contexts independently at random, predictions would have the *same distribution* across contexts.

Some train-time methods are able to achieve counterfactual invariance in the predictors they learn, but enforcing counterfactual invariance in a given predictor at test time is considerably more challenging. Recent works [, ] have used LLMs to perform *counterfactual data augmentation* at training time, which randomly transforms an input $X$ to a potential input $X(z)$ by changing the context randomly. Under the assumption that one is able to transform $X$ according to the true conditional, these methods will learn counterfactual-invariant predictors in the limit of infinite data. The reason is that the learning algorithm will get to “see” potential inputs for all exogenous noise realizations and become invariant to the context almost surely. Unfortunately, a naive application of this at test time fails: even if we average out the context for a given test point, we are still vulnerable to variations in exogenous noise and may fail to enforce invariance across different realizations of the process. Therefore, in this section we investigate the questions: (i) What type of invariance can counterfactual data augmentation provide at test time? (ii) Can we measure it? (iii) What adaptations and assumptions in counterfactual data augmentation are needed at test time?

#### Stratified invariance

Our key idea is that additional measurements at test time, captured in a random variable $S\in{\mathcal{S}}$, can be used to construct stratified predictors, each of which ensures intervention invariance locally across the context $z$. One can think of $S$ as a view into the exogenous noise of the system, and for the noise not captured in $S$ we can ensure intervention invariance at best. We call this flexible notion of invariance *stratified invariance*.

###### Definition 1 (Stratified invariance) .

$\hat{Y}$ is $S$-stratified invariant to the context $Z$ if

$$ $P(\hat{Y}(z)=y\mid S=s)=P(\hat{Y}(z^{\prime})=y\mid S=s)\quad\forall z,z^{ \prime}\in{\mathcal{Z}},s\in{\mathcal{S}},y\in{\mathcal{Y}}.$ $$

Stratified invariance with particular choices of $S$ appears in works studying counterfactual invariance. As Fawkes and Evans, [] note, the definition of counterfactual invariance in [] is better interpreted as Definition 1. We study Definition 1 in its own right, e.g., providing new results like Definitions 2 and 3, which we hope will help shed light into these important criteria. To develop an intuition, consider two special cases. If $S:=c$ is a constant random variable, then stratified invariance is just equality in distribution, i.e., intervention invariance. If $S:=\{\hat{Y}(z)\}_{z\in{\mathcal{Z}}}$, then stratified invariance is almost sure equality, i.e., counterfactual invariance.

Stratified invariance has a number of appealing properties: (i) it always implies interventional invariance; (ii) if $S$ contains all the randomness generating the prediction it is equivalent to counterfactual invariance; and (iii) if $S$ is an adjustment set (see below for a definition) for $(\hat{Y},Z)$ we can provide a complete observational test for it. Therefore, stratified invariance is a middle ground between intervention and counterfactual invariance. If we were to make multiple randomized experiments stratifying $S$, the distribution of predictions would match across contexts with the same value of $S$. As we add more variables (randomness) into $S$, we get finer-grained experimental stratification. If we add all the randomness, we consider only the same individual in each experiment and we are measuring counterfactual invariance.

###### Definition 1 (Stratified invariance) .

#### An observational test for stratified-invariant predictions

One of the main difficulties with counterfactual invariance is our inability to test it from observational data []. As for interventional/stratified notions, we are not always able to run interventional experiments to directly observe the potential outcomes $\hat{Y}(z)$ for a given context $z$. Here, we derive a complete observational test for stratified invariance using what is classically known as an *adjustment set*.

###### Definition 2 (Adjustment set) .

Given $Z\in{\mathcal{Z}}$ and the potential outcomes $\{B(z)\}_{z\in{\mathcal{Z}}}$, we say that $A$ is an adjustment set for $(B,Z)$ if $A$ satisfies both (strong) ignorability and positivity assumptions: $\{B(z)\}_{z\in{\mathcal{Z}}}\perp\!\!\!\perp Z\mid A,\text{ and }0<p_{Z\mid A}
(z\mid a)<1,\forall(z,a)\in{\mathcal{Z}}\times\text{supp}(A)$ [].

If the stratifying measurement $S$ is also an adjustment set for $(\hat{Y},Z)$, then we can test for stratified invariance by testing for conditional independence.

[Conditional Independence][end]
Let $S$ be an adjustment set for $(Z,\hat{Y})$. Then, $\hat{Y}$ is $S$-stratified invariant to $Z$ if and only if $\hat{Y}\perp\!\!\!\perp Z\mid S$.

Let $(y,z,s)\in{\mathcal{Y}}\times{\mathcal{Z}}\times{\mathcal{S}}$. From the definition of the PO $\hat{Y}(z)$, we can write the conditional

$$ $P(\hat{Y}(z)=y\mid S=s)=\frac{P(\hat{Y}=y,Z=z\mid S=s)}{P(Z=z\mid\hat{Y}(z)=y, S=s)}.$ $$

Since $S$ is an adjustment set of $(\hat{Y},Z)$,

$$ $P(\hat{Y}(z)=y\mid S=s)=\frac{P(\hat{Y}=y,Z=z\mid S=s)}{P(Z=z\mid S=s)}=P(\hat {Y}=y\mid Z=z,S=s).$ (1) $$

- ($\Leftarrow$)
If $\hat{Y}\perp\!\!\!\perp Z\mid S$, the by (1) we have
$\displaystyle P(\hat{Y}(z)=y\mid S=s)$
$\displaystyle=P(\hat{Y}=y\mid Z=z,S=s)$
$\displaystyle=P(\hat{Y}=y\mid S=s)$
which is invariant under $z$. Therefore, $P(\hat{Y}(z)=y\mid S=s)=P(\hat{Y}(z^{\prime})=y\mid S=s)$ for every pair $z,z^{\prime}\in{\mathcal{Z}}$.
- ($\Rightarrow$)
Now, if $\hat{Y}$ is $S$-invariant to $Z$ we have that for any $y\in{\mathcal{Y}},z,z^{\prime}\in{\mathcal{Z}},s\in{\mathcal{S}}$
$P(\hat{Y}(z)=y\mid S=s)=P(\hat{Y}(z^{\prime})=y\mid S=s),$
and thus by (1)
$P(\hat{Y}=y\mid Z=z,S=s)=P(\hat{Y}=y\mid Z=z^{\prime},S=s),\forall y\in{
\mathcal{Y}},z,z^{\prime}\in{\mathcal{Z}},s\in{\mathcal{S}}$
$\implies\hat{Y}\perp\!\!\!\perp Z\mid S.$

We stress that this test is only complete when $S$ is also an adjustment set. Indeed, unless an empty adjustment set is feasible, it is not complete for intervention invariance, i.e., intervention invariance does not imply independence. Similarly, although Veitch et al., [] proposed this test as a signature of counterfactual invariance, conditional independence does not imply counterfactual invariance unless $S$ contains all the exogenous noise in the potential predictions $\hat{Y}(z)$.

###### Definition 2 (Adjustment set) .

#### Designing invariant predictors at test time

The stratifying measurement $S$ allows us to transform an existing predictor $h$ into one that is stratified-invariant at test time under some additional assumptions. The key idea is to run a synthetic “randomized experiment” at test time, conditioned on $S$ and the given input $X$, by generating a new potential input $X^{+}=X(Z^{+})$ via a randomized context $Z^{+}$. Once we have $X^{+}$, we return the prediction $h(X^{+})$. By conditioning on $S$, we ensure almost sure equality up to the exogenous noise not contained in $S$.

More specifically, suppose there is a collection of potential inputs $\{X(z)\}_{z\in{\mathcal{Z}}}$ and an existing predictor $h:{\mathcal{X}}\to{\mathcal{Y}}$. If we assume that we can both (i) exactly recover the context from $X(z)$ given $S$; and (ii) sample from the conditional distribution of $X(z^{+})$ given $S$ and $X(z)$; then the following data augmentation procedure will produce an $S$-stratified invariant predictor.

###### Definition 3 (Stratified Data Augmentation) .

Let $(x,s,z^{+})\in{\mathcal{X}}\times{\mathcal{S}}\times{\mathcal{Z}}$ and $h:{\mathcal{X}}\to{\mathcal{Y}}$ be a predictor. Assume that $f:{\mathcal{X}}\times{\mathcal{S}}\to{\mathcal{Z}}$ is such that $f(X(z),S)\stackrel{{\scriptstyle\text{a.s.}}}{{=}}z$ for all $z\in{\mathcal{Z}}$ and assume that we can sample from the conditional distribution of $X(z^{+})$ given $S$ and $X(z)$. Define the following collection of predictions $\hat{Y}_{\text{aug}}(x,s,z^{+})$:
{mdframed}

Let $Z^{+}\in{\mathcal{Z}}$ be a random variable independent of all other random variables, then the $S$-adjusted potential prediction is given by $\hat{Y}_{\text{aug}}(z):=\hat{Y}_{\text{aug}}(X(z),S,Z^{+})$ for every $z\in{\mathcal{Z}}$ and the observed $S$-adjusted prediction is given by $\hat{Y}_{\text{aug}}:=\hat{Y}_{\text{aug}}(Z)$.

[Stratified Data Augmentation is Stratified Invariant][end]
The $S$-adjusted predictor $\hat{Y}_{\text{aug}}$ of Def. 3 is $S$-invariant to $Z$.
{proofE}

$$ $\displaystyle P(\hat{Y}_{\text{aug}}(z)=y\mid S=s)$ $\displaystyle=\mathbb{E}\left[\mathds{1}\{h(X^{+})=y\}\mid S=s\right]$ $\displaystyle=\mathbb{E}\left[\mathbb{E}\left[\mathds{1}\{h(X^{+})=y\}\mid Z^{ +},S=s\right]\mid S=s\right]$ $$

Looking at the inner expectation, we have

$$ $\displaystyle\mathbb{E}\left[\mathds{1}\{h(X^{+})=y\}\mid Z^{+}=z^{+},S=s\right]$ $\displaystyle=\sum_{x,x^{+}\in{\mathcal{X}}}\mathds{1}\{h(x^{+})=y\}\cdot p_{X (z^{+})\mid X(z),S,Z^{+}}(x^{+}\mid x,s,z^{+})p_{X(z)\mid S,Z^{+}}(x\mid s,z^{ +})$ $\displaystyle=\sum_{x^{+}\in{\mathcal{X}}}\mathds{1}\{h(x^{+})=y\}\cdot p_{X(z ^{+})\mid S,Z^{+}}(x^{+}\mid s,z^{+})$ $\displaystyle=\mathbb{E}\left[\mathds{1}\{h(X(z^{+}))=y\}\mid Z^{+}=z^{+},S=s\right]$ $$

From this we get

$$ $\displaystyle P(\hat{Y}_{\text{aug}}(z)=y\mid S=s)=P(h(X(Z^{+}))=y\mid S=s),$ $$

which is invariant to $z$. Thus $\hat{Y}_{\text{aug}}$ is $S$-invariant.

Although predictions from Theorem 3 are stratified invariant, the variance in predictions can make it hard to observe the invariance in a given dataset. To mitigate this issue, one can repeat steps 1-3 in Def. 3 to generate multiple predictins $\hat{Y}_{\text{aug}}$, and aggregate their answers —e.g., majority vote.

###### Definition 3 (Stratified Data Augmentation) .

## 3 Out-Of-Context Prompting

In this section, we present *Out-Of-Context (OOC) prompting*, a strategy to implement stratified data augmentation with LLMs at test time. The core idea of OOC is to use the LLM itself to both (i) simulate the transformations of Definition 3 and (ii) perform predictions over the transformed inputs.

Recent works used LLMs to sample counterfactual augmentations of data at training time by directly asking the model “what would $X$ be if $Z$ had been $Z^{+}$?” [, ]. The main differences with the procedure in Definition 3 is that at test time, conditional on $(X,S)$, to produce $X^{+}=X(Z^{+})$ we must: (i) exactly recover $Z$ and (ii) replace $Z$ with $Z^{+}$. The replacement step is the most complex part of this process, i.e., despite being able to infer $Z$ from some part of the input, the LLM might ignore subtle references to $Z$ in other parts.

Therefore, instead of recovering and replacing, OOC implements the steps in Definition 3 with LLMs by performing two equivalent steps: (i) recover and remove $Z$ from $X$ to produce $X_{\text{LM}}^{-}$; and (ii) incorporate $Z^{+}$ into $X_{\text{LM}}^{-}$ to produce $X_{\text{LM}}^{+}$. By separating the removal task, which implicitly requires the recovery of $Z$, we make the replacement task less complex. For the rest of the section, we denote by $p_{\mathtt{LM}}(\cdot\mid c)$ the LLM conditional density with prefix $c$.

#### Context obfuscation ( 𝐗 , 𝐒 ) → 𝐗 LM − → 𝐗 𝐒 superscript subscript 𝐗 LM \mathbf{(X,S)\to X_{\text{LM}}^{-}} ( bold_X , bold_S ) → bold_X start_POSTSUBSCRIPT LM end_POSTSUBSCRIPT start_POSTSUPERSCRIPT - end_POSTSUPERSCRIPT ( Appendix F )

We use role-playing prompts to obfuscate the input $X_{\text{LM}}^{-}\sim p_{\mathtt{LM}}(\cdot\mid\mathtt{F}^{(\text{obfs})}(X,S;
\pi^{(\text{obfs})}))$. We use a template function $\mathtt{F}^{(\text{obfs})}$ asking the LLM to perform a text obfuscation task for a security company (^1^11A template function merges the input and the prompt in a specified way.). The prompt $\pi^{(\text{obfs})}$ is sampled from a set of possible obfuscation instructions. The randomization is performed to promote diversity in generation as suggested in []. To condition on $S$, we pass it as a piece of secret information that the LLM can use when rewriting the text, but cannot explicitly disclose —in the case of $S=Y$, we want to avoid the same initial prediction later on.

#### Context addition ( 𝐗 LM − , 𝐙 + , 𝐒 ) → 𝐗 LM + → superscript subscript 𝐗 LM superscript 𝐙 𝐒 superscript subscript 𝐗 LM \mathbf{(X_{\text{LM}}^{-},Z^{+},S)\to X_{\text{LM}}^{+}} ( bold_X start_POSTSUBSCRIPT LM end_POSTSUBSCRIPT start_POSTSUPERSCRIPT - end_POSTSUPERSCRIPT , bold_Z start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT , bold_S ) → bold_X start_POSTSUBSCRIPT LM end_POSTSUBSCRIPT start_POSTSUPERSCRIPT + end_POSTSUPERSCRIPT ( Appendix F )

We sample $Z^{+}\sim\text{Unif}({\mathcal{Z}})$, and generate an input with the new context $X_{\text{LM}}^{+}\sim p_{\mathtt{LM}}(\cdot\mid\mathtt{F}^{(\text{add})}(X_{
\text{LM}}^{-},Z^{+},S;\pi^{(\text{add})}))$. Again, we leverage role-playing prompts: $\mathtt{F}^{(\text{add})}$ asks the model to perform a writing assistance task: someone forgot to add a piece of information to the text that needs to be disclosed. Again, we perform prompt randomization and sample $\pi^{(\text{add})}$, which asks the LLM to add or disclose the information in $Z^{+}$. As in the obfuscation step, we pass $S$ as additional secret information.

Figure: Algorithm 1 OOC prompting strategy.

As described at the end of Section 2, we repeat the process, generate predictions, and aggregate their answers —e.g., take the majority or ask the LLM to decide (in open-ended generation). Putting it all together, we have the final OOC prompting strategy described in Algorithm 1 and visualized in Figure 1(c).

#### Practical Considerations

OOC prompting relies on a mix of causal assumptions from the user(cf. Section 2), data access assumptions, and LLM capabilities (cf. Section 3). Next, we will review these assumptions and discuss how the practitioner can assess them. Although we cannot assess these capabilities in theory, our results in Section 5 indicate that they are more reliable and have better scaling laws than the LLM’s implicit fairness and robustness capabilities.

- •
One has access to $\mathbf{S}$. Definition 3 and OOC as written above take $S$ as input together with $X$. However, it is common in real-world applications of LLMs to only observe the input $X$. In this case, we generate a synthetic $S_{\text{LM}}^{+}\sim p_{\mathtt{LM}}(\cdot\mid\mathtt{F}_{S}(X;\pi_{S}))$ from $X$, where $\mathtt{F}_{S}$ is a template function and $\pi_{S}$ a prompt specifying the prediction of $S$ from $X$. If all the other assumptions hold, our predictions will be invariant conditional on the proxy $S_{\text{LM}}^{+}$, not the underlying $S$. It is important to stress that, if $S$ is not available at test time, we will not be able to provide $S$-stratified invariance. The user has to then assess whether they believe the prediction $S_{\text{LM}}^{+}$ is correlated to $S$ enough to provide a meaningful stratification for the problem. In Section 5 we empirically explore this assumption by measuring the invariance of OOC under $S$ stratification.
- •
$\mathbf{S}$ and the input fully determine the context. OOC prompting relies on an LLM’s ability to implicitly recover $Z$ from $X$ and remove it in the obfuscation step. The existence of a function that fully determines the context $z$ from a potential input $X(z)$ and $S$ is associated to how much a person believes the underlying context of an input can be extracted from the input (and $S$). For instance, in Figure 1(c) we can expect this to be true, since pronouns and names tend to be everywhere in a person’s biography.
- •
The LLM can generate a potential input conditional on $\mathbf{X,Z,S}$. Given an obfuscated input, OOC prompting relies on an LLM’s ability generate a potential input $X(Z^{+})$ for a randomly chosen context $Z^{+}$. Essentially, the LLM would have had to have seen counterfactuals in its training data, i.e., both $X(z)$ and $X(z^{\prime})$. This assumption is our strongest assumption, as training data is largely observational, may even have some randomized controlled outcomes, but it is rare for it to contain counterfactuals, except in carefully controlled settings [].
- •
$\mathbf{S}$ is an adjustment set for the task. Although stratified invariance and counterfactual augmentations do not depend on $S$ being an adjustment set for $(X,Z)$, our ability to observe and validate it does. In practice, they are determined by the user under certain causal assumptions, see Appendix B.

## 4 Related Work

Our work is related to a wide variety of existing literature in safety, fairness, and causality. Next, we will provide additional context about the key works related to OOC. Please, refer to Appendix C for a review of prompting strategies.

#### Other concepts of fairness and robustness

There exists an extensive literature on fairness in machine learning [, ]. Most of the classical works focus on observational properties of fairness: demographic parity [] and equalized odds []. Definition 2 implies that these concepts can be recovered from stratified invariance when the adjustment set for the task is empty (demographic parity) or the label (equalized odds). Moreover, there are other continuous definitions of robustness that are not applicable in language tasks [].

#### Counterfactual invariance

There has been a recent interest in studying counterfactual invariance of predictors, mostly due to fairness reasons []. The work of Veitch et al., [] is the first to formulate the almost sure equality requirement as we state, but we note that it is equivalent to counterfactual fairness as originally stated in Kusner et al., [], Fawkes and Evans, []. As we note in Section 2, existing works that enforce conditional independence at training time [, ] are not imposing counterfactual, but rather stratified invariance. In fact, this was already pointed by Veitch et al., [], where the authors acknowledge that counterfactual invariance implies conditional independence, but the other direction is not valid in general. Finally, we note that Plecko and Bareinboim, [] provides a rich literature on graphical conditions for counterfactual invariance. Although this cannot be directly used to enforce invariances at test time, it is a useful tool to measure it under (mostly restrictive) causal model assumptions.

#### Counterfactual data augmentation in text classification

The fairness and robustness solution inspiring OOC is counterfactual data augmentation [, , ]. The main difference between OOC and previous works leveraging counterfactual transformations is that OOC performs it at test time. Existing literature, such as Mouli et al., [], is interested in applying counterfactual transformations as augmentations during the model training. In this context, the recent work of Feder et al., [] is the most similar to ours. As we mention in Section 2, the main difference with OOC is that, at test time, these procedures do not guarantee counterfactual, or even stratified, invariance. OOC can be seen as an adaptation of these ideas to test time leveraging Definitions 3 and 3.

Fairness and robustness in LLMs. Previous works in fairness and LLMs focus on one or two of the following: (i) characterizing existing biases and discrimination in frontier LLMs [, , ]; and (ii) works designing safety instructions to reduce such problems Schick et al., [], Tamkin et al., [], Ganguli et al., [], Si et al., []. Our work is motivated by the findings in (i) and fundamentally differs from (ii) in its solution: instead of designing prompts that explore the model’s implicit notions of biases, we leverage the user’s causal knowledge of the task to design a prompting strategy explicitly enforcing a known, user-specified, causal invariance property. Moreover, we highlight that there are works focusing on the characterization of robustness/sensitivity of LLMs, but they mostly focus on sensitivity to prompts [, , ], while offering task- and context-specific solutions [, ].

## 5 Results

We conduct a broad set of experiments to study OOC’s zero-shot ability to boost stratified invariance in LLM predictions at test time. Concretely, we focus on answering four questions: (i) Can OOC boost stratified invariance in real-world tasks? cf. Section 5.1; (ii) Does it retain the predictive performance of LLMs? cf. Section 5.1; (iii) How does OOC interact with scale (model size)? cf. Appendix E; (iv) How does stratification impact individual guarantees, i.e., counterfactual invariance, in OOC? cf. Section 5.2.

### 5.1 Boosting Stratified Invariance in Real-World Tasks

Here, we investigate whether OOC can boost stratified invariance in real-world text classification tasks. More specifically, we consider improving over the standard prompt of each task, i.e., directly querying for $Y$. Do other zero-shot methods also boost stratified invariance? In particular, is reasoning enough to boost stratified invariance? Do instructions leveraging the LLM’s implicit notion of bias also boost stratified invariance? Does predicting $S$ with the LLM improve $S$-stratified? To answer these questions, we also evaluate zero-shot CoT [] and six safety prompts proposed by Tamkin et al., []. Two of the safety prompts are asking the LLM to be unbiased (Unbiased, Precog) and four (Really4x, Illegal, Ignore, Illegal+Ignore) are more specifically asking it to avoid biases towards demographic groups. All baseline prompts can be found in Appendix F.

#### Datasets

We consider five real-world text classification datasets commonly used in the most recent fairness and robustness literature. For each of them, we define $S$ as an adjustment set to leverage the complete observational test from Definition 2.

- •
*Toxic Comments.* We consider the dataset civilcomments as proposed in Koh et al., []. The input $X$ corresponds to a comment made on an online forum and $Y$ to whether it is toxic or not. We estimate stratified invariance on three different binary contexts $Z$ that are more likely to present a higher discrepancy in predictions: gender (male/female), religion (Muslim/Christian), and race (black/white). For this task, we take the adjustment set as the comment’s label $S:=Y$ considering the causal graph from Figure 5 (c) (Appendix B) under selection bias (comment causes toxicity and we tend to observe more toxic comments towards minorities).
- •
*Bios.* We take the dataset of biography passages originally proposed by De-Arteaga et al., []. Here, as in Figure 1 we are interested in predicting someone’s occupation $Y$ from a passage of their biography $X$, while being fair with respect to their gender (male/female) $Z$. Our work focuses on the task proposed in Lertvittayakumjorn et al., [], where the occupation $Y$ is either nurse or surgeon. We take the adjustment set as the comment’s label $S:=Y$ by assuming the anti-causal graph from Figure 5 (a) (Appendix B) —the occupation causes the biography.
- •
*Amazon.* Here, we have the Amazon fashion reviews dataset []. The input $X$ corresponds to the text of a review made by a user, $Y$ to whether the review was evaluated as helpful by other users, and $Z$ to the sentiment of the reviewer, i.e., positive or negative. As in Veitch et al., [], we use the rating given by the user as a proxy for their sentiment. Here, we assume the same causal model as in Veitch et al., [], Figure 5 (b) (Appendix B), $S:=\emptyset$.
- •
*Discrimination.* We also take the synthetic dataset of yes/no questions recently proposed by Tamkin et al., []. We focus on five types of question that originally showed a stronger discriminant behavior in LLMs: (i) granting secure network access to users; (ii) suspending user accounts; (iii) increasing someone’s credit line; (iv) US customs allowing someone to enter the country; and (v) granting property deeds. These are decision questions that do not necessarily have a correct answer, and therefore we do not evaluate the LLM predictive performance here. We estimated stratified invariance across three different context pairs that, as shown in Tamkin et al., [], are more likely to present higher discrimination scores: gender (male/female), race (black/white), and age ($\leq$30/$\geq$60). Moreover, we follow Tamkin et al., [] and define an empty adjustment set $S:=\emptyset$.
- •
*Clinical.* Finally, we consider the MIMIC-III [] set of clinical notes ($X$). We take as context $Z$ whether the patient is employed or not and as label $Y$ whether the patient has an alcohol abuse history or not. Both the context and the label information are extracted from the subset MIMIC-SBDH []. Over the years, public health researchers have studied the effect of alcohol abuse on employment []. Ideally, healthcare workers should not bias their diagnosis according to a patient’s social history —unless there is strong evidence that it is a direct cause of their condition. Since the alcohol abuse information was used to generate notes, we make $S:=Y$ by considering the anti-causal graph from Figure 5 (i) (Appendix B).

Figure: (a) gpt-3.5-turbo.
Refer to caption: x4.png

#### Setup

Since we are dealing with binary classification tasks, we follow Veitch et al., [], Hardt et al., [] and define the following stratified invariance bias:

$$ $\text{SI-bias}:=\max_{s\in{\mathcal{S}},z_{1},z_{2}\in{\mathcal{Z}}}\mid P( \hat{Y}=1\mid S=s,Z=z_{1})-P(\hat{Y}=1\mid S=s,Z=z_{2})\mid.$ $$

It follows from Definition 2 that if $S$ is an adjustment set, the above metric is complete, i.e., a predictor satisfies stratified invariance if and only if its SI-bias is zero. For each dataset and context pair, we estimate the SI-bias with 200 random examples balanced according to $S$ and $Z$. To evaluate whether an $S$ predicted by the LLM can induce $S$-invariance, we prompt OOC with $S_{\text{LM}}^{+}$ (as suggested in Section 3) and evaluate the bias using the true $S$. To compute the predictive performance (macro F1-score(^2^22We chose F1-score due to label imbalance in some datasets.)) of each prompting strategy, we take 200 random examples sampled i.i.d. from the original dataset. As common practice [], we use temperature 0 to predict the labels of each task (including OOC). We evaluate stratified invariance in three popular, frontier LLM models: gpt-3.5-turbo, gpt-4-turbo [], and LLAMA-3-70B []. As suggested in [], we generate our counterfactual transformations with a temperature of $0.7$ (GPT family) and $0.8$ in the other models. In each task, we used $m=3$ samples for OOC with all models and tasks except for gpt-4-turbo and Clinical —where we used $m=1$ due to their high monetary cost and larger input size, respectively.

#### OOC consistently boosts stratified invariance in real-world tasks

Figure 2 shows how OOC is the only prompting method consistently improving stratified invariance on all tasks across all models. In particular, OOC is better than standard in 23/27 pairs of tasks and models, while Precog and CoT, the best baselines, improve only in 14/27 and 13/27 settings, respectively. Moreover, we see in Figure 2 that OOC provides the largest improvements over standard, being the method with the lowest bias in 20/27 settings. For comparison, CoT is the best method only in 5/27 and Precog in 2/27 tasks. See Appendix E for the raw results. Finally, we highlight that, with the exception of Amazon and Discrimination, OOC used the LLM prediction of $S$. The SI-bias is computed using the true value of $S$, therefore the improvements indicate that the LLM prediction $S_{\text{LM}}^{+}$ and $S$ are correlated enough to improve $S$-invariance —as we commented in Section 3.

Figure: Figure 3: Difference in F1 score of each method with standard prompting averaged across real-world tasks. In general, OOC does not affect the predictive performance of LLMs with standard prompting.
Refer to caption: x8.png

#### OOC retains the model’s predictive performance

Stratified invariance does not guarantee strong predictive performance. What if the LLM is transforming the input into independent noise? To assess this, Figure 3 shows the difference in predictive performance (macro F1 score) of each method with standard prompting across datasets. We see that OOC, on average, does not impact the original predictive performance by more than 0.05, with a worst case of 0.10 in Toxic Comments with gpt-4-turbo. Finally, Figure 3 shows that safety instructions produce not only larger negative impacts in predictive performance, but also a higher variance, making them unreliable to use at test time in a zero-shot manner.

### 5.2 Approaching Counterfactual Invariance Through Stratification

In Section 2, we discussed how amplifying the conditioning set $S$ should, monotonically, push stratified invariance towards counterfactual invariance. In this section, we investigate whether this is observed in practice with OOC.

Figure: Figure 4: As $\mathbf{S}$ encompasses more exogenous variables, OOC is more likely to make the same prediction for individuals differing only in context, i.e., it is more counterfactual-invariant.
Refer to caption: x11.png

#### Setup

We leverage synthetic tasks, where we can observe all the exogenous variables, and thus (i) empirically measure the degree of counterfactual invariance of a predictor; (ii) guarantee that $S$ has information about the exogenous variables generating $X$. We consider the issue of semantic leakage in LLMs []. This is a robustness problem where models generate text with semantic relationships to unrelated contexts in the prompts. For instance, when prompted with “He likes koalas. His favorite food is…”, gpt-4o-mini generates “eucalyptus salad”. Since the original tasks only contain information about the contexts, we define three binary exogenous variables $(U_{1},U_{2},U_{3})$ and use Claude 3.5 Sonnet [], a different model from the predictor, to generate one potential input for each value of context and exogenous noise $X(z,u_{1},u_{2},u_{3})$. We use three tasks proposed by Gonen et al., []: (1) $Z_{1}:$ “He likes {animal}”, $Y_{1}:$ “His favorite food is…” ; (2) $Z_{2}:$ “John likes {color}”, $Y_{2}:$ “John’s father is working as a…”; (3) $Z_{3}:$ “My friend likes to eat {food}”, $Y_{3}:$ “He works as a…”. We use the same set of exogenous variables for the three tasks.

We test standard, unbiased, and OOC prompting with predictors using gpt-4o-mini. To evaluate OOC’s ability to approach counterfactual invariance, we test it using $S$ with increasingly more knowledge about the exogenous variables: $U_{1},(U_{1},U_{2})$, and $(U_{1},U_{2},U_{3})$. We use the LLMs as deterministically as their APIs allow us to, i.e., fixing the seeds and using temperature 0 to force the potential predictions to be a deterministic function of $Z$ and the exogenous variables $\hat{y}(z,u_{1},u_{2},u_{3})$. This way, we can compute the counterfactual invariance probability of a predictor:
$\text{CI Probability}:=\nicefrac{{1}}{{\prod_{i}\mid\!{\mathcal{U}}_{i}\!\mid}
}\cdot\sum_{u_{1},u_{2},u_{3}}\prod_{z,z^{\prime}}\mathds{1}\{\hat{y}(z^{
\prime},u_{1},u_{2},u_{3})=\hat{y}(z,u_{1},u_{2},u_{3})\}$. We can interpret CI Probability as the proportion of groups of individuals differing only in context that get the same prediction.

#### OOC approaches counterfactual invariance through stratification

We see in Figure 4 that, as $S$ is defined with more exogenous variables, OOC’s CI Probability increases —more inputs only differing in context are assigned the same prediction. Moreover, implicit prompting provides more counterfactual invariance than standard prompting only in one task, while OOC with any conditioning set $S$ improves upon standard. Finally, we would like to highlight that OOC does not achieve probability of 1 and, as we see in the Food/Work task, it might not always monotonically increase. This is probably due to the LLM not perfectly approximating the conditional distributions of potential inputs needed in Definition 3. Note, however, that Section 5.1 showcased OOC’s practical improvements in stratified invariance, and here we see that, by making the stratification more fine-grained, we can also approach (not satisfy) individual notions of invariance at test time. *Overall, our results demonstrate that by conditioning on $S$, OOC can enhance population-level fairness and robustness in LLM predictions at test time, progressively approaching individual-level guarantees.*

## 6 Conclusions

We developed stratified invariance as a central notion of fairness and robustness in LLMs at test time. We showed how, unlike counterfactual invariance, it possesses a complete observational test and a valid counterfactual data augmentation procedure at test time. We then proposed to implement stratified counterfactual data augmentation with Out-Of-Context (OOC) prompting. Our empirical results demonstrated that OOC improves stratified invariance of LLM predictions in real-world tasks across models of different families and sizes. Finally, we empirically showed that OOC reflects a crucial theoretical notion of stratified invariance: as we condition on more exogenous variables generating $X$, we are more fair and robust at an individual (counterfactual invariance) level.

## Broader Impact

We hope that our theoretical analysis, together with its implementation in LLMs via OOC prompting, can safeguard users against biased, often discriminatory, predictions in a more explicit manner. However, due to an inherent external validity problem, we do not believe that an empirical evaluation of OOC is sufficient to allow for the use of LLMs in very sensible domains, e.g., making or enforcing public policies. Finally, we once again highlight the importance of the practical considerations we make in Section 3: a user has to always check if they believe those assumptions about the world and the model’s capabilities hold.

## Appendix A Proofs

## Appendix B Choosing S 𝑆 S italic_S as an adjustment set

Figure: Figure 5: Examples of causal DAGs for text generation/classification tasks with LLMs [].
Refer to caption: x12.png

How can we determine $S$ such that it is an adjustment set? It is known that, unless we make other assumptions or control the data-generating process, we cannot empirically test the validity of adjustment sets []. In practice, they are taken as causal assumptions from the user []. In this context, it becomes useful to define $S$ with graphical representations of causal models []. A causal DAG represents the known, or assumed, causal relationships between the variables of interest in our task. For instance, in Figure 5 (b,c) we can see DAGs where our input $X$ is generated from the context $Z$ and an independent, usually hidden, part $U$. In the anti-causal DAG (a) $X$ is also generated from the response variable $Y$, while in (b) and (c) $Y$ is generated from $X$. Moreover, all three DAGs contain some kind of unknown, non-causal, association between $Y$ and the context $Z$. This spurious dependence can come from an unobserved confounder (b), an observed collider (c), or either (a). We can identify $S$ in the DAGs of Figure 5 using the back-door criterion []. In the anti-causal DAG (a), we see that $S$ can be defined as $Y$, since it blocks the only non-causal path from $Z$ to $X$. Now, for the DAG (b), we note that $Y$ is a non-observed collider, and therefore it already blocks the existing non-causal path, i.e., $S:=\emptyset$. As for (c), the collider $B$ is observed, therefore the non-causal path is unblocked and we need to condition on $Y$, i.e., $S:=Y$.

## Appendix C Extended Related Work

Prompting strategies for LLMs. The impact of prompt design techniques significantly increased with the in-context learning capabilities presented in GPT-3 []. Since then, works have shown remarkable results when designing general techniques to improve the performance of LLMs. The most representative case is the one of zero-shot Chain-of-Thought (CoT) []: induce an intermediate reasoning step with “Let’s think step by step” and get a drastic improvement in the model’s performance. OOC prompting aims to be to fairness and robustness what CoT is to performance, i.e., a simple and yet powerful technique that boosts fairness and robustness in LLMs. Other relevant prompting algorithms that are not zero-shot but also focus on improving the model’s performance are automatic prompt tuning methods, e.g., DLN [], APE [], and other sophisticated in-context learning approaches [, ]. Our method is different from theses classes of prompting algorithms in that i) we are zero-shot and ii) we are not interested in boosting the model’s performance, but in boosting its fairness and robustness. Finally, we note that prompting techniques for tasks related to ours, such as diversity in generation [] and moral reasoning [] have been recently proposed. The work of Ma et al., [] is the closest to OOC since, in the same flavor of OOC, the authors also induce counterfactual generation as an intermediate step. However, the counterfactual generation is done for a different purpose and in a different manner, i.e., the authors explicitly ask for a counterfactual, instead of directly implementing the stratified counterfactual data augmentation from Definition 3.

## Appendix D Tasks from Section 5.2

Our tasks have the following variables:

- •
${\mathcal{Z}}_{1}:=\{\text{koalas},\text{rabbits},\text{mice},\text{monkeys}\}$, ${\mathcal{Y}}_{1}:=\{\text{cheese},\text{eucalyptus leaves},\text{bananas}\}$; ${\mathcal{Z}}_{2}:=\{\text{red},\text{green},\text{yellow}\}$, ${\mathcal{Y}}_{2}:=\{\text{biologist},\text{school bus driver}\}$; ${\mathcal{Z}}_{3}:=\{\text{pizza},\text{burgers},\text{foie grais}\}$, ${\mathcal{Y}}_{3}:=\{\text{federal judge},\text{truck driver}\}$.
- •
${\mathcal{U}}_{1}:=\{\text{``The person likes pineapple.''}$,
$\text{``The person's grandfather had a history of alcohol abuse.''}\}$,
${\mathcal{U}}_{2}:=\{\text{``The person's grandfather was born in Thailand.''}
,\text{``The person likes arts and crafts.''}\}$,
${\mathcal{U}}_{3}:=\{\text{``The person knows a criminal lawyer.''},$
$\text{``The person's grandfather had a vibrant personality.''}\}$.

We directly used the above to fill in OOC’s prompting parameters as in Appendix F.

## Appendix E Additional Results

**Table 1: OOC consistently reduces SI-bias ($\downarrow$) in gpt-3.5-turbo across tasks.**
|  | Clinical | Discrimination | Toxic Comments | Bios | Amazon |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| $Z$ | Employment | Race | Gender | Age | Gender | Race | Religion | Gender | Sentiment | $\downarrow$ Default |
| Default | $0.100$ | $0.080$ | $0.020$ | $0.060$ | $0.120$ | $0.180$ | $0.340$ | $0.160$ | $0.600$ | – |
| CoT | $0.060$ | $0.070$ | $0.020$ | $0.050$ | $0.220$ | $0.160$ | $0.340$ | $0.120$ | $0.240$ | 5/9 |
| Unbiased | $0.140$ | $0.050$ | $0.050$ | $0.120$ | $0.220$ | $0.180$ | $0.360$ | $0.184$ | $0.490$ | 2/9 |
| Precog | $0.180$ | $0.130$ | $0.060$ | $0.040$ | $0.080$ | $0.220$ | $0.180$ | $0.120$ | $0.480$ | 5/9 |
| Really4x | $0.060$ | $0.150$ | $0.080$ | $0.100$ | $0.120$ | $0.200$ | $0.400$ | $0.123$ | – | 2/8 |
| Illegal | $0.080$ | $0.080$ | $0.030$ | $0.060$ | $0.260$ | $0.180$ | $0.300$ | $0.123$ | – | 3/8 |
| Ignore | $0.080$ | $0.080$ | $0.060$ | $0.070$ | $0.180$ | $0.180$ | $0.300$ | $0.140$ | – | 2/8 |
| Illegal+Ignore | $0.060$ | $0.090$ | 0.000 | $0.060$ | $0.220$ | $0.200$ | $0.320$ | $0.163$ | – | 3/8 |
| OOC (ours) | 0.040 | 0.020 | $0.030$ | 0.020 | 0.060 | 0.120 | 0.060 | 0.102 | 0.190 | 8/9 |
|  | $\pm$ 0.000 | $\pm$ 0.009 | $\pm$ 0.004 | $\pm$ 0.009 | $\pm$ 0.001 | $\pm$ 0.006 | $\pm$ 0.007 | $\pm$ 0.019 | $\pm$ 0.003 |  |

**Table 2: OOC consistently reduces SI-bias ($\downarrow$) in gpt-4-turbo across tasks.**
|  | Clinical | Discrimination | Toxic Comments | Bios | Amazon | Better than |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| $Z$ | Employment | Race | Gender | Age | Gender | Race | Religion | Gender | Sentiment | Default |
| Default | $0.120$ | $0.040$ | 0.020 | $0.080$ | $0.060$ | $0.200$ | $0.180$ | $0.104$ | $0.220$ | – |
| CoT | $0.120$ | $0.050$ | 0.020 | $0.080$ | $0.060$ | 0.100 | $0.200$ | 0.083 | $0.080$ | 3/9 |
| Unbiased | 0.040 | 0.010 | $0.030$ | $0.080$ | $0.060$ | $0.160$ | $0.260$ | $0.125$ | $0.170$ | 4/9 |
| Precog | $0.120$ | $0.020$ | $0.040$ | $0.070$ | $0.060$ | $0.120$ | $0.200$ | $0.206$ | $0.100$ | 4/9 |
| Really4x | 0.040 | $0.040$ | 0.020 | $0.070$ | 0.040 | $0.120$ | $0.200$ | $0.125$ | – | 3/8 |
| Illegal | $0.060$ | $0.140$ | $0.060$ | 0.050 | 0.040 | $0.220$ | $0.240$ | $0.126$ | – | 3/8 |
| Ignore | 0.040 | $0.130$ | $0.080$ | $0.060$ | $0.060$ | $0.140$ | $0.200$ | $0.085$ | – | 4/8 |
| Illegal+Ignore | $0.060$ | $0.070$ | $0.080$ | 0.050 | $0.160$ | $0.200$ | $0.260$ | $0.147$ | – | 2/8 |
| OOC (ours) | 0.040 | $0.030$ | 0.020 | 0.030 | 0.040 | 0.100 | 0.100 | 0.083 | 0.030 | 8/9 |
|  | $\pm$ 0.000 | $\pm$ 0.010 | $\pm$ 0.007 | $\pm$ 0.006 | $\pm$ 0.009 | $\pm$ 0.004 | $\pm$ 0.004 | $\pm$ 0.012 | $\pm$ 0.008 |  |

**Table 3: OOC consistently reduces SI-bias ($\downarrow$) in LLAMA-3-70B across tasks.**
|  | Clinical | Discrimination | Toxic Comments | Bios | Amazon |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| $Z$ | Employment | Race | Gender | Age | Gender | Race | Religion | Gender | Sentiment | $\downarrow$ Default |
| Default | $0.200$ | $0.030$ | $0.030$ | $0.080$ | $0.140$ | $0.180$ | $0.240$ | $0.166$ | $0.070$ | – |
| CoT | $0.120$ | $0.040$ | $0.050$ | 0.050 | $0.240$ | $0.180$ | $0.160$ | $0.084$ | $0.040$ | 5/9 |
| Unbiased | $0.180$ | 0.000 | $0.090$ | $0.090$ | $0.100$ | $0.200$ | $0.260$ | $0.168$ | $0.050$ | 4/9 |
| Precog | 0.020 | $0.040$ | $0.050$ | 0.050 | $0.280$ | $0.160$ | $0.160$ | $0.148$ | $0.140$ | 5/9 |
| Really4x | $0.160$ | $0.020$ | $0.150$ | $0.060$ | $0.160$ | $0.220$ | $0.180$ | $0.247$ | – | 4/8 |
| Illegal | $0.160$ | $0.010$ | $0.120$ | 0.050 | $0.140$ | $0.260$ | $0.220$ | $0.248$ | – | 4/8 |
| Ignore | $0.120$ | $0.070$ | $0.060$ | $0.070$ | 0.080 | $0.180$ | $0.260$ | $0.207$ | – | 3/8 |
| Illegal+Ignore | $0.100$ | $0.060$ | $0.050$ | $0.060$ | 0.080 | $0.240$ | $0.280$ | $0.227$ | – | 3/8 |
| OOC (ours) | $0.200$ | $0.050$ | 0.020 | $0.060$ | $0.120$ | 0.080 | $0.220$ | 0.064 | 0.030 | 7/9 |
|  | $\pm$ 0 | $\pm$ 0.007 | $\pm$ 0.002 | $\pm$ 0.003 | $\pm$ 0 | $\pm$ 0.008 | $\pm$ 0.002 | $\pm$ 0.001 | $\pm$ 0.008 |  |

### E.1 OOC Across Different Scales

As the access to frontier LLMs increasingly faces monetary restrictions, it is natural to wonder whether OOC can improve SI-bias in smaller as well. Is it limited by stronger models’ capabilities? How does OOC interact with scale? To answer this, we replicated the experiments from Section 5.1 across the entire model family Qwen-1.5{ 4B,7B,14B,72B }. We chose CoT and Precog, the best performing strategies in Section 5.1 as representative baselines. In Figure 6 we observe that, in fact, OOC tends to improve stratified invariance almost uniformly across models of different sizes. This is not the case for CoT or Precog, highlighting that OOC should be the best prompting strategy for boosting stratified invariance across models of different, including smaller, sizes. Finally, in Figure 7 we show that OOC retains the original predictive of performance of LLMs across models of different sizes as well.

Figure: Figure 6: OOC reduces SI-Bias across different model sizes.
Refer to caption: x13.png

Figure: Figure 7: OOC preserves the model predictive performance across different model sizes.
Refer to caption: x14.png

## Appendix F Prompts

### Standard Prompts

### CoT

As usual, zero-shot CoT simply appends “Let’s think step by step” to the standard prompt of the task, generates a reasoning, and answers the question in a posterior step conditioning on the question, reasoning and “So the answer is:”.

### Implicit Safety Prompts

### OOC Prompts

**Table 4: OOC prompt parameters.**
| Dataset | Sampled Contexts (Z) | Z_description | S_description |
| --- | --- | --- | --- |
| Bios | [male, female] | Every direct or indirect<br>reference to the gender<br>(such as name) of the person | A passage from the<br>biography of a {S_lm} |
| Amazon | [positive, negative] | The sentiment expressed<br>in the review | A product review |
| Toxic Comments | [black, white, unknown] | Any racial information or<br>reference to a human race<br>in the comment | A {S_lm} comment made<br>on an online platform |
| [male, female] | Gender (even if implicitly<br>disclosed) of the people<br>mentioned in the comment | A {S_lm} comment made on<br>an online platform |  |
| [muslim, christian] | Every direct or indirect<br>mention to a religion in<br>the comment | A {S_lm} comment made on<br>an online platform |  |
| Discrimination | [20:30, 60:100] | Age of the person mentioned<br>in the question | A hypothetical decision<br>question |
| [black, white] | Race of the person mentioned<br>in the question | A hypothetical decision<br>question |  |
| [male, female] | Gender of the person mentioned<br>in the question | A hypothetical decision<br>question |  |
| Clinical Notes | [employed, unemployed,<br>unknown or undisclosed,<br>removed] | Patient’s social history and<br>any other mentions to their<br>work (or if they don’t have<br>one), including related<br>mentions to companies or<br>the act of working | Clinical notes of a<br>patient {S_lm} |

### Data Generation for Section 5.2

### CoT

As usual, zero-shot CoT simply appends “Let’s think step by step” to the standard prompt of the task, generates a reasoning, and answers the question in a posterior step conditioning on the question, reasoning and “So the answer is:”.

### Implicit Safety Prompts

### OOC Prompts

**Table 4: OOC prompt parameters.**
| Dataset | Sampled Contexts (Z) | Z_description | S_description |
| --- | --- | --- | --- |
| Bios | [male, female] | Every direct or indirect<br>reference to the gender<br>(such as name) of the person | A passage from the<br>biography of a {S_lm} |
| Amazon | [positive, negative] | The sentiment expressed<br>in the review | A product review |
| Toxic Comments | [black, white, unknown] | Any racial information or<br>reference to a human race<br>in the comment | A {S_lm} comment made<br>on an online platform |
| [male, female] | Gender (even if implicitly<br>disclosed) of the people<br>mentioned in the comment | A {S_lm} comment made on<br>an online platform |  |
| [muslim, christian] | Every direct or indirect<br>mention to a religion in<br>the comment | A {S_lm} comment made on<br>an online platform |  |
| Discrimination | [20:30, 60:100] | Age of the person mentioned<br>in the question | A hypothetical decision<br>question |
| [black, white] | Race of the person mentioned<br>in the question | A hypothetical decision<br>question |  |
| [male, female] | Gender of the person mentioned<br>in the question | A hypothetical decision<br>question |  |
| Clinical Notes | [employed, unemployed,<br>unknown or undisclosed,<br>removed] | Patient’s social history and<br>any other mentions to their<br>work (or if they don’t have<br>one), including related<br>mentions to companies or<br>the act of working | Clinical notes of a<br>patient {S_lm} |

### Data Generation for Section 5.2

### OOC Prompts

**Table 4: OOC prompt parameters.**
| Dataset | Sampled Contexts (Z) | Z_description | S_description |
| --- | --- | --- | --- |
| Bios | [male, female] | Every direct or indirect<br>reference to the gender<br>(such as name) of the person | A passage from the<br>biography of a {S_lm} |
| Amazon | [positive, negative] | The sentiment expressed<br>in the review | A product review |
| Toxic Comments | [black, white, unknown] | Any racial information or<br>reference to a human race<br>in the comment | A {S_lm} comment made<br>on an online platform |
| [male, female] | Gender (even if implicitly<br>disclosed) of the people<br>mentioned in the comment | A {S_lm} comment made on<br>an online platform |  |
| [muslim, christian] | Every direct or indirect<br>mention to a religion in<br>the comment | A {S_lm} comment made on<br>an online platform |  |
| Discrimination | [20:30, 60:100] | Age of the person mentioned<br>in the question | A hypothetical decision<br>question |
| [black, white] | Race of the person mentioned<br>in the question | A hypothetical decision<br>question |  |
| [male, female] | Gender of the person mentioned<br>in the question | A hypothetical decision<br>question |  |
| Clinical Notes | [employed, unemployed,<br>unknown or undisclosed,<br>removed] | Patient’s social history and<br>any other mentions to their<br>work (or if they don’t have<br>one), including related<br>mentions to companies or<br>the act of working | Clinical notes of a<br>patient {S_lm} |

### Data Generation for Section 5.2

### Data Generation for Section 5.2

## Peer Reviews

confidence: 5
contribution: 2
initial_rating: 5
presentation: 1
questions: 1. Could the authors provide concrete examples to better illustrate Definition 2 and Definition 3? Specific examples could clarify these definitions and their practical implications, helping readers understand the core concepts more intuitively. A worked example applying these definitions to a simple fairness scenario would help illustrate how they capture different aspects of fairness.

2. Could the authors offer intuitive justifications for Lemma 1 and Theorem 1? An explanation or reasoning beyond formal proofs would help make these results more accessible and easier to interpret.

3. Could the authors conduct comparative analyses with existing prompting approaches to contextualize the contributions and highlight relative advantages (see weakness section)?

4. Could the authors provide an in-depth discussion on how this work aligns with or differs from other fairness metrics?
soundness: 2
strengths: The theoretical development of Stratified Invariance and Stratified Data Augmentation is interesting. Also, by experimenting on both synthetic and real-world datasets, the authors demonstrate the advantage of the proposed prompting strategy to boost stratified invariance in LLM predictions at test time.
summary: This paper proposed stratified invariance, a stratified notion of debiasing, to capture a range of debiasing requirements from population level to individual level through an additional measurement that stratifies the predictions. The authors further propose Out-Of-Context (OOC) prompting, a zero-shot method that simulates stratified counterfactual data augmentations in LLM predictions.
weaknesses: While the paper’s introduction of "stratified invariance" is an interesting measure of fairness, it appears conceptually close to existing techniques in fair representation learning and causal fairness (e.g., statistical parity). It would be good if the authors could provide an in-depth discussion with other fairness metrics or write out the equations for comparison if this measurement is claimed as a novelty. It is also worth noting that the proposed metric and/or prompting strategy only works for decision tasks (i.e., the output is a discrete answer/decision). The paper also lacks discussions with other debiasing methods, particularly those leveraging causal inference, such as the causality-guided debiasing framework proposed by Li et al. (2024) and Si et al. (2023). The OOC prompting strategy is also very similar to the FACT strategy in Li et al. (2024): i.e., the transformation of the examples in Figure 1 is very similar to Figure 1 in  Li et al. (2024). It would also be nice to conduct comparative analyses with these existing prompting approaches to contextualize the contributions and highlight relative advantages. I am willing to increase my score if the authors could address these concerns.

- Li, Jingling, et al. "Steering LLMs Towards Unbiased Responses: A Causality-Guided Debiasing Framework." arXiv preprint arXiv:2403.08743 (2024).
- Si, Chenglei, et al. "Prompting gpt-3 to be reliable." arXiv preprint arXiv:2210.09150 (2022).

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: As detailed in comments in the section above.
soundness: 3
strengths: The strength of the paper comes from the clear presentation of the potential issue of directly applying certain causal fairness notions (especially ones that are related to counterfactual invariance) in the LLM context (Section 2), and the attempt to address this issue by proposing stratified invariance (Definition 1), which is a reasonable middle ground between the almost-sure-equality between potential outcomes (counterfactual invariance) and the distribution-level equality (referred to as intervention invariance in the paper). The theoretical presentation (Section 2) is relatively clear and not hard to follow, the OOC prompting design (Section 3) is guided by the theoretical analysis, and the empirical evaluations include how OOC improve stratified invariance, as well as how to approach counterfactual invariance through stratifications.
summary: The paper considers the test-time evaluation of fairness for LLMs. In particular, the paper aims to address the potential issue of naive applications of certain causal debiasing strategies (e.g., in terms of counterfactual data augmentations operating on the individual level), and proposes Stratified Invariance (Definition 1). The idea is to incorporate additional measurements at test time, so that stratified predictors can be constructed (for bias evaluation purposes). Prompting template and empirical results are presented.
weaknesses: The paper can be improved by (1) considering recent LLM debiasing strategies that do not specifically "rely on model's implicit understanding of bias" (lines 47 -- 49), so that the addressing of the existing LLM literature can be more comprehensive; (2) including discussion on the inference overhead of the proposed pipeline.

(1) recent LLM debiasing strategies that do not specifically rely on model's implicit understanding of bias

The paper presents criticisms of the existing LLM debiasing strategies in terms of the reliance on model's implicit understanding of bias (lines 47 -- 49). However, this might not be the case for recent LLM debiasing strategies. For instance, Li et al. (2024) consider a possible causal modeling of how LLM decisions are modulated by prompts, and proposed prompting-based strategies to encourage fact-based reasoning where no social category (e.g., gender, race) appears.  These strategies do not rely on model's understanding of bias. Considering them would help make the addressing of existing very relevant literature more comprehensive.

(2) discussion on the inference overhead of the proposed pipeline

Since the proposed approach (OOC prompting) involves multiple inference followed by a majority vote, it seems that the inference cost goes up pretty quickly. It would be important to discuss the relation between the inference overhead introduced by the proposed approach and the effectiveness of debiasing.

#### Reference

Li, J., Tang, Z., Liu, X., Spirtes, P., Zhang, K., Leqi, L., & Liu, Y. (2024). Steering LLMs Towards Unbiased Responses: A Causality-Guided Debiasing Framework. arXiv preprint arXiv:2403.08743.

---

confidence: 2
contribution: 2
initial_rating: 5
presentation: 2
questions: See questions above.
soundness: 3
strengths: - Originality:
    - Unlike previous works that used safety instructions to implicitly address the bias issue, this work leverages the causal invariance framework that utilizes interventions to obtain a less biased result.
    - This work also developed a stratified invariance notion that is built on observational data (random generations).
    - A novel OOC strategy is introduced to debias LLM predictions.

- Quality: 
    - The theoretical definition and analysis are introduced for stratified invariance which makes the design of OOC in principle.
- Clarity:
    - The clarity could be improved.
- Significance:
    - The proposed method evaluated on stratified invariance bias shows significant improvement, but it is unclear on other evaluation metrics.
summary: This paper considers the problem of LLM debiasing at the test time. By making use of causal invariance, the authors proposed a novel stratified invariance notion to address the limitation of standard conterfactual data augmentation. Besides, an out-of-context prompting strategy, inspired by stratified invariance, was proposed to demonstrate that the bias of LLMs can be reduced for real-world benchmarks.
weaknesses: - The presentation of this paper could be substantially improved. I tried very hard to understand this paper, but many things still remain unclear. I will list a few here:
    - Line 127-138 are helpful for understanding but they only appeared in the method section. I suggest the author can elaborate the problem and objective further in the introduction. 
    - Motivation of applying causal invariance in LLM debiasing is unclear.
    - It would be better if in Sec. 3 or before, a complete example in LLMs where the introduced variable can have some correspondence. I can only find such correspondence in Sec. 5.1.
    - Notation abusing makes some concepts confusing: e.g., what does "a.s." & "d" over = mean? in distribution?;  
    - typos: e.g., "predictins" in line 215
- Why does OOC perform less significant on LLAMA-3-70B? Is it because the possible obfuscation instructions are of low quality?
- To measure if your method successfully remove/reduce the bias, except for the stratified invariance you introduced, are there other bias evaluation metrics that you can use to demonstrate?

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: 1. Since the stratifying measurement or the adjustment set $S$ is important to the stratified invariance, can the authors clarify more in the paper how $S$ is typically chosen? I see in the experiments section that $S$ are usually the labels of the task, or empty set.
2. Could the authors clarify what does $S$ being an empty set mean? And how do they affect the context obfuscation/addition steps when it is an empty set?
3. It is assumed that the LLM can incorporate and generate a response containing the new context $z^+$ given the obfuscated input. Do you have empirical results on whether this is indeed the case? And how to test them practically, so that we can determine whether the proposed out-of-context will work with this LLM at test time?
4. It is unclear to me how to read Figure 2. More explanations should be provided.
5. The paper brings causal invariances to LLM inference. While it may be typical for causal invariances to consider classification tasks, it is not how typically LLMs are used in practice. How does the method extend to generative tasks for LLMs?
soundness: 3
strengths: 1. The motivations for the test-time fairness enhancement are well written, and the gaps in the current literature for counterfactual invariance are well discussed.
2. It provides a good analysis of the assumptions, and properly discusses them in the context of practical adoption.
3. The empirical experiments are well-designed to show the superior performance of OOC.
summary: The paper studies an important problem of ensuring better fairness and robustness of LLM during test time. It focuses on the notion of stratified invariance and advocates the adoption of a stratified data augmentation procedure at test time. The work further implements the procedure on LLMs through prompting (with specially designed role-playing prompts), and naming this strategy out-of-context (OOC) prompting. Extensive empirical validations are done to demonstrate that OOC improved the stratified invariance of LLM predictions and hence fairness in real-world datasets.
weaknesses: 1. While the authors adequately discussed the assumptions when adopting stratified data augmentation using OCC in the context of LLM, there is no explicit discussion on the limitation of the method in theory and in practice. For example, what are the implications when the assumptions do not hold?

Meta-review: This paper uses causal inference to achieve test-time fairness and robustness of LLMs. The paper proposes stratified invariance which provides a better measurement of biases of LLM-generated texts, and proposes a strategy to achieve stratified invariance.

The reviewers in general agree that the theoretical analysis and results are interesting and useful, and that the experiments are well designed and the results are promising.

During the rebuttal period, there were extensive discussions regarding comparisons with the related work of Li et al. (2024). In particular, both Reviewers Q4ph and 86wE pointed out this very related work and mentioned the similarities between the proposed methods from Li et al. (2024) and the current paper. For example, Reviewer Q4ph commented that there is a "conceptual alignment between context obfuscation/addition (from this work) and the 'demographic-agnostic fact'/'demographic-aware text' (from Li et al. (2024))". From what I have read in the discussions, this point was not explicitly clarified or acknowledged by the authors. For the healthy development of a field, I think it is important to clearly position the contribution of a work with respect to the prior works and provide fair and accurate descriptions and attributions to the contributions from the prior works. In addition, there are other concerns shared by multiple reviewers as well, for example, the clarity of presentation can be improved.

Given these concerns and also given that no reviewer would like to champion the paper, rejection is recommended.

Decision: Reject