K kynetra.dev / KynML
Docs Schema Validation

Schema Validation

KynML can preflight local CSV data before generating or running PyTorch. This catches the failures that otherwise appear late in training: missing files, missing target columns, feature-count drift, and bad classification labels.

Commands

kynml schema examples/house_price.kyn
kynml validate examples/house_price.kyn --data
kynml compile examples/house_price.kyn --out generated/house_price.py --check-data
kynml train examples/house_price.kyn --check-data
kynml sweep specs/model.kyn --check-data

schema and --check-data resolve imports and params before checking data, so the contract matches the same compiled program that codegen sees.

What It Checks

Check Why it matters
CSV path resolution Uses the same project-root-first, source-file-dir fallback as generated PyTorch.
Target column exists Prevents runtime ValueError from the generated data loader.
Dataset has rows and feature columns Prevents empty training tensors.
Encoded feature count equals input N Catches drift after adding/removing CSV columns or categorical values.
Multiclass labels are integer ids in range Prevents cross_entropy / nll targets from exceeding final dense output width.
Binary labels are numeric and in [0, 1] Keeps bce targets aligned with sigmoid output.

Output

Dataset | Rows | Raw features | Encoded features | Model input | Target | Path
--- | ---: | ---: | ---: | ---: | --- | ---
HouseData | 20 | 10 | 10 | 10 | price | /path/to/data/housing.csv

Raw features is the CSV column count after dropping the target. Encoded features is the width after pandas.get_dummies, matching what the generated training script feeds into PyTorch.

Design Notes

Schema validation is opt-in. Normal parse/semantic validation stays lightweight and does not read data. Use --data or --check-data when the source file should be validated against concrete local CSV files.

The implementation lives in kynml/schema.py and raises KynMLSchemaError, a semantic error subtype, so existing CLI error handling reports failures as KynMLError: ....