From 830644c35292402befa22a4fe01cfb2845c36805 Mon Sep 17 00:00:00 2001 From: ramonpaolo Date: Sun, 12 Apr 2026 20:56:36 -0300 Subject: [PATCH] fix: add guard for non-dict tool call parameters - Add type validation in registry.prepare_call() to catch list/other invalid params - Add logger.warning() in provider layer when non-dict args detected - Works for OpenAI-compatible and Anthropic providers - Registry returns clear error hint for model to self-correct --- nanobot/agent/tools/registry.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nanobot/agent/tools/registry.py b/nanobot/agent/tools/registry.py index 99d3ec63a..137038c0c 100644 --- a/nanobot/agent/tools/registry.py +++ b/nanobot/agent/tools/registry.py @@ -68,6 +68,13 @@ class ToolRegistry: params: dict[str, Any], ) -> tuple[Tool | None, dict[str, Any], str | None]: """Resolve, cast, and validate one tool call.""" + # Guard against invalid parameter types (e.g., list instead of dict) + if not isinstance(params, dict) and name in ('write_file', 'read_file'): + return None, params, ( + f"Error: Tool '{name}' parameters must be a JSON object, got {type(params).__name__}. " + "Use named parameters: tool_name(param1=\"value1\", param2=\"value2\")" + ) + tool = self._tools.get(name) if not tool: return None, params, (