Developer Tools

v0.20.3-rc0: model/parsers: add gemma4 tool call repair (#15374)

New update fixes common parsing errors in Google's Gemma 4 models, making AI tool usage more robust.

Deep Dive

Ollama, the popular open-source platform for running large language models locally, has released version v0.20.3-rc0 with a critical enhancement for users of Google's Gemma 4 models. The update introduces a new "tool call repair" system that fixes common parsing errors when these models attempt to call external tools or APIs. When the primary strict parser fails, the system now builds a set of repair candidates to handle malformed outputs, specifically addressing issues like missing Gemma string delimiters, single-quoted string values, and raw terminal strings that should be properly formatted.

This technical improvement stems from practical issues documented in GitHub issue #15315, where developers reported Gemma 4 models producing tool calls that couldn't be parsed correctly. The repair system covers four specific failure patterns and uses the first candidate that successfully parses, ensuring backward compatibility while dramatically improving reliability. The release includes comprehensive regression testing for the documented malformed tool calls and focused unit tests for individual repair helpers, making it a production-ready solution for developers building AI agents that need robust tool-calling capabilities.

Key Points
  • Fixes common Gemma 4 parsing errors including missing string delimiters and single-quoted values
  • Builds repair candidates when primary parser fails, using first successful parse
  • Includes regression tests from issue #15315 and focused unit tests for reliability

Why It Matters

Developers can now run Gemma 4 models more reliably for AI agents that need to call tools and APIs without crashing on formatting issues.