pymaiml.validation¶
validation ¶
pymaiml.validation¶
Validates a MaiML (JIS K 0200 / MaiML-Schema-1_0) file against:
- The official XSD schema (well-formedness, element/attribute cardinality and order, id/IDREF resolvability, xsi:type <-> content model consistency, UUID string format, etc).
- Supplementary business rules from the MaiML AI Common Specification that XSD alone cannot express (ref-target element-type checks, the lifecycle "complete" event bookkeeping, XES namespace exact-URI binding, the "layer-1 elements must never be concealed by EncryptedData" rule, chain/parent structure, file extension/encoding conventions).
This is a library-friendly port of the same checks used by the maiml-schema-validator Claude skill's validate_maiml.py, restructured around a ValidationResult object instead of argparse + stdout, so any Python code (a CI step, another pymaiml module, a notebook) can call it directly:
from pymaiml.validation import validate
result = validate("sample.maiml")
if not result.ok:
for finding in result.errors:
print(finding)
The official schema files (MaiML-Schema-1_0) are bundled under pymaiml/schema/MaiML-Schema-1_0/ so validation works offline with zero configuration; pass schema_dir= to point at a different schema version.
Known gap vs. the full JIS K 0200 specification (documented, not silently skipped): XML digital signature cryptographic verification, full Petri-net reachability simulation of the material->operation->result flow (the "complete" event check here is a simplified file-wide presence check, not a per-instruction trace), cross-file UUID consistency, and thesaurus (Annex A/B) vocabulary conformance for key= values. See the skill's reference/maiml_validation_rules.md for the full rationale if/when those need porting too.
ValidationResult
dataclass
¶
validate ¶
validate(path: Union[str, Path], schema_dir: Optional[Union[str, Path]] = None) -> ValidationResult
Validate a .maiml / .maiml.zip / .mai file.
schema_dir defaults to the MaiML-Schema-1_0 bundled with pymaiml (pymaiml/schema/MaiML-Schema-1_0/). Pass a different directory to validate against another schema version.