Common causes
1. An item property indented one space short
The properties of a list item must line up with the first key after the dash. Here value starts one column left of name, so it belongs to neither the item nor the list.
- name: REGION
value: "eu-west-1"- name: REGION
value: "eu-west-1"2. A key placed at the dash column inside a list
In a GitHub Actions or CI file, writing a key at the same indentation as the dashes ends the list as far as you are concerned, but not for the parser. Move it out to its parent’s level or make it an item.
steps:
- name: Test
run: npm test
name: Deployname: Deploy
steps:
- name: Test
run: npm test3. A new item written without its dash
Adding an item by copying the properties of the previous one but forgetting - leaves a mapping inside the list. Every item needs its own dash.
ports:
- containerPort: 80
containerPort: 443ports:
- containerPort: 80
- containerPort: 4434. A nested block aligned with the dash instead of the item
Kubernetes manifests hit this when resources: or env: is pasted two spaces too far left, or a Helm nindent value is too small. The block belongs inside the list item, so it must line up with name.
containers:
- name: web
image: nginx:1.27
resources:
limits:
cpu: "1"containers:
- name: web
image: nginx:1.27
resources:
limits:
cpu: "1"Go's line number is not the line to edit
This error most often comes from Go tools, and their line numbers need translating. For the sample on this page the mistake is on line 5:
yaml.v2andsigs.k8s.io/yaml(the form seen aserror converting YAML to JSON) reportline 4. The number is zero-based here, so add one.yaml.v3reportsline 1. That is the context mark, the start of the list, counted from zero, so it tells you which list and not which line.- Ruby’s Psych prints the start of the list as well:
while parsing a block collection at line 2 column 3. - PyYAML gives both, an
in "<unicode string>", line 2for the list andline 5, column 4for the problem. Use the second one.
The message also changes with the shape of the mistake. In PyYAML, a badly indented property reads expected <block end>, but found '<block mapping start>', and a key sitting at the dash column reads but found '?'. In js-yaml the two cases are bad indentation of a sequence entry and bad indentation of a mapping entry. The yaml package says Sequence item without - indicator and All mapping items must start at the same column.
The three legal positions for the next line
Inside a list, each new line has only three valid starting columns:
env:
- name: REGION # dash in column 3, first key in column 5
value: eu-west-1 # column 5: same item
- name: LOG_LEVEL # column 3 with a dash: new item
other: value # column 1: the list has ended
Column 4 fits none of them, and neither does column 3 without a dash, so both raise this error. Work upwards from the reported line to the most recent dash, put a cursor on the first key after it, and check the failing line starts in that column.
The opposite mistake is worse because it raises no error. A line indented more than the dash, with its own dash, is read as a continuation of the previous plain string:
items:
- one
- two
That parses as a single item, the string one - two. A file with no errors can still have the wrong shape, so check the structure as well. In PasteKit, the Tree view shows which keys landed in which item once the file parses.
Catching it before deployment
For hand-edited files, turn on visible whitespace and a two-space indent for YAML in your editor, since most of these mistakes are one column wide.
yamllintreports the failure as asyntaxerror with the real line and column, and itsindentationrule can enforce how sequences are indented across a repository.helm template ./chart > out.yamlshows the rendered output, so you debug the result and not the template. The reported line refers to the rendered file, not to your chart source.kubectl apply --dry-run=client -f out.yamlruns the manifest through kubectl’s own parsing without changing the cluster.
Wrong indent and nindent values in Helm charts are a frequent source of this error. Counting the columns in the rendered output is quicker than counting braces in the template.
Frequently asked questions
Do list dashes need to be indented under their key?
No. Both “key:\n- item” and “key:\n - item” are valid. What matters is that every dash in the same list sits in the same column and that each item’s properties line up after the dash.
What does PyYAML's "expected <block end>, but found '?'" mean?
It is PyYAML’s wording for the same problem: inside a block collection it expected the list to continue or end and found a mapping key (‘?’) instead.
Why is the reported line one above the mistake?
Tools built on sigs.k8s.io/yaml print a zero-based line number for this parser error, so the mistake is one line below the number shown. With Helm, the number refers to the rendered output and not to your template.
How can I see the structure the parser is building?
Fix the first error PasteKit reports, then open the Tree view. It shows which keys belong to which list item, which quickly reveals an item that swallowed a sibling’s property.