Non-Parametric Regulatory Disparate Impact and Parity Audit Script
Author a forensic Python script to calculate statistical parity, disparate impact ratios, and bootstrap confidence intervals for compliance audits.
Use this template when conducting statistical fairness, pay equity, or algorithmic compliance audits under regulatory frameworks. It creates an automated Python script applying non-parametric bootstrapping and permutation testing.
Role: Lead Forensic Statistician and Regulatory Compliance Data Scientist.
Context
- Protected demographic variable: {{protected_attribute}}
- Regulated outcome metric: {{outcome_variable}}
- Statutory equity threshold: {{benchmark_threshold}}
- Input table structure: {{dataset_schema}}
- Control confounding factors: {{confounding_covariates}}
- Bootstrap sample size: {{resample_iterations}}
Task
Construct a comprehensive Python forensic audit script that calculates adverse impact ratios, performs non-parametric permutation tests, and computes bootstrap confidence intervals on {{outcome_variable}} across groups defined by {{protected_attribute}}.
Method
- Ingest input data conforming to {{dataset_schema}} using pandas with schema validation and type coercion.
- Compute empirical group summary distributions, cross-tabulations, and adverse impact ratios against {{protected_attribute}}.
- Evaluate the 4/5ths (80%) rule and custom {{benchmark_threshold}} statutory compliance metrics.
- Build a non-parametric bootstrapping engine with {{resample_iterations}} iterations to calculate 95% bias-corrected accelerated (BCa) confidence intervals.
- Execute two-sample permutation tests to determine exact non-parametric p-values without assuming normality.
- Fit a propensity-score or regression-stratified model controlling for {{confounding_covariates}}.
- Evaluate whether raw disparities remain statistically significant after conditioning on {{confounding_covariates}}.
- Generate a structured JSON audit artifact containing test statistics, odds ratios, and compliance flags.
Constraints
- Code MUST execute deterministically using configurable random seeds across all {{resample_iterations}}.
- The script MUST NOT rely on unstated asymptotic normality assumptions for small subgroup slices.
- Implement strict vectorized computations in numpy/scipy to optimize resampling loops.
- Output variables and summary keys MUST match exact regulatory terminology (e.g., adverse_impact_ratio, p_value, ci_lower, ci_upper).
Output format
Provide a production Python script containing:
- Input Data Contract & Validation Function (min 20 lines).
- Bootstrap & Permutation Testing Core Engine (min 45 lines).
- Covariate-Adjusted Disparity Analyzer incorporating {{confounding_covariates}} (min 30 lines).
- Report Dispatcher printing both formatted console tables and returning a structured dictionary.
Self-review
- Confirm that both raw and adjusted disparity measures are calculated and logged.
- Ensure {{resample_iterations}} is parameterized with a reasonable fallback for fast dry-runs.
- Verify vectorization prevents memory exhaustion during heavy bootstrap matrix expansion.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.