Error rendering prompt with jinja template

#11
by binaryzer0 - opened

I'm trying to use the model in LMStudio but getting errors when trying to infer:

Error rendering prompt with jinja template: "Cannot call something that is not a function: got UndefinedValue".

This is usually an issue with the model's prompt template. If you are using a popular model, you can try to search the model under lmstudio-community, which will have fixed prompt templates. If you cannot find one, you are welcome to post this issue to our discord or issue tracker on GitHub. Alternatively, if you know how to write jinja templates, you can override the prompt template in My Models > model settings > Prompt Template.. Error Data: n/a, Additional Data: n/a

Any hints on how to fix it ?

Hi! This fixed it for me:
https://github.com/lmstudio-ai/lmstudio-bug-tracker/issues/2012 but tool usage is not functioning consistently (most time it doesn't).

Owner
β€’
edited Jun 15

Root cause: this model ships a rich chat template (thinking channel + tool-calling), and LM Studio's minja
engine doesn't fully support some Jinja2 features it uses (e.g. dict.get()), which is what triggers the
UndefinedValue error. The template renders fine on backends with full Jinja2 β€” llama.cpp (llama-server --jinja)
or Ollama work out of the box
β€” so if you want the thinking/tool features reliably, that's the smoothest path.

If you just want plain chat working inside LM Studio right now, override the template under My Models β†’ βš™οΈ β†’ Prompt
Template
with this minja-safe version (keeps the model's custom turn tokens, drops the unsupported logic):

{{ bos_token }}{% if messages[0]['role'] == 'system' %}<|turn>system
{{ messages[0]['content'] | trim }}<turn|>
{% set loop_messages = messages[1:] %}{% else %}{% set loop_messages = messages %}{% endif %}{% for message in
loop_messages %}{% if message['role'] == 'assistant' %}{% set role = 'model' %}{% else %}{% set role = message['role']
%}{% endif %}<|turn>{{ role }}
{{ message['content'] | trim }}<turn|>
{% endfor %}{% if add_generation_prompt %}<|turn>model
<|channel>thought
<channel|>{% endif %}

Heads-up on tool calling: it'll stay flaky in LM Studio because the tool-rendering branches hit the same minja
limitations β€” for reliable tool use, go with llama.cpp / Ollama. Thanks for the patience, and feel free to ping me if
the override above doesn't behave!

Sign up or log in to comment