YAML errors

YAML error messages explained

A YAML parser stops at the first thing it cannot read and prints one line about it. That line depends on the parser: the same missing quote is mapping values are not allowed in this context in Python with libyaml, mapping values are not allowed here in Java, and bad indentation of a mapping entry in JavaScript. This page is organized by cause. For each one: what the message means, a small file that triggers it, the fix, and what each parser printed for that file.

Tested November 2026 on the exact examples below: js-yaml 4.3.2 (used by this site) · PyYAML 6.0.3 with libyaml 0.2.5 · Ruby 2.6 Psych 3.1.0 · go-yaml v2.4.0 and v3.0.1 · SnakeYAML 2.3. Default settings.

Messages on this page

Find your message

Which parser wrote it

The wording tells you the parser

Several YAML libraries share code or wording, so the words of the message hint at which one printed it, and which entry below to read.

Message looks likePrinted by
mapping values are not allowed in this context, did not find expected keylibyaml (C): PyYAML with CSafeLoader or CLoader, Ruby's Psych. go-yaml is a Go port of libyaml and uses the same words.
mapping values are not allowed here, expected <block end>, but found ...PyYAML's default pure-Python loaders, including yaml.safe_load(), and SnakeYAML (Java).
bad indentation of a mapping entry (1:13), with line:column in parenthesesjs-yaml (JavaScript), which this site uses. It reports many different causes as bad indentation, so trust the line and column more than the words.
Cause · a colon where a value was expected

mapping values are not allowed in this context

A colon followed by a space starts a new key. The parser is in the middle of reading a value, finds : and cannot start a key there. This happens in two ways: the value itself contains : , or a key is indented further than the key above it, so the parser reads it as the second line of the previous value.

A value that contains a colon and a space

The value Error: not found has its own : . Quote the value. A colon with no space after it, as in http://host:8080, is fine unquoted.

Broken
title: Error: not found
Fixed
title: "Error: not found"
  • libyaml, Psych, go-yamlmapping values are not allowed in this context (line 1, column 13)
  • PyYAML safe_load, SnakeYAMLmapping values are not allowed here (line 1, column 13)
  • yamlvalidator.devInvalid YAML: bad indentation of a mapping entry (1:13)
Try it in the validator →

A key indented further than the one above it: bad indentation of a mapping entry

image is indented under name: app, so the parser reads app image as one value split over two lines, then meets : . Line the keys up. js-yaml prints bad indentation of a mapping entry for this, for the colon in a value above, and for several causes further down, so look at the column it points to.

Broken
name: app
  image: nginx
Fixed
name: app
image: nginx
  • libyaml, Psych, go-yamlmapping values are not allowed in this context (line 2, column 8)
  • PyYAML safe_load, SnakeYAMLmapping values are not allowed here (line 2, column 8)
  • yamlvalidator.devInvalid YAML: bad indentation of a mapping entry (2:8)
Try it in the validator →
Cause · something other than a key inside a mapping

did not find expected key

The parser is inside a mapping and expects either the next key at the same indentation or the end of the mapping. It found something else: a key indented between two levels, or extra text after a value that was already finished. libyaml adds while parsing a block mapping and the position where that mapping started, which is often a few lines above the real problem.

A key between two indentation levels

tier has 3 spaces: more than labels (2), fewer than app (4). It belongs to neither mapping. Give it the same indentation as its siblings.

Broken
metadata:
  name: web
  labels:
    app: web
   tier: front
Fixed
metadata:
  name: web
  labels:
    app: web
    tier: front
  • libyaml, Psych, go-yamldid not find expected key (PyYAML with libyaml: line 5, column 4)
  • PyYAML safe_load, SnakeYAMLexpected <block end>, but found '<block mapping start>' (line 5, column 4)
  • yamlvalidator.devInvalid YAML: bad indentation of a mapping entry (5:4)
Try it in the validator →

Text after a closing quote

A quoted value ends at the closing quote. Anything after it on the same line, other than a comment, is an error. Quote the whole value.

Broken
name: "web" server
port: 80
Fixed
name: "web server"
port: 80
  • libyaml, Psych, go-yamldid not find expected key (PyYAML with libyaml: line 1, column 13)
  • PyYAML safe_load, SnakeYAMLexpected <block end>, but found '<scalar>' (line 1, column 13)
  • yamlvalidator.devInvalid YAML: bad indentation of a mapping entry (1:13)
Try it in the validator →

libyaml also prints did not find expected key for a list that follows a mapping and for a list item indented too far.

Cause · a tab, or a reserved character

found character that cannot start any token

Some characters cannot begin anything in YAML. A tab is never allowed as indentation, and @ and the backtick are reserved, so a plain (unquoted) value cannot start with them. PyYAML's pure-Python loader names the character: found character '\t' that cannot start any token.

A tab used for indentation: tab characters must not be used in indentation

Line 2 below starts with a tab. Indent with spaces; most editors can convert tabs for .yaml files. When the line above holds a value (as in a: 1), libyaml and go-yaml print found a tab character that violates indentation instead.

Broken (tab on line 2)
server:
	port: 8080
Fixed
server:
  port: 8080
  • libyaml, Psych, go-yamlfound character that cannot start any token (line 2, column 1)
  • SnakeYAMLfound character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation)
  • yamlvalidator.devInvalid YAML: tab characters must not be used in indentation (2:1)
Try it in the validator →

