The @explain annotation enables generating detailed explanations for derived facts, helping to understand their provenance and the rules applied. Explanations can be presented in structured JSON format, natural language, or refined reports via LLM, enhancing transparency and aiding debugging.

Materializing Explanations to External Data Sources

The @explain annotation configures how the explanations are stored. Its syntax is as follows:
The explanations storage format varies based on the selected datasource. To CSV:
To PostgreSQL:
To console:

Explanation Output Structure

The explanation output has three fields:
  • Fact — the derived fact being explained.
  • JsonExplanation — a hierarchical JSON representation of the fact’s derivation.
  • TextualExplanation — a natural language explanation based on model annotations or default verbalization.
Example:

Json Explanation Example

Textual Explanation Examples

Without Model Annotations In the absence of model annotations, the explanation uses fact:
With Model Annotations With model annotations, explanations become more informative and context-specific:
Refined explanation:

Explanation Scenarios and Use Cases

Example 1: Linear Rule Explanation without Model Annotations

Prometheux generates a generic explanation:

Example 2: Linear Rule Explanation with Model Annotations

Prometheux generates the explanation verbalizing facts according to the specified models:

Example 3: Join Rule Explanation

Prometheux generates the explanation verbalizing facts according to the specified models:

Example 4: Explaining Pre-Materialized Chase Results

By setting chase=false, Prometheux exploits a pre-materialized chase data for explanations, avoiding recomputation. Explanations are related to the predicates specified in the @output annotation. To explain specific predicates not in @output, use the predicates='predicate1,predicate2' option. Chase Materialization:
Explanation of Pre-Materialized Data:
Prometheux generates the following explanation:

Example 7: Explaining Multiple Connected Chases

Multiple chases are connected by using the results of the first in the second. Model annotations provide detailed descriptions for each predicate. Explanations are generated for both path and tc predicates. By setting chase=false, explanations are generated based on pre-materialized chase data. The predicates=‘path,tc’ option specifies the predicates to explain, especially if they are not in @output. Prometheu will generate comprehensive explanations that cover derivations across multiple connected chases. Step 1: First Chase - Computing Transitive Closure
Step 2: Second Chase - Computing Paths Using Previous Results
Step 3: Explaining the Combined Results