jinja
jinja
¶
Jinja template validation checks.
Validates Jinja2 template syntax and detects undefined variables that would cause runtime errors.
Classes¶
JinjaSyntaxCheck
¶
Check for Jinja template syntax errors (V001).
Attempts to parse templates and reports syntax errors with line numbers and context. This catches issues like: - Unclosed blocks ({% if ... without {% endif %}) - Unclosed expressions ({{ ... without }}) - Invalid syntax inside blocks
Methods:¶
check
¶
Check Jinja syntax in templates.
Source code in src/marianne/validation/checks/jinja.py
JinjaUndefinedVariableCheck
¶
Check for undefined template variables (V101).
Warns about variables used in templates that aren't defined in the config's variables section or the built-in sheet context. Uses fuzzy matching to suggest corrections for typos.
Methods:¶
check
¶
Check for undefined variables in templates.
Source code in src/marianne/validation/checks/jinja.py
FanOutStringFilterCheck
¶
Detect dict[X | string] on int-normalized variable dicts (V102, #132).
A per-instance dict with int-like string keys ({"1": ...}) has its keys
normalized to integers at render time (_normalize_dict_keys). A template
that subscripts it with dict[instance | string] re-stringifies the int
instance to "1", which no longer matches the int key 1 →
UndefinedError on every fan-out instance.
Detection is CORRELATED, not pure-AST: | string is correct for
genuinely string-keyed dicts, so the check fires ONLY when the subscripted
base Name resolves to a prompt.variables dict whose keys are ALL
integers after normalization (int, or int-normalizable strings). This gives
zero false positives — a string index never matches an all-int-keyed dict.
The filtered Name is not restricted: the dict's key types are the
precondition, and | string always produces a string index regardless of
what it filters.
Methods:¶
check
¶
Flag dict[X | string] where dict has all-int-normalizable keys.
Source code in src/marianne/validation/checks/jinja.py
BashArrayLengthCheck
¶
Detect bash ${#...} length syntax in templates (V305, #362).
Jinja2 tokenizes the literal {# as a comment opener. Bash array/string
length expansion (${#ARR[@]}, ${#var}) contains {#, so Jinja silently
consumes everything from {# to the next #} — truncating the rendered
prompt mid-token. The cli instrument then runs a broken script and dies
with a bare "Exit code 2" and no stderr. There is no legitimate ${# in a
Jinja template (it always opens a comment), so this scan is zero-false-
positive and blocks validation. Recommends a length-free idiom.
Methods:¶
check
¶
Scan prompt.template and template_file for the ${# collision.