A value that starts with @ or a backtick

Quote the value. The same applies to cmd: `date`.

Broken
user: @admin
Fixed
user: "@admin"
  • libyaml, Psych, go-yamlfound character that cannot start any token (line 1, column 7)
  • SnakeYAMLfound character '@' that cannot start any token. (Do not use @ for indentation)
  • yamlvalidator.devInvalid YAML: bad indentation of a mapping entry (1:7)
Try it in the validator →
Cause · a missing comma in [ ] or { }

missed comma between flow collection entries

Lists in square brackets and mappings in curly braces (flow style, as in JSON) need a comma between items. The parser finished one item and found the start of another.

Broken
ports: ["80" "443"]
Fixed
ports: ["80", "443"]
  • libyaml, Psych, go-yamldid not find expected ',' or ']' (',' or '}' inside curly braces)
  • PyYAML safe_load, SnakeYAMLexpected ',' or ']', but got '<scalar>' (line 1, column 14)
  • yamlvalidator.devInvalid YAML: missed comma between flow collection entries (1:14)
Try it in the validator →
Cause · a key without a colon

could not find expected ':'

A line inside a mapping has no colon, so it is a key with nothing after it. libyaml, go-yaml, PyYAML and SnakeYAML all say could not find expected ':', after while scanning a simple key. js-yaml has two messages for it, depending on what comes next. Add the colon and the value, or turn the line into a comment.

can not read a block mapping entry; a multiline key may not be an implicit key

With no colon on line 2, js-yaml keeps reading into line 3 and gets the key image port. A key written without ? has to fit on one line.

Broken
name: app
image
port: 80
Fixed
name: app
image: nginx
port: 80
  • libyaml, Psych, go-yaml, PyYAML, SnakeYAMLcould not find expected ':'
  • yamlvalidator.devInvalid YAML: can not read a block mapping entry; a multiline key may not be an implicit key (3:5)
Try it in the validator →

can not read an implicit mapping pair; a colon is missed

Here a comment ends the key on its own line, so js-yaml sees a one-line key with no colon.

Broken
name: app
image  # todo
port: 80
Fixed
name: app
image: nginx  # todo
port: 80
  • libyaml, Psych, go-yaml, PyYAML, SnakeYAMLcould not find expected ':'
  • yamlvalidator.devInvalid YAML: can not read an implicit mapping pair; a colon is missed (2:8)
Try it in the validator →
Cause · text on the same line as | or >

a line break is expected

A block scalar (| keeps line breaks, > folds them) starts its text on the next line. On the line of the | itself only a modifier such as |- or >+ and a comment may follow. Move the text down and indent it.

Broken
run: | npm test
Fixed
run: |
  npm test
  • libyaml, Psych, go-yamldid not find expected comment or line break
  • PyYAML safe_loadexpected a comment or a line break, but found 'n' (line 1, column 8)
  • yamlvalidator.devInvalid YAML: a line break is expected (1:8)
Try it in the validator →
Cause · a list after a mapping at the same level

end of the stream or a document separator is expected

The top of the file is a mapping (name: app), then a line starts a list item at the same indentation. One level cannot be a mapping and a list at once. js-yaml has finished the mapping and expects the file to end, or a new document to start with ---. Usually the list is missing its key.

Broken
name: app
- web
- worker
Fixed
name: app
services:
  - web
  - worker
  • libyaml, Psych, go-yamldid not find expected key
  • PyYAML safe_load, SnakeYAMLexpected <block end>, but found '-' (line 2, column 1)
  • yamlvalidator.devInvalid YAML: end of the stream or a document separator is expected (2:1)
Try it in the validator →
Cause · the same key twice

duplicated mapping key

The YAML spec requires the keys of a mapping to be unique, but many parsers accept a duplicate without a word. In our test PyYAML and Ruby's Psych kept the last value (image: b), and SnakeYAML and go-yaml v2 loaded the file without an error. So a file that works in one tool can fail in another, and the first web service silently disappears. Rename or merge the two entries.

Broken
services:
  web:
    image: a
  web:
    image: b
Fixed
services:
  web:
    image: a
  worker:
    image: b
  • go-yaml v3mapping key "web" already defined at line 2
  • PyYAML, Psych, SnakeYAML, go-yaml v2No error
  • yamlvalidator.devInvalid YAML: duplicated mapping key (4:3)
Try it in the validator →
Cause · a list item indented too far

bad indentation of a sequence entry

Items of one list must start at the same column. The second - below is indented further than the first, so it lands inside the first item's mapping, where a key is expected. Common in CI files, where steps are long lists of mappings.

Broken
steps:
  - run: make
    - run: test
Fixed
steps:
  - run: make
  - run: test
  • libyaml, Psych, go-yamldid not find expected key (PyYAML with libyaml: line 3, column 5)
  • PyYAML safe_load, SnakeYAMLexpected <block end>, but found '-' (line 3, column 5)
  • yamlvalidator.devInvalid YAML: bad indentation of a sequence entry (3:5)
Try it in the validator →
Any other message

How to read a YAML error

The line and column mark where the parser gave up, not always where the mistake is. Check that line first, then the line above it: an unclosed quote, a missing colon or a wrong indent there often surfaces one line later. Compare the indentation of the line with its neighbours, and look for : or a leading @, ` or tab in unquoted values. If the file parses but the values come out wrong, such as NO turning into false, see YAML gotchas instead.

Open the YAML validator →