LangFair: A Python Package for Assessing Bias and Fairness in Large Language Model Use Cases
Dylan Bouchard, Mohit Singh Chauhan, David Skarbrevik, Viren Bajaj, Zeya Ahmad
TL;DR
Large Language Models exhibit bias in prompt-dependent contexts, making model-wide metrics insufficient for real-world safety and fairness. LangFair provides a prompt-aware, output-based evaluation framework that accommodates task-specific risks through a BYOP approach. It offers dataset generation utilities (ResponseGenerator, CounterfactualGenerator) and a modular metrics suite spanning toxicity, stereotypes, counterfactual fairness, and classification, plus AutoEval for semi-automated assessments. These capabilities support governance audits and practical fairness assessments in diverse LLM use cases.
Abstract
Large Language Models (LLMs) have been observed to exhibit bias in numerous ways, potentially creating or worsening outcomes for specific groups identified by protected attributes such as sex, race, sexual orientation, or age. To help address this gap, we introduce LangFair, an open-source Python package that aims to equip LLM practitioners with the tools to evaluate bias and fairness risks relevant to their specific use cases. The package offers functionality to easily generate evaluation datasets, comprised of LLM responses to use-case-specific prompts, and subsequently calculate applicable metrics for the practitioner's use case. To guide in metric selection, LangFair offers an actionable decision framework.
