pre-commit "check-yaml...Failed" in CI
The pre-commit check-yaml hook loads every staged YAML file. When one does not parse, the hook prints "Failed" with the parser error and the file, and the run exits non-zero.
What this error means
pre-commit output shows "check-yaml...............Failed" followed by the YAML parse error and the offending filename.
check-yaml...............................................................Failed
- hook id: check-yaml
- exit code: 1
config.yaml: could not determine a constructor for the tag '!Ref'
mapping values are not allowed here
in "config.yaml", line 6, column 12Common causes
A genuine YAML syntax error
A tab, bad indentation, an unquoted colon, or a duplicate key stops the parser, exactly as it would in any consumer.
Custom tags the loader rejects
CloudFormation !Ref/!GetAtt or other custom tags fail the default safe loader unless --unsafe is set to allow syntax-only checking.
How to fix it
Fix the reported YAML
- Open the file at the line:column in the hook output.
- Correct the syntax (quote colons, remove tabs, dedupe keys).
- Re-run
pre-commit run check-yaml --all-files.
pre-commit run check-yaml --all-filesAllow custom tags with --unsafe
For CloudFormation and similar custom tags, pass --unsafe so check-yaml validates syntax without resolving the tags.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
args: [--unsafe]How to prevent it
- Run pre-commit locally so YAML errors never reach CI.
- Use
--unsafeonly for files with legitimate custom tags. - Pair check-yaml with yamllint for style plus syntax.