lmstudio-ai / lmstudio-ai/lmstudio-bug-tracker

fix: Gemma 4 chat template missing format_type_argument macro → crashes on tool calls via API

Open
#2,012 2 comments 20 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
152
Forks
38
PR merge metrics
No merged PRs in 30d

Description

Which version of LM Studio?
LM Studio 0.4.16

Which operating system?
Arch linux

What is the bug?
Gemma 4 12B UD crashes with UndefinedValue jinja error when any external client hits /v1/chat/completions with tools[] in the request. GUI works fine. API path dies immediately.

Root cause: bundled chat template calls format_type_argument everywhere but never defines the macro. Confirmed fix adding this one macro on top resolves it:

{%- macro format_type_argument(type_arg) -%}
    {{- type_arg if type_arg is string else format_argument(type_arg) -}}
{%- endmacro -%}

Screenshots
No

Logs
API Error: 400 {"error":"Error rendering prompt with jinja template: "Cannot call something that is not a function: got UndefinedValue".\n\nThis 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."}

To Reproduce
Load gemma-4-12b-it-ud in LM Studio
Start the local server
Send any request to /v1/chat/completions with tools[] populated (e.g. via OpenCode or curl)
Instant 400 with UndefinedValue error

Note: not the same as #1927 — that's GUI + 26B compressed. This is API path + 12B UD, different trigger, same underlying missing macro.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce with gemma-4-12b-it-ud through the local server's /v1/chat/completions endpoint, using a request with tools[] populated. Inspect the bundled Gemma 4 chat template and verify that tool calls no longer produce the UndefinedValue error while the GUI behavior remains unaffected.

Written by the indexing model from the issue text.

Assessment

Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.