Skip to content

Home / Blog / Runners and limits

How do I fix "You have an error in your yaml syntax" in GitHub Actions?

"Invalid workflow file: You have an error in your yaml syntax on line N" usually means the file is not valid YAML. Four mistakes, each reproduced, with the fix.

“Invalid workflow file: .github/workflows/ci.yml#L12 You have an error in your yaml syntax on line 12” usually means GitHub could not parse the file as YAML, so no job in it runs. GitHub has also, through bugs, printed it for files that are valid YAML (runner issue #751). The mistake is on that line or just above it. The 4 usual ones are a key indented differently from its siblings, a step’s keys out of line, an unquoted colon inside a value, and a tab.

In short
  • GitHub usually could not parse the workflow file as YAML, so none of its jobs run; bugs have also printed it for valid YAML.
  • Four usual mistakes: a key indented differently from its siblings, a step's keys out of line, an unquoted colon, and a tab.
  • A parser reports where it gave up; in one example that was two lines above the mistake.
  • While an invalid file is in .github/workflows, GitHub creates a failed run for every new commit.
  • actionlint 1.7.12 printed the file, line and column for each of the four mistakes.

The file name and the line number change; the sentence does not. This post shows each mistake with the fix, why the line number can be off by one or two, and how to check a workflow file before you push it. Each example was parsed with two YAML parsers, and their messages are in the table.

What does “You have an error in your yaml syntax on line” mean?

A workflow is a YAML file first and a workflow second. GitHub reads it in that order: the text has to parse as YAML before GitHub looks at what the keys mean. This message is meant for the first stage failing, and a report on GitHub’s runner repository notes that the run fails at once, before any job starts. That report was a bug: its file was valid YAML, a matrix read from an earlier job’s output, and GitHub fixed it. So a file that parses cleanly in a checker can still, rarely, get this message. GitHub’s documentation adds a consequence: while an invalid file sits in .github/workflows, every new commit produces a failed run.

Which mistakes cause it?

MistakeWhat actionlint saidLine actionlint gave
A key indented one space more than its siblingsmapping values are not allowed in this contextThe line with the extra space
A step's second key not lined up under its firstdid not find expected '-' indicatorThe steps: line, two above the mistake
A value with a colon and a space, unquotedmapping values are not allowed in this contextThe line, at the second colon
A tab used to indentfound character that cannot start any tokenThe line with the tab

A key indented differently from its siblings. Keys of the same mapping must start in the same column. Here steps has five spaces and runs-on has four, so the parser reads steps: as a continuation of the line above and stops at its colon.

jobs:
  build:
    runs-on: ubuntu-latest
     steps:              # one space too many
      - run: make

A step’s keys out of line. Inside a list item, every key lines up with the first one, after the dash. A run placed under the dash itself is neither a new item nor part of the old one.

    steps:
      - name: Test
      run: make test    # must line up with "name", two columns to the right

A colon inside a value. A colon followed by a space starts a new key, so an unquoted step name such as Build: release is rejected (“mapping values are not allowed”). Put the value in quotes: name: "Build: release".

A tab. Both parsers refused a line indented with a tab, saying the character cannot start a token. Indent with spaces, and set your editor to insert spaces in .yml files.

Why is the line number wrong?

Because a parser reports where it gave up, which is not always where you went wrong. In the second example above the mistake is on the run line. One parser pointed two lines up, at steps:, and the other pointed at the run line with a message about a block ending. I did not run GitHub’s parser, so I cannot say which line it names, but the lesson holds for any of them: when the reported line looks fine, read the two or three lines above it, and compare the indentation of each with its neighbours.

How do I check a workflow file before pushing?

Parse it locally. actionlint, an open-source checker for workflow files, printed “could not parse as YAML” with the file, line and column for each of the four files above.

actionlint .github/workflows/ci.yml
# ci.yml:6:10: could not parse as YAML: mapping values are not allowed in this context

A plain YAML parser catches these four too, but a checker that knows workflows catches more. A step with two run keys loaded without complaint in the plain parser, and actionlint reported the duplicate. Put the check in a pre-commit hook or the first job of the workflow that tests your workflows.

What if the YAML is valid and the file is still refused?

Then the message is a different one, and names the problem more closely. A step with nothing to do gives “every step must define a `uses` or `run` key”, and a context used where it is not available gives “Unrecognized named-value”. To try a workflow on your own machine before pushing, see running GitHub Actions locally, and for the shape of a matrix, where indentation mistakes are easy to make, the matrix reference.

GitHub rejects the file before any runner is asked for, so this error is the same whichever runner the jobs name, ours included. Every size we run, with its memory, disk and rate a minute, is on our managed GitHub Actions runners page.

Sources

Frequently asked questions

How do I fix "You have an error in your yaml syntax" in GitHub Actions?

Open the file at the line in the message and check it and the lines just above. The 4 usual mistakes are a key indented differently from its siblings, a step's keys out of line, an unquoted colon inside a value, and a tab.

Which mistakes cause it?

A key indented one space further than the keys beside it. A step's second key that is not lined up under its first. A value that contains a colon followed by a space and is not in quotes. A tab used for indentation.

Why is the line number wrong?

A parser reports the place where it gave up, which can be before or after the mistake. For a run key out of line, one parser we used pointed two lines up, at steps. When the reported line looks fine, read the lines above it.

How do I check a workflow file before pushing?

Run actionlint on it. For each of the four mistakes in this post it printed could not parse as YAML with the file, line and column. It also reported a step with two run keys, which a plain YAML parser loaded without complaint.

Move your CI onto our runners with one line

Change one line, watch your own build, then decide.

Connect GitHub

Card required: a $5.00 authorisation, released at once and never charged. 3,000 minutes a month at 2 vCPU are included.

.github/workflows/ci.yml
jobs: test:removed: runs-on: ubuntu-latestadded: runs-on: runnersio-4vcpu-ubuntu-latest steps: - uses: actions/checkout@v4 - run: make testadded: build:added: runs-on: runnersio-32vcpu-ubuntu-latest