YAML error: found character that cannot start any token

Some characters are reserved by YAML and cannot begin an unquoted (plain) value: @ and the backtick are reserved for future use, % starts a directive, and a tab cannot be used as indentation. When a value begins with one of them, the scanner cannot decide what kind of token it is looking at. Quoting the value fixes it.

Seen as:

  • yaml.scanner.ScannerError: while scanning for the next token found character '@' that cannot start any token
  • found character '`' that cannot start any token
  • yaml: line 2: found character that cannot start any token
  • Plain value cannot start with reserved character @ at line 2, column 11

Input

Settings

History

Load from URL

Common causes

1. A value that starts with @

Mentions, npm scopes and decorators often start with @. Wrap the value in quotes; an @ in the middle of a value, as in an email address, is fine.

Before
notify: @oncall-team
package: @acme/ui
After
notify: "@oncall-team"
package: "@acme/ui"

2. A shell command in backticks

Backticks are reserved in YAML. Quote the whole command, or use a block scalar for longer scripts.

Before
command: `date +%F`
After
command: '`date +%F`'

3. A value that starts with %

A leading % looks like a directive such as %YAML 1.2. URL-encoded strings and format strings need quotes.

Before
separator: %20
log_format: %h %l %u
After
separator: "%20"
log_format: "%h %l %u"

4. A tab used as indentation

In PyYAML and Go the same message appears for a tab at the start of a line, shown as '\t'. Replace it with spaces; see tabs in YAML.

Before
deploy:
	notify: oncall
After
deploy:
  notify: oncall

Frequently asked questions

Which characters cannot start a plain YAML value?

The indicators - ? : , [ ] { } # & * ! | > ’ " % @ and the backtick all have special meaning at the start of a value. A few, such as - ? and :, are allowed when followed by a non-space character, but quoting is the simple rule.

Why does Go not say which character it found?

Go’s yaml packages print the generic libyaml message without the character. Use the line number, or paste the file into PasteKit, which names the character and its column.

Will quoting change the value?

No. “@oncall-team” and an unquoted @oncall-team (if it were allowed) are the same string. Quotes only tell the parser where the string starts and ends.

Related