Skip to content
Latchkey

YAML "did not find expected key" error in CI

The YAML parser was reading a mapping and, at the reported line, expected the next key: but found content at the wrong indentation instead. It reports "did not find expected key".

What this error means

A YAML load fails with "did not find expected key" and a line:column. The surrounding block has mismatched indentation between siblings.

YAML
yaml: line 10: did not find expected key

Common causes

A sibling key indented differently from its neighbors

One key in a mapping is off by a space, so the parser cannot align it as a sibling and reports a missing key.

A list item indented under a scalar value

A - item placed where a key was expected (because indentation drifted) breaks the mapping structure.

How to fix it

Align sibling keys to the same column

  1. Open the file at the reported line and inspect the indentation of nearby keys.
  2. Make every sibling key start at the exact same column.
  3. Re-run the loader or yamllint to confirm.
deployment.yaml
# wrong: 'image' is indented one space too far
spec:
  containers:
    - name: app
       image: nginx
# right
spec:
  containers:
    - name: app
      image: nginx

Lint indentation before CI

yamllint's indentation rule catches the misalignment that produces this parser error.

Terminal
yamllint deployment.yaml

How to prevent it

  • Keep a strict, consistent indentation step (2 spaces).
  • Never use tabs in YAML.
  • Run yamllint in a pre-commit hook.

Frequently asked questions

What causes ""did not find expected key""?
One key in a mapping is off by a space, so the parser cannot align it as a sibling and reports a missing key.
How do I fix "did not find expected key"?
Align sibling keys to the same column

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card