Gemma 4 Chat Template Bug: Tool Parameters with anyOf/null Rendered as Empty type

A Reddit user discovered that Gemma 4 (gemma-4-31B-it) fails to parse tool parameters that use the JSON Schema pattern anyOf: [$ref, null] — a common pattern for nullable object references. The default chat template assumes a direct type field at the top level, so schemas like this:
{"anyOf": [{"$ref": "#/$defs/SomeObject"}, {"type": "null"}]}get stripped of anyOf, $ref, and $defs, resulting in type: "" in the prompt. This breaks tool calling on multiple inference engines (llama-server, others) while Qwen3.5 and gpt-oss-20b handle it correctly.
Diagnosis and Fix
The user debugged with verbose logging from llama-server and had GPT-5.5-high (via codex CLI) compare logs between Qwen3.5-27B-Q4_K_M and gemma-4-31B-it-Q4_K_S on a MacBook Pro. The root cause was traced to the Gemma chat template's assumption that every parameter has a direct type key. A small change to the Jinja template now preserves anyOf, $ref, and $defs structures.
The corrected Jinja template is available on Pastebin: https://pastebin.com/p9z3BAC0
A PR has been submitted to the Hugging Face repository for gemma-4-31B-it.
Takeaway
If you use Gemma 4 for tool/function calling with nullable JSON Schema refs, apply the fixed chat template. Users of Qwen3.5 or gpt-oss-20b are unaffected.
📖 Read the full source: r/LocalLLaMA
👀 See Also

OpenClaw Discussion on AI Agent-to-Agent Messaging and Context Sharing
A Reddit discussion explores the implications of AI agents using personal context to communicate with other agents on a user's behalf, examining what information users might be comfortable sharing.

Building FastTab with AI: A Custom Task Switcher for X11
FastTab solves a specific performance issue in the Plasma task switcher on X11 using Zig and OpenGL, with development supported by AI tools like Claude.

Qwen3.6 Plus benchmark comparison against Western SOTA models
Qwen3.6 Plus scores 78.8 on SWE-bench Verified, 90.4 on GPQA/GPQA Diamond, 28.8 on HLE (no tools), and 78.8 on MMMU-Pro, placing it competitively against models like GPT-5.4, Claude Opus 4.6, and Gemini 3.1 Pro Preview.

Claude Code 2.1.63 adds bundled slash commands, HTTP hooks, and memory leak fixes
Anthropic released Claude Code 2.1.63 with 26 CLI changes including new /simplify and /batch slash commands, HTTP hooks that POST JSON to URLs, and fixes for multiple memory leaks in long-running sessions.