Skip to main content
DevOps Insightsguides & answers

YAML · troubleshooting

yaml: did not find expected key

A line inside a block is indented differently from the keys around it, so the parser cannot place it. The line number usually points at the line before the real mistake, which is why the error is hard to see.

Reproduced on Helm 3.18.2, . Where the text says “reproduced”, the behaviour was run on that version, not taken from documentation.

First published

New to this? Read what is actually happening first, then come back to the steps.

On this page · 8 sections

Before you start

  • The file and the line number from the message.

Run this first

step 1 of 1
python3 -c 'import sys,yaml; yaml.safe_load(open(sys.argv[1]))' FILE

Look for expected <block end>, but found ... in "FILE", line N, column M

PyYAML, if installed, names the line and column of the mistake itself.

Work out which cause you have

A few questions to narrow the list. Every answer ends in a command that confirms or rules the cause out — this cannot see your cluster, so nothing here is a certainty until you have checked.

Narrow it down

0 answered · nothing is sent anywhere

Which message is it?

Cause space

3 of 3 still possible

  • A key is one or more spaces out of line with its siblingsCommon
  • A list item is missing its dash, or a key sits at the dash's indentCommon
  • A quote that is never closedOccasional

Nothing ruled out yet. Answer the question above and the branches your answer eliminates will strike through here.

Or diagnose it manually

In this order. The first command usually contains the whole answer.

  1. Step 1

    python3 -c 'import sys,yaml; yaml.safe_load(open(sys.argv[1]))' FILE

    PyYAML, if installed, names the line and column of the mistake itself.

    Look for expected <block end>, but found ... in "FILE", line N, column M

Every cause, and how to fix it

Ordered by how often each one turns out to be the answer.

A key is one or more spaces out of line with its siblings

Common

Usually a hand edit or a paste that added or removed a space at the start of one line.

Confirm

cat -et FILE | sed -n 'N,+3p'

On the line after N, a key starting in a different column (cat -A on Linux)

Fix

  • Align it with the other keys of the same block.

A list item is missing its dash, or a key sits at the dash's indent

Common

After - name: http, a key at the column of the dash is read as a new list item without its dash.

Confirm

sed -n 'N,+3p' FILE

A key lined up with the - of the item above

Fix

  • Indent it to line up with name (part of the same item), or start a new item with - .

A quote that is never closed

Occasional

An opening " or ' without its partner swallows the rest of the file, and the parser reports the end of the stream.

Confirm

grep -nE '^[^#]*: *"[^"]*$' FILE

A value that opens a double quote and never closes it

Fix

  • Close the quote, or escape the quote character inside the value.

Understanding it properly

Skip this if you are mid-incident — the working part of the page is above. Worth reading afterwards, because understanding the mechanism is what stops the next one.

In plain terms

YAML uses indentation to say which key a line belongs to. All keys of one block must start in the same column. A key one space to the left or right, or a list item missing its dash, leaves the parser expecting something it does not find.

Words used on this page

Block
A group of keys at the same indentation, belonging to the key above them.
'-' indicator
The dash that starts each item of a list.
What is actually happening

Reproduced with Helm 3.18.2: tag: indented one space less than repository: printed yaml: line 2: did not find expected key, although the bad line was line 3. memory: indented one space less than cpu: printed line 3 for a mistake on line 4. The number points at the last good line, so look at the line after it.

A key written at the list's indent after a list item printed did not find expected '-' indicator: the parser expected another item.

PyYAML 6.0.3 named the bad line itself for the same file: line 4, column 4. An unclosed double quote produced a different message, found unexpected end of stream, at a line number past the end of the file.

How to tell this is your problem
WhereWhat you see
helm and other Kubernetes toolsyaml: line N: did not find expected key
Listsyaml: line N: did not find expected '-' indicator
Unclosed quoteyaml: line N: found unexpected end of stream

How to know it is actually fixed

  • The tool that failed now parses the file.

Stopping it happening again

  • Indent with two spaces, never tabs, and let the editor show whitespace.
  • Run helm lint or a YAML linter before applying.

Sources

Behaviour described here is drawn from official documentation. Where a figure could not be confirmed on an official page it is attributed in the text rather than stated as canonical.

Did this get you to an answer?

No text box on purpose — please do not paste production logs anywhere

Something wrong or out of date? Report it