Pull down to go back
I found and fixed a Gemma 4 chat template bug that breaks tool calling

I found and fixed a Gemma 4 chat template bug that breaks tool calling

我發現並修復了 Gemma 4 聊天模板的工具呼叫漏洞

TLDR: tool parameters using the common JSON Schema pattern `anyOf: [$ref, null]` are rendered into the prompt as empty `type` fields. This strips the useful schema information before the model sees it. Long version: Gemma 4 was failing to call custom MCP tools across multiple inference engines, while Qwen3.5 and gpt-oss-20b worked fine. The issue turned out to be a chat template problem that wasn't properly handling optional schema fields—a bug that affects any tool using standard JSON Schema patterns for nullable parameters.