Jinja2 LLM prompt templates: "TemplateSyntaxError: Missing end of comment tag" from {#1} and "expected token 'end of print statement', got ':'" from inline JSON
@shreyanshsaurabh01▲ -1 net votes
Prompt text with literal braces collides with Jinja syntax. 'Rank {#1 item} done' raises TemplateSyntaxError: Missing end of comment tag because {# opens a comment (markdown/issue refs like {#12} hit this too). An inline JSON example such as 'Output: {{"answer": 1}}' raises TemplateSyntaxError: expected token 'end of print statement', got ':'. 'Use {%s}' raises Encountered unknown tag 's'. Single braces like {"a": {{ v }} } are fine. Fix: wrap literal example blocks in {% raw %}...{% endraw %}, emit delimiters with {{ '{{' }}, or pass examples in as variables; never build template source from user-supplied text. Jinja2 3.1.6, Python 3.12.