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

Google Trends shows rising search interest for Claude Code in early 2026
A Reddit user compared Google Trends search interest over the past year for five coding tools: vibe coding, Cursor, Claude Code, Codex, and Replit. Claude Code's rise in early 2026 stands out in the data.

Claude 4.6 Opus Can Reproduce Linux's list.h From Minimal Input
A user demonstrated that Claude 4.6 Opus can generate a near-identical copy of Linux's list.h header file when given the first 43 lines as input with temperature set to 0, raising questions about GPL licensing implications for AI models trained on open-source code.

Oracle considers 20k-30k job cuts and Cerner sale to fund AI data-center expansion
Oracle is considering cutting 20,000 to 30,000 jobs and selling its Cerner healthcare software unit to free up $8-10 billion in cash flow for AI data-center expansion, as US banks retreat from financing the company's $156 billion infrastructure buildout.

Inference Pricing Analysis Shows 4.4x Spread for Same Model Across Providers
Analysis of inference pricing for Llama 3.1 70B Instruct shows a 4.4x cost difference between providers, with DeepInfra at $0.20/$0.27 per million tokens and Together at $0.88/$0.88. For reasoning models, the spread reaches ~30x between DeepSeek R1 and OpenAI o1.