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
Arguments
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.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.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
- Human-readable
- JSON report
When Invalid output:
--json is not passed, the script prints valid on success, or invalid followed by a bullet list of error messages on failure.Valid output:Validation behavior
JSON parsing
Files are read withencoding="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 thejsonschema 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
Whenjsonschema is not installed, the script uses an internal strict validator that supports the following JSON Schema keywords:
| Supported keyword | Notes |
|---|---|
$schema | Recognized but not evaluated |
title / description | Recognized but not evaluated |
type | Checked for object, array, string, integer, number, boolean, null |
required | All listed keys must be present |
properties | Recursively validated for keys present in the instance |
additionalProperties | false rejects any key not listed in properties |
const | Exact equality check |
enum | Membership check |
minimum | Numeric lower bound (inclusive) |
items | Applied to every element of an array |
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
| Code | Meaning |
|---|---|
0 | All supplied files are valid |
1 | At least one file is invalid, or a file could not be read |