Declarative Causal Inference and Counterfactual Reasoning via SQL-Dialect Operators
Ronnit Peter, Suprio Ray, Moulay A. AkhloufiRelational databases power high-stakes decisions in lending, healthcare, and justice, yet SQL lacks native constructs for causal and counterfactual reasoning. Prior SQL-based causal systems address parts of this gap but do not unify treatment-effect estimation with counterfactual generation in a single, composable SQL surface. We present a system that extends the SQL dialect with two declarative operators: EXPLAIN_CAUSALLY_WHY (ψ) for estimating average and conditional treatment effects via meta-learners, and EXPLAIN_COUNTERFACTUAL (φ) for generating diverse, constraint-respecting alternatives via a hybrid KD-tree/LSH pipeline. Both operators consume standard SQL relations (joins, filters, projections) and return table-valued results with optional diagnostics, confidence intervals, and feasibility metrics. We formalize the operators in relational algebra, and describe our prototype system called PsiQL. On four evaluation datasets, PsiQL recovers a protective TWINS treatment effect, returns a non-significant COMPAS point ATE with imbalance diagnostics, flags HMDA covariate imbalance via built-in SMD checks, and generates constraint-respecting counterfactuals; a synthetic Census run serves as a balanced pipeline proof-of-concept alongside a real ACS diagnostic under severe imbalance.