Out-Of-Context Prompting Boosts Fairness and Robustness in Large Language Model Predictions

Leonardo Cotta, Chris J. Maddison · DOI

Introduction

Large Language Models (LLMs) are increasingly integrated into decision-making pipelines, yet they remain susceptible to "spurious correlations." For instance, a model might associate the profession of "nurse" primarily with women or "doctor" with men due to biases inherent in its training data. While fine-tuning or retraining can mitigate these issues, such processes are often prohibitively expensive for end-users.

Existing test-time interventions typically rely on "safety prompts"—explicit instructions like "Please ensure your answer is unbiased." However, these methods are often inconsistent and rely on the model's internal, subjective interpretation of fairness. This research introduces Out-Of-Context (OOC) prompting, a zero-shot technique designed to enforce fairness and robustness by explicitly decoupling protected attributes from the decision-making context.

The OOC Prompting Framework

The core of OOC prompting is the pursuit of counterfactual invariance: the principle that a model's output should remain identical regardless of changes to protected attributes (e.g., changing a name from "John" to "Mary"). To achieve this practically, the researchers propose a two-step "obfuscate and replace" strategy.

Figure 1: Comparison of standard prompting, safety instructions, and the proposed OOC prompting mechanism.

The Two-Step Process

  1. Obfuscation: The LLM is first prompted to rewrite the input text to hide or neutralize the protected attribute. For example, gendered pronouns like "his" are replaced with neutral terms like "their," and specific names are removed.
  2. Addition and Randomization: The model then takes the obfuscated text and re-inserts a randomly sampled version of the attribute. By generating multiple variations (e.g., one where the subject is male and another where the subject is female) and taking a majority vote, the final prediction is effectively shielded from the original bias.

This process is formalized in Algorithm 1, which outlines the iterative sampling and aggregation strategy used to reach a fair consensus.

Figure 2: The formal OOC prompting strategy algorithm.

Theoretical Foundation: Stratified Invariance

To bridge the gap between theoretical counterfactual fairness and practical implementation, the authors introduce Stratified Invariance. This concept suggests that while perfect individual-level invariance is difficult to measure, we can achieve a robust middle ground by stratifying predictions based on available measurements. As more detail is added to these strata, the model's behavior converges toward true counterfactual fairness.

Experimental Evaluation

The researchers evaluated OOC prompting across six diverse benchmarks, including:

  • CivilComments: Detecting toxicity while avoiding bias against race or religion.
  • Bios: Predicting occupations based on gendered biographies.
  • Discrimination: High-stakes synthetic decisions like credit approval.
  • MIMIC-III: Clinical note analysis ensuring employment status does not skew medical predictions.

The method was tested across various model families, including GPT-3.5, GPT-4, Llama-3, and the Qwen-1.5 series (ranging from 4B to 72B parameters).

Key Findings

  • Superior Fairness: OOC prompting improved fairness (measured by reduced SI-bias) in 23 out of 27 tested scenarios. It achieved the lowest bias scores in 20 of those settings, outperforming standard safety prompts and Chain-of-Thought (CoT) methods.
  • Robustness vs. Safety Prompts: Standard safety instructions were found to be highly inconsistent, sometimes even increasing bias or significantly degrading accuracy. In contrast, OOC prompting maintained high predictive performance, with Macro F1 score drops generally staying below 0.05.
  • Scalability: The benefits of OOC prompting were consistent across model sizes, suggesting that the technique scales effectively as LLM capabilities grow.

Conclusion and Future Work

OOC prompting demonstrates that explicit structural intervention—physically removing and randomizing biased attributes—is far more effective than implicit instructions. While the method is more computationally expensive due to the multiple rewriting and sampling steps, it provides a powerful, zero-shot tool for developers who require fair outputs without the ability to retrain underlying models.

Future research aims to automate the discovery of protected attributes, allowing OOC prompting to be applied even in complex scenarios where the specific sources of bias are not immediately obvious to the user.

Summary updated

BibTeX
@article{cotta2025out,
  author = {Leonardo Cotta and Chris J. Maddison},
  title = {{Out-Of-Context Prompting Boosts Fairness and Robustness in Large Language Model Predictions}},
  journal = {Accepted by TMLR},
  year = {2025},
  url = {https://openreview.net/forum?id=1fML4VF5FG},
}
Figure