Skip to content

Graph validation and diagnostics

Graph validation checks that a definition can form a usable graph: its root exists, its references connect the right records, and its nodes, conditions and outputs meet the supported contracts. Run it when a definition changes, before your application makes that version available to people. A rejected definition is much easier to repair at that point than when someone is already trying to navigate it.

The loaders perform validation while constructing a Graph. The CLI lets you check the same kind of definition earlier, as part of editing or publication, and receive a diagnostic without starting a session.

We will reuse the learning-choice graph from Anatomy of a graph. Node 10 asks how the person wants to learn. Edge 101 leads to the guide at terminal 20; edge 102 leads to practice at terminal 30 when practiceEnabled is true.

In this deliberately broken copy, the second edge points to 300:

{
"id": 102,
"from": 10,
"to": 300
}

This is an extract from edges, not a complete definition. The node records still contain only 10, 20 and 30. JSON can represent that number perfectly well, but the engine cannot navigate to a node that the graph does not define.

From your project directory, check the downloaded file with the installed CLI:

Terminal window
vendor/bin/execkernel validate learning-path-invalid.json --json

validate requests strict definition validation. --json returns structured information that an editor or publication step can read. The command exits with status 1. Its relevant response fields are:

{
"ok": false,
"error": {
"ek_code": "EK-SEC-LOD-001",
"severity": "fatal",
"message": "Edge con referencias inválidas.",
"context": {
"edge_id": 102,
"from": 10,
"to": 300,
"validation_ek_code": "EK-GRAPH-010"
}
}
}

The message means that an edge has invalid references. For this loading path, EK-SEC-LOD-001 reports the rejected graph structure; validation_ek_code preserves the underlying reference-validation code, EK-GRAPH-010. Keep both when recording a diagnostic. The context provides the useful coordinates for the repair: find edge 102, then compare its endpoints with the node IDs.

Here, from: 10 is valid and to: 300 is not. Changing a label would only change what your application displays; it would not repair the destination.

The intended destination already exists as terminal 30. Replace the edge record with:

{
"id": 102,
"from": 10,
"to": 30
}

The edge keeps its identity, so its label and condition remain associated with edge 102. Only the destination changes.

Run the same validation command after saving the correction:

Terminal window
vendor/bin/execkernel validate learning-path-invalid.json --json

It now exits with status 0. These response fields show what was accepted:

{
"ok": true,
"summary": {
"nodes": 3,
"edges": 2,
"terminal_nodes": 2,
"warnings": 0
},
"data": {
"warnings": []
}
}

The complete corrected definition is also available for comparison. In your publication step, a nonzero exit status should keep the changed definition out of use and send the diagnostic back to the person editing it. After a successful check, your application can load the accepted definition through its graph loader or repository.

Validation stops when a rule rejects the definition. Correct the reported problem and run it again: the next pass may reveal another issue that the first failure prevented it from reaching.

A valid reference is only one part of a coherent definition. The checks also cover matters such as duplicate IDs, missing roots, presentation records attached to nonexistent elements, invalid rule parameters, and graph topology that cannot provide a usable path to a terminal.

Choose the CLI operation according to what you need to inspect:

Operation What it helps you decide
validate graph.json --json Whether the definition passes strict validation before you put it into use.
lint graph.json --json Which additional static warnings deserve attention while editing. A successful response may still contain warnings.
explain graph.json --lang=en --json Whether the loaded nodes, destinations, labels and conditions describe the graph you intended to write.

For the repaired example, explain places edge 102 under node 10, with destination 30 and the condition on practiceEnabled. That makes it useful when the file is valid but a choice appears to lead to the wrong place. It describes the definition; it does not evaluate that condition for a particular person’s session.

Read data.warnings as well as ok. Warnings carry a message and may include a rule and context. Your application’s publication policy can require an editor to resolve or review them even when the command succeeds. Keep validate as the acceptance check; a clean-looking lint or explain response is not a substitute for it.

What remains your application’s decision

Section titled “What remains your application’s decision”

Validation can establish that edge 102 has an existing destination and a supported condition. It cannot decide whether practice should be available to a particular person, whether the guide contains the right material, or whether the application’s final screen satisfies the intended process.

Check those requirements with representative application contexts and the resulting choices and terminal outputs. For this example, that includes confirming the experience with practiceEnabled both true and false. Structural validation gives that application-level check a coherent definition to work with.