Skip to content
Latchkey

Helm "YAML parse error on ... template" - Fix Template Output in CI

Helm rendered a template and the resulting text is not valid YAML. The Go templating produced broken indentation, an empty value where a key was expected, or an unquoted interpolated string that corrupts the document.

What this error means

helm install/template fails with Error: YAML parse error on <chart>/templates/<file>.yaml: error converting YAML to JSON: yaml: line N: <detail>. The chart’s logic is fine; the rendered output at that line is malformed.

helm output
Error: YAML parse error on api/templates/deployment.yaml: error converting YAML
to JSON: yaml: line 23: did not find expected key

Common causes

Bad indentation from templating

A {{ .Values.x | nindent N }} with the wrong N, or a block inserted at the wrong indentation, shifts keys so the rendered YAML no longer parses.

Missing/empty value or unquoted interpolation

A value that renders empty leaves key: with nothing (or wrong structure), and an unquoted string containing : or special chars breaks the document. Numbers/strings often need | quote.

How to fix it

Render the template and read line N

See exactly what Helm produced at the failing line so you can spot the indentation or empty value.

Terminal
helm template ./chart --debug 2>&1 | sed -n '18,28p'
# or render one file
helm template ./chart --show-only templates/deployment.yaml

Fix indentation and quote values

  1. Use nindent/indent with the correct column for inserted blocks.
  2. Quote interpolated scalars ({{ .Values.x | quote }}) and provide defaults ({{ .Values.x | default "..." }}) so nothing renders empty.
  3. Lint the chart (helm lint) and validate rendered output before install.

How to prevent it

  • Run helm lint and helm template in CI to catch render errors before install.
  • Quote interpolated values and supply defaults so templates never emit empty keys.
  • Use nindent carefully and review rendered output for indentation drift.

Frequently asked questions

What causes ""YAML parse error on ... template""?
A {{ .Values.x | nindent N }} with the wrong N, or a block inserted at the wrong indentation, shifts keys so the rendered YAML no longer parses.
How do I fix "YAML parse error on ... template"?
See exactly what Helm produced at the failing line so you can spot the indentation or empty value.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card