mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-31 05:51:10 +00:00
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
This commit is contained in:
parent
92ef594b6a
commit
830644c352
@ -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, (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user