Developer Tools

v0.20.1-rc2: model/parsers: rework gemma4 tool call handling (#15306)

The update replaces a custom parser to ensure reliable AI agent actions and proper data typing.

Deep Dive

Ollama, the open-source platform for running large language models locally, has pushed a new release candidate (v0.20.1-rc2) with a critical fix for users of Google's Gemma 4 model. The update specifically targets the model's ability to handle tool or function calls—a core feature for building AI agents that can execute code, call APIs, or take other programmed actions. The fix addresses a parser issue where Gemma 4's unique output format for tool arguments was not being correctly normalized into standard JSON, which could cause agent workflows to fail or behave unpredictably.

The technical core of the patch, referenced in pull request #15306, involves replacing a custom-built 'argument normalizer' with a more robust and stricter conversion process. This new method preserves strings that Gemma 4 outputs with quotes, ensures bare keys are properly quoted, and then unmarshals the final result as valid JSON. This approach maintains correct data types, so a number like `42` from the model stays an integer instead of becoming a string, and boolean values remain true or false. The update also adds test coverage to reject malformed inputs that a reference implementation would deny, increasing overall stability for developers building tool-using applications with the Gemma 4 model on Ollama.

Key Points
  • Fixes tool/function call parsing for Google's Gemma 4 model in the Ollama local runner.
  • Replaces a custom argument normalizer with a stricter, reference-style JSON conversion for reliability.
  • Preserves correct data types (strings, numbers, booleans) and rejects malformed inputs from the model.

Why It Matters

This fix is crucial for developers building reliable AI agents with Gemma 4, ensuring tool calls execute correctly without silent data corruption.