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.
Find your message
- mapping values are not allowed in this context / herecolon inside a value, key indented too far
- bad indentation of a mapping entryjs-yaml, several causes
- did not find expected keykey between two indent levels, text after a quote
- found character that cannot start any tokentab, @ or backtick
- tab characters must not be used in indentationjs-yaml, tab
- missed comma between flow collection entries["80" "443"] instead of ["80", "443"]
- could not find expected ':'a key without a colon
- can not read a block mapping entry; a multiline key may not be an implicit keyjs-yaml, a key without a colon
- can not read an implicit mapping pair; a colon is missedjs-yaml, a key without a colon
- a line break is expectedtext on the same line as | or >
- end of the stream or a document separator is expecteda list after a mapping
- duplicated mapping keythe same key twice
- bad indentation of a sequence entrya list item indented too far
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 like | Printed by |
|---|---|
mapping values are not allowed in this context, did not find expected key | libyaml (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 parentheses | js-yaml (JavaScript), which this site uses. It reports many different causes as bad indentation, so trust the line and column more than the words. |
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.
title: Error: not foundtitle: "Error: not found"- libyaml, Psych, go-yaml
mapping 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.dev
Invalid YAML: bad indentation of a mapping entry (1:13)
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.
name: app
image: nginxname: app
image: nginx- libyaml, Psych, go-yaml
mapping 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.dev
Invalid YAML: bad indentation of a mapping entry (2:8)
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.
metadata:
name: web
labels:
app: web
tier: frontmetadata:
name: web
labels:
app: web
tier: front- libyaml, Psych, go-yaml
did 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.dev
Invalid YAML: bad indentation of a mapping entry (5:4)
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.
name: "web" server
port: 80name: "web server"
port: 80- libyaml, Psych, go-yaml
did 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.dev
Invalid YAML: bad indentation of a mapping entry (1:13)
libyaml also prints did not find expected key for a list that follows a mapping and for a list item indented too far.
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.
server:
port: 8080server:
port: 8080- libyaml, Psych, go-yaml
found character that cannot start any token(line 2, column 1) - SnakeYAML
found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation) - yamlvalidator.dev
Invalid YAML: tab characters must not be used in indentation (2:1)
A value that starts with @ or a backtick
Quote the value. The same applies to cmd: `date`.
user: @adminuser: "@admin"- libyaml, Psych, go-yaml
found character that cannot start any token(line 1, column 7) - SnakeYAML
found character '@' that cannot start any token. (Do not use @ for indentation) - yamlvalidator.dev
Invalid YAML: bad indentation of a mapping entry (1:7)
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.
ports: ["80" "443"]ports: ["80", "443"]- libyaml, Psych, go-yaml
did not find expected ',' or ']'(',' or '}'inside curly braces) - PyYAML
safe_load, SnakeYAMLexpected ',' or ']', but got '<scalar>'(line 1, column 14) - yamlvalidator.dev
Invalid YAML: missed comma between flow collection entries (1:14)
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.
name: app
image
port: 80name: app
image: nginx
port: 80- libyaml, Psych, go-yaml, PyYAML, SnakeYAML
could not find expected ':' - yamlvalidator.dev
Invalid YAML: can not read a block mapping entry; a multiline key may not be an implicit key (3:5)
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.
name: app
image # todo
port: 80name: app
image: nginx # todo
port: 80- libyaml, Psych, go-yaml, PyYAML, SnakeYAML
could not find expected ':' - yamlvalidator.dev
Invalid YAML: can not read an implicit mapping pair; a colon is missed (2:8)
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.
run: | npm testrun: |
npm test- libyaml, Psych, go-yaml
did not find expected comment or line break - PyYAML
safe_loadexpected a comment or a line break, but found 'n'(line 1, column 8) - yamlvalidator.dev
Invalid YAML: a line break is expected (1:8)
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.
name: app
- web
- workername: app
services:
- web
- worker- libyaml, Psych, go-yaml
did not find expected key - PyYAML
safe_load, SnakeYAMLexpected <block end>, but found '-'(line 2, column 1) - yamlvalidator.dev
Invalid YAML: end of the stream or a document separator is expected (2:1)
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.
services:
web:
image: a
web:
image: bservices:
web:
image: a
worker:
image: b- go-yaml v3
mapping key "web" already defined at line 2 - PyYAML, Psych, SnakeYAML, go-yaml v2No error
- yamlvalidator.dev
Invalid YAML: duplicated mapping key (4:3)
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.
steps:
- run: make
- run: teststeps:
- run: make
- run: test- libyaml, Psych, go-yaml
did not find expected key(PyYAML with libyaml: line 3, column 5) - PyYAML
safe_load, SnakeYAMLexpected <block end>, but found '-'(line 3, column 5) - yamlvalidator.dev
Invalid YAML: bad indentation of a sequence entry (3:5)
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.