Skip to content
Latchkey

pre-commit ".pre-commit-config.yaml: mapping values are not allowed here" in CI

The YAML parser rejected .pre-commit-config.yaml before pre-commit validated it. "mapping values are not allowed here" almost always means bad indentation or an unquoted colon in a value.

What this error means

The run fails with a YAML scanner error naming a line and column in the config, such as "mapping values are not allowed here" or "could not find expected ':'".

YAML
while parsing a block mapping
  in ".pre-commit-config.yaml", line 5, column 7
mapping values are not allowed here
  in ".pre-commit-config.yaml", line 5, column 12

Common causes

Incorrect indentation under a list item

A hook key indented under the wrong level, or a mix of tabs and spaces, produces a mapping where the parser does not expect one.

An unquoted colon inside a value

A value containing : (like an args entry) that is not quoted confuses the YAML parser.

How to fix it

Fix indentation and quote colons

  1. Go to the line and column the parser named.
  2. Correct the indentation (spaces only) and quote any value containing a colon.
  3. Re-run so YAML parses cleanly.
.pre-commit-config.yaml
repos:
  - repo: https://github.com/psf/black
    rev: 24.4.2
    hooks:
      - id: black
        args: ["--line-length=88"]

Lint the YAML in CI

Add a YAML check so a parse error is caught with a precise location before pre-commit runs.

.github/workflows/ci.yml
- run: python -c "import yaml,sys; yaml.safe_load(open('.pre-commit-config.yaml'))"

How to prevent it

  • Use spaces, never tabs, in the config.
  • Quote any value that contains a colon.
  • Validate the YAML in CI before invoking pre-commit.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →