arXiv:2608.26335cs.DBAug 2026

Manuscript Offprint

arXiv:2608.26335

Realistic Counterfactual Explanations via Denial Constraints

Avia Asael, Nave Frost, Amir Gilad, Daniel Deutch

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

AVIA ASAEL, Tel Aviv University, Israel

DANIEL DEUTCH, Tel Aviv University, Israel

NAVE FROST, eBay Inc., Israel

AMIR GILAD, The Hebrew University of Jerusalem, Israel

In the realm of Explainable AI, classification results are often explained via counterfactuals (CFs for short), which are (ideally small) perturbations to an instance that lead to a change of classification label. Such CFs may serve as explanations for the prediction, pinpointing the features that were important. Existing explainability solutions typically aim at minimizing the distance of CFs from the original instance so that they are specific to it; and/or maximizing the diversity of CFs to cover multiple facets of the reasons underlying the prediction. In this paper, we note that in pursuing these aims, state-of-the-art explainability solutions may (and often do) yield counterfactual explanations that do not correspond to realistic instances. This limits their applicability and usefulness in practice. To remedy this, we combine ideas from Explainable AI with ideas from data management. Specifically, we capture realism of CFs via logical constraints that hold with respect to a dataset of examples (e.g. training set); the class of such constraints that we focus on is that of denial constraints, extensively studied in the context of relational databases. Algorithmically, we then combine explainable AI solutions to yield CFs, with ideas from data cleaning that we adapt to this unique setting, to transform CFs into realistic ones. Extensive experiments across four datasets validate that our solutions achieve realism with relatively minor compromise in terms of distance and diversity. They further validate that the dedicated optimizations that we have developed to speed up the search for CFs are indeed highly effective.

Additional Key Words and Phrases: Explainable AI, Counterfactuals, Denial Constraints

Resource Availability:

The source code of this paper has been made publicly available at https://doi.org/10.5281/zenodo.20271397.

1 Introduction

Counterfactuals (CFs) explain an ML prediction made by a given model for a given instance, through perturbations that yield a change to the assigned label. Intuitively, these perturbations pinpoint the features that were significant for the original prediction. Indeed, there is a large body of research on CFs, both in terms of modeling (which CFs are more useful for explainability) and in terms of algorithms (how to efficiently find highly useful CFs) [24, 26, 46].

Consider, for example, the NY Housing dataset [20], a snippet of which appears at the top of Figure 1. It includes information on real estate assets, such as their type, number of bedrooms/bathrooms, square footage, sublocality (i.e. neighborhood), etc. A natural classification task is to decide whether an asset's price exceeds 1M USD. If the model outputs "no" for a particular asset, CFs could identify reasons: perhaps the same asset in a different neighborhood would exceed 1M USD? Perhaps a slightly larger square footage would pass the bar? Etc. Among many applications, the availability of such explanations promotes transparency and accountability, and allows identifying bugs and biases in the model. [36, 46, 47]

To be useful, CFs should be in the proximity of the original instance: continuing our example, price estimates for very dissimilar assets are uninformative. They should also ideally be diverse: as exemplified above, there are many possible

Authors' Contact Information: Avia Asael, Tel Aviv University, Tel Aviv, Israel, aviaasael@mail.tau.ac.il; Daniel Deutch, Tel Aviv University, Tel Aviv, Israel, danielde@post.tau.ac.il; Nave Frost, eBay Inc., Netanyahu, Israel, nafrost@ebay.com; Amir Gilad, The Hebrew University of Jerusalem, Jerusalem, Israel, amirg@cs.huji.ac.il.

Avia Asael, Daniel Deutch, Nave Frost, and Amir Gilad

reasons for the classification, and diverse CFs could cover much of these grounds. Furthermore, they should be realistic: an explanation stating, for a Manhattan condo, that having 10 bedrooms would push the price over 1M USD is not very useful, if there are no 10-bedroom condos in Manhattan.

Several concrete notions for capturing proximity (i.e. distance functions) have been proposed, and the problem of finding CFs that optimize them has been extensively investigated [15, 36, 42, 47]. This in particular includes standard measures such as L0 (number of features that have changed) or L1 (magnitude of change), where a common variant normalizes per-feature change magnitudes before aggregation. Likewise, the problem of finding diverse CFs has been extensively studied [15, 36].

By contrast, capturing realism is much more subtle, and here there is a wide range of approaches ranging from restricting CFs to be members of an explicitly given dataset (e.g. the training set) to learning a complex model of what is realistic (see Section 6 for further discussion). Recent work [4], in a different context of adversarial Machine Learning, has proposed to capture realism via database constraints, and specifically Denial Constraints (DCs) [10]. Originally introduced to capture data integrity, these logical constraints were shown in [4] to strike a good balance between allowing for inference and correctly capturing realism. To illustrate, Table 1 shows example DCs for 3 standard ML benchmarks. The first two are unary DCs: they capture constraints, in the form of negated conjunctions, over individual tuples/instances, e.g. that no individual younger than 17 holds a Doctorate, or that Manhattan apartments do not have 10 or more bedrooms. The third is an example of a binary DC (universally quantified over pairs of tuples, rather than a single tuple), reflecting in this case that tax child exemption laws are consistent for individuals in every state. To capture realism of individual instances (in our case, of CFs), we can think of such binary DCs as a compact representation of many unary ones: given an instance, it will be realistic only if it matches the child exemption status of individuals with the same characteristics in the same state. Using DCs as our basis for capturing realism also has the advantage that their inference/mining from datasets has been extensively studied, and out-of-the-box solutions such as FastADC [48] may be employed.

Our work focuses on tabular data, the primary application domain for CF explanations [24, 46] and the setting of all major CF methods. A separate line of work studies CFs for images [23, 25], where realism is captured via generative or natural-image priors; our constraint-based notion is specific to relational data, and extending it to unstructured domains is left to future work.

In this paper, we study for the first time the problem of optimizing distance and diversity of CFs while constraining them to adhere to DCs. This combination has not been studied before (see Section 6 for related work overview); in particular, state-of-the-art solutions for diverse CFs such as DiCE [36] are agnostic to constraints and indeed often yield CFs that violate them (as we demonstrate in Section 5).

Algorithmically, finding realistic, diverse, and close CFs requires addressing several layers of complexity. First, even without realism constraints, generating optimal CFs is intractable unless P = NP for common model families such as Neural Networks and Random Forests [17]. Second, we show that projecting a tuple onto the space of realistic tuples (namely those consistent with a given set of DCs) is also intractable unless P = NP, even for unary DCs. Third, realism may, and often does, conflict with both the flip-of-label and with the diversity aims.

Our algorithmic solution is then a perturb-and-project framework that repeatedly iterates between perturbation, namely constraints agnostic CF generation (we incorporate DiCE [36], a state-of-the-art method for diverse CFs) and projection onto the space of DC-consistent tuples, which is essentially an optimization-under-constraints problem. A difficulty is that a straightforward use of optimizers such as SMT solvers [16] for the latter problem is prohibitively inefficient. This is due to two unique features in our setting: (1) we need to invoke the solver many times in a single

Table 1. Example Denial Constraints

DatasetExample Denial Constraint
Adult¬{t0.age<17∧t0.education=“Doctorate”}\neg \{t_{0}.age<17\land t_{0}.education=\text{“Doctorate”}\}
NY¬{t0.sublocality=“Manhattan”∧t0.beds≥10}\neg \{t_{0}.sublocality=\text{“Manhattan”}\land t_{0}.beds\ge10\}
Tax¬{t0.State = t1.State∧t0.HasChild = t1.HasChild∧t0.ChildExemp≠t1.ChildExemp}\neg \{t_{0}.State~=~t_{1}.State\land t_{0}.HasChild~=~t_{1}.HasChild\land t_{0}.ChildExemp\neq t_{1}.ChildExemp\}

execution of the CF-search solution. This is both because we look for multiple diverse CFs and because of the above mentioned conflict between realism and flip-of-label, requiring multiple iterations; (2) Binary DCs must be checked against each relevant tuple in the database, resulting in a large number of assertions for the solver to evaluate. We address this through several dedicated optimizations that we have developed: pre-processing and caching of solver instances; a dedicated constraint-pruning technique, inspired by works in data cleaning [12, 41], that identifies the relevant subset of database tuples (suspect set); and the incorporation of explicit diversity-based constraints to avoid redundant projections. The framework is model-agnostic: the projection step, our core contribution, treats the classifier as a black-box labeling oracle.

We have conducted an extensive experimental study over four standard benchmarks (Adult, NY Housing, Tax, and Census). Our results show that 55.9–100% of the CFs produced by DiCE violate Denial Constraints, while our solutions achieve zero violations, namely all CFs that we generate are realistic. This realism comes at only a modest cost: proximity and diversity degrade by under 10% and ~3% respectively on most datasets, compared to DiCE CFs. In terms of execution time, the constrained problem is naturally hard, and while a direct SMT-solver formulation is the natural exact approach, it does not scale with over 18,000 seconds for a single CF projection on Census. Our optimizations reduce that by up to 63× while preserving the same guarantees.

Summary of Main Contributions. Our main contributions are:

(1) We formalize the problem of generating diverse counterfactual explanations that adhere to Denial Constraints, combining for the first time the goals of proximity, diversity, and DC-based realism (Section 2).

(2) We develop a perturb-and-project framework with multiple solver optimizations, including constraint caching, suspect-set filtering, and diversity-aware projection (Sections 3–4).

(3) We show that the projection subproblem—finding the nearest DC-consistent tuple—is NP-hard (Section 4).

(4) We conduct an extensive experimental evaluation on four benchmarks, demonstrating that our approach eliminates constraint violations while maintaining proximity and diversity comparable to unconstrained baselines (Section 5).

References (9)