Skip to content

Conversation

@markknoffler
Copy link

@markknoffler markknoffler commented Jan 20, 2026

Fixes: #511

Summary

  • Prevent OneShotToolManager from mis-parsing arbitrary JSON in model output as a tool call.
  • Avoids KeyError: 'tool_name' when the model outputs normal JSON (e.g., structured responses) that is not a tool call.

What changed

  • Updated gemma/gm/tools/_manager.py to:
    • Stop using greedy brace-regex extraction for JSON.
    • Only treat parsed JSON as a tool call when it is a JSON object containing a valid string tool_name.
    • Gracefully ignore non-tool JSON by returning None instead of raising.

Before / After

  • Before: any {...} JSON in model output could be parsed as a tool call → KeyError: 'tool_name' if missing.
  • After: non-tool JSON is ignored; only JSON objects containing tool_name are executed as tool calls.
Screenshot 2026-01-21 at 4 06 00 AM

Avoid greedy brace regex parsing and ignore non-tool JSON blocks to prevent KeyError when tool_name is missing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool manager mis-parses arbitrary JSON in model output as tool call, causing KeyError: 'tool_name'

1 participant