Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/xxyoudeadpunkxx/canon-boundary-guard-for-gpt-project/llms.txt

Use this file to discover all available pages before exploring further.

validate_state.py is an optional Python utility that mechanically validates SESSION_STATE and CANON_STATE_DELTA files against their schemas. It uses jsonschema when available and falls back to a strict manual validator when the package is not installed. It does not decide provenance — it only performs structural checks.
This is a mechanical helper only. A file that passes validation is structurally correct, but structural correctness does not mean the state accurately reflects what was inspected or authorized. Provenance decisions remain the operator’s responsibility.

Usage

# Validate a SESSION_STATE file
python validate_state.py --state SESSION_STATE.json

# Validate a CANON_STATE_DELTA file
python validate_state.py --delta CANON_STATE_DELTA.json

# Validate both files in one invocation
python validate_state.py --state SESSION_STATE.json --delta CANON_STATE_DELTA.json

# Emit a machine-readable JSON report
python validate_state.py --state SESSION_STATE.json --json

Arguments

--state
path
Path to a SESSION_STATE.json file to validate. The file is read as UTF-8 (with BOM handling) and validated against SESSION_STATE.schema.json. At least one of --state or --delta must be provided.
--delta
path
Path to a CANON_STATE_DELTA.json file to validate. The file is validated against CANON_STATE_DELTA.schema.json and an additional cross-field check confirms that current_state.state_seq equals delta.seq. At least one of --state or --delta must be provided.
--json
flag
Emit a JSON report ({"valid": true/false, "errors": [...]}) instead of human-readable output. Useful for programmatic consumption in CI pipelines or pre-save hooks.

Output

When --json is not passed, the script prints valid on success, or invalid followed by a bullet list of error messages on failure.Valid output:
valid
Invalid output:
invalid
- SESSION_STATE.active_l0_sources[0]: missing required key: source_type
- SESSION_STATE: current_state.state_seq should equal delta.seq (2 != 3)

Validation behavior

JSON parsing

Files are read with encoding="utf-8-sig", which silently strips a UTF-8 BOM if present. Files that cannot be parsed as valid JSON produce an error entry and fail immediately without proceeding to schema validation.

jsonschema path

When the jsonschema package is importable, the script uses jsonschema.Draft202012Validator to perform full JSON Schema Draft 2020-12 validation. This path supports the complete schema feature set and produces error messages rooted at the path of each failing node.

Strict manual fallback

When jsonschema is not installed, the script uses an internal strict validator that supports the following JSON Schema keywords:
Supported keywordNotes
$schemaRecognized but not evaluated
title / descriptionRecognized but not evaluated
typeChecked for object, array, string, integer, number, boolean, null
requiredAll listed keys must be present
propertiesRecursively validated for keys present in the instance
additionalPropertiesfalse rejects any key not listed in properties
constExact equality check
enumMembership check
minimumNumeric lower bound (inclusive)
itemsApplied to every element of an array
Any schema keyword outside this set causes the validator to return an error for that node rather than silently skipping the check. This is the fail-closed behavior: an unknown schema feature is treated as a validation failure, not as a pass-through.

Additional cross-field check (CANON_STATE_DELTA)

After schema validation, the script performs one cross-field check that is not expressible in JSON Schema: current_state.state_seq must equal delta.seq. If they differ, a validation error is appended even if the document is otherwise schema-valid.

Exit codes

CodeMeaning
0All supplied files are valid
1At least one file is invalid, or a file could not be read

Schema paths

The script resolves schema files relative to its own location:
scripts/validate_state.py
schemas/SESSION_STATE.schema.json    ← ../schemas/SESSION_STATE.schema.json
schemas/CANON_STATE_DELTA.schema.json ← ../schemas/CANON_STATE_DELTA.schema.json
The script must be run from inside the bundle directory tree. If the schema files are not found at the expected relative paths, the script will fail with a file-not-found error rather than falling back to a permissive validator.

Build docs developers (and LLMs) love