yamale: Schema-Validate YAML in CI
yamale -s schema.yaml data.yaml validates YAML against a Yamale schema and exits non-zero on any validation error.
Yamale is a Python YAML schema validator with a compact schema syntax (str(), int(), enum(), list()). It is a lightweight way to gate YAML config in CI.
What it does
yamale reads a schema written in its own concise DSL (fields typed as str(), int(min=1), enum(...), list(...), map(...), and so on), validates one or more YAML data files against it, and reports each violation with its path. It exits non-zero when validation fails.
Common usage
pip install yamale
# validate a data file against a schema
yamale -s schema.yaml data.yaml
# validate every YAML in a directory
yamale -s schema.yaml ./config/
# choose the YAML parser explicitly
yamale -s schema.yaml -p ruamel data.yamlOptions
| Flag | What it does |
|---|---|
| -s <file> | Schema file to validate against |
| -p, --parser pyyaml|ruamel | YAML parser backend |
| -n, --no-strict | Allow undefined extra keys |
| --no-schema | Skip loading; treat all files as data (rare) |
In CI
yamale exits non-zero on the first invalid file, so a plain yamale -s schema.yaml config/ step fails the build on a bad config. Keep strict mode on (the default) so unexpected keys are caught; add -n only when the schema intentionally allows extra fields.
Common errors in CI
A failure prints Error validating data 'data.yaml' with schema 'schema.yaml' then lines like port: 'abc' is not a int. or env: 'staging' not in ('dev', 'prod'). name: Required field missing flags a missing required key. Unexpected element appears in strict mode for an undefined key. Invalid schema expression means the schema DSL itself has a typo.