Skip to content

gemma4:31b - Tool Call Fails #15241

Closed

Description

@Glitch3dPenguin

What is the issue?

gemma4 seems to fail a tool call.

Version running is: ollama:0.20.0-rc1

Relevant log output

source=gemma4.go:287 msg="gemma4 tool call parsing failed" error="invalid character 'p' after object key:value pair" content="call:subagent{*****************}"

OS

Docker

GPU

Nvidia

CPU

AMD

Ollama version

0.20.0-rc1

Activity

  1. changed the title [-]gemma4:31b[/-] [+]gemma4:31b - Tool Call Fails[/+] on Apr 2, 2026
  2. chathaway-codes commented on Apr 3, 2026

    @chathaway-codes
    Contributor

    Same issue; I believe the error message can answer this:

    time=2026-04-03T02:05:16.223Z level=WARN source=gemma4.go:287 msg="gemma4 tool call parsing failed" error="invalid character 'U' after object key:value pair" content="call:terminal{cd:<|\"|>dir<|\"|>,command:<|\"|>git add task1.yaml && git commit -m \"Update task1.yaml to use gemma4:31b\"<|\"|>}"
    

    The issue is this line; if the command contains a quote, it will fail because it replaces <"> with ", and doesn't escape " when converting to the string that is passed to the JSON parser

  3. added a commit that references this issue on Apr 3, 2026
    6fa035e
  4. drifkin commented on Apr 3, 2026

    @drifkin
    Contributor

    Thanks for reporting! I've got what I think is an initial fix up at #15254, but still testing it

  5. added a commit that references this issue on Apr 3, 2026
    d928879
  6. chathaway-codes commented on Apr 3, 2026

    @chathaway-codes
    Contributor

    No pressure to take this, but I already had the code mostly finished before I had to step away :). Your testing is much more thorough than mine, although I'm not 100% about some of the details of the test cases.

    In particular, this one:

    <|tool_call>call:search{query:<|"|>say \"hello\"<|"|>}<tool_call|>

    It's not clear to me what the correct behavior is; PR 15255 uses strconv.Quote to do the quoting.

    #15255

  7. drifkin commented on Apr 3, 2026

    @drifkin
    Contributor

    @chathaway-codes thanks for the PR, appreciate it! I'm a little uncertain of the exact correct behavior for that test case, I'm trying to experimentally figure it out right now, thanks for highlighting that. Models aren't always consistent about this sort of thing (which makes it impossible to solve it 100% of the time), but from my empirical testing, I think you're right that I was handling that case differently from what the model prefers to do. Checking some of the other escapes right now to see if it's consistent.

  8. drifkin commented on Apr 3, 2026

    @drifkin
    Contributor

    @chathaway-codes I pushed up that fix to my PR, will go with mine for now since I tested it more, but I've still got some other edge cases to look at tomorrow. Thanks again for pointing out that test case, was super helpful. Added you as a co-author on that commit since it wouldn't have happened tonight without you!

  9. added a commit that references this issue on Apr 3, 2026
    036ed1b
  10. daniel-farina commented on Apr 3, 2026

    @daniel-farina
  11. tryblackjack commented on Apr 5, 2026

    @tryblackjack
  12. drifkin commented on Apr 6, 2026

    @drifkin
    Contributor

    @tryblackjack: this issue is already fixed, no need for a workaround

  13. added a commit that references this issue on Jul 13, 2026
    cb587e7
  14. added a commit that references this issue on Oct 12, 2026
    ff2fdf2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions