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 2026.4.29 Broken – Downgrade to 2026.2.6
OpenClaw version 2026.4.29 is broken with random errors, slow CLI, double replies. Downgrade to 2026.2.6 to fix.

Qwen3.6 27B FP8 Runs 200k Tokens BF16 KV Cache at 80 TPS on RTX 5000 PRO 48GB
A Reddit user shares a vLLM setup for Qwen3.6 27B FP8 with BF16 KV cache at 200k tokens, achieving 60-90 TPS on a single RTX 5000 PRO 48GB. Full environment variables, config, and benchmark results are provided.

Claude Code v2.1.187: Structured Output Fixes, Sandbox Security, and Org Model Restrictions
Claude Code v2.1.187 adds sandbox.credentials setting, org model restrictions, and fixes for structured output loops, remote MCP hangs, and subagent depth tracking.

Claude Corps: Anthropic's $150M National Fellowship for Nonprofit AI
Anthropic launches Claude Corps, a 12-month paid fellowship placing 1,000 early-career fellows at nonprofits to build AI tools using Claude. $150M budget, $85k salary, expert mentorship.