Parsing Error: unexpected '}' in model sql"
Fixes dbt Jinja parsing errors from unbalanced braces by locating the offending line with dbt parse and correcting the brace structure. Use when dbt parse or dbt compile fails with an unexpected brace error. Not for warehouse SQL syntax errors, which surface after compilation.
TL;DR
A Jinja block in the model SQL has mismatched braces, such as a {{ closed by a single } or a stray } in a string. Run dbt parse to get the exact line number, fix the brace pairing on that line, and recompile.
Error
Parsing Error: unexpected '}' in model sqlSteps
- Run
dbt parse --no-partial-parseto force a full parse and surface the error with a file and line number. Expected: the output names the model file and the line. - Open that line and count the braces: every
{{needs a}}, every{%needs a%}. Expected: you spot the unpaired or doubled brace. - Watch for braces inside string literals, which still count for Jinja parsing. Expected: any
}inside a quoted string is either escaped or removed. - Fix the pairing and save the file. Expected: the line now has balanced delimiters.
- Run
dbt compile --select [MODEL NAME]. Expected: compilation succeeds.
When to use
dbt parseordbt compilefails with an unexpected brace or bracket error.- You just edited Jinja in a model (a macro call, a for loop, an if block).
When not to use
- The error is a warehouse "syntax error at or near" (the SQL compiled fine but is invalid for the warehouse).
- The error names a macro file rather than a model (same technique, different file).
Tool compatibility
- dbt Core 1.0 and later, all adapters. Jinja2 parsing rules are adapter-independent.
Variant phrasings
Parsing Error: unexpected '%' or unexpected end of template
Sibling errors from the same family: an unclosed {% block or a truncated file.
Encountered unexpected character in Jinja block
Often a stray brace adjacent to a macro argument.
Why it happens
dbt renders every model through Jinja before the warehouse ever sees the SQL. Jinja is strict about delimiter pairing, so one stray brace fails the whole file at parse time.
Edge cases
- A literal
{{needed in output (for example in a JSON string) must be written as{{ '{{' }}. - Editor auto-closing of braces can insert invisible mismatches; retype the line manually if counting fails.
- Macros with default arguments containing braces are a classic source of this error.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_5eDFkyj0Ma-0j1zPUxb1lQ
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.