{"record":{"id":"7957e87c0d0c4a74","repo":"jd-opensource/joyagent-jdgenie","slug":"error-7957e8","errorCode":null,"errorMessage":"工具参数必须是字典类型","messagePattern":"工具参数必须是字典类型","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"genie-client/app/client.py","lineNumber":318,"sourceCode":"        Args:\n            name: 工具名称\n            arguments: 工具参数字典，默认为空字典\n\n        Returns:\n            Any: 工具执行结果\n\n        Raises:\n            ValueError: 当工具名称无效时抛出\n            Exception: 当工具调用失败时抛出异常\n        \"\"\"\n        # 参数验证\n        if not name or not isinstance(name, str):\n            raise ValueError(\"工具名称不能为空且必须是字符串类型\")\n\n        if arguments is None:\n            arguments = {}\n        elif not isinstance(arguments, dict):\n            raise ValueError(\"工具参数必须是字典类型\")\n\n        try:\n            async with self._sse_connection() as session:\n                logger.info(f\"正在调用工具 '{name}'，参数: {arguments}\")\n\n                # 调用工具\n                response = await session.call_tool(name=name, arguments=arguments)\n\n                logger.info(f\"工具 '{name}' 执行成功\")\n                logger.debug(f\"工具 '{name}' 返回结果类型: {type(response).__name__}\")\n\n                return response\n\n        except Exception as e:\n            error_msg = f\"调用工具 '{name}' 失败: {str(e)}\"\n            logger.error(error_msg)\n            raise Exception(error_msg) from e\n","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-client/app/client.py#L300-L336","documentation":"A ValueError raised in `call_tool` when `arguments` is provided but is not a dict (e.g. a list, string, or JSON text). Passing None is fine (it defaults to {}); only a wrong non-dict type triggers this.","triggerScenarios":"`client.call_tool(\"tool\", [\"a\"])`, a JSON-encoded string, or another mapping-like object that is not a Python dict.","commonSituations":"Passing raw JSON text instead of a parsed dict; passing a list of (key, value) pairs; framework-provided params object that isn't a plain dict.","solutions":["Convert the value to a dict: `json.loads(...)` for JSON strings or `dict(pairs)` for pair lists","Check the type before calling: `isinstance(arguments, dict)`","Pass None or omit the argument if there are no parameters"],"exampleFix":"// before\nawait client.call_tool(\"search\", '{\"query\": \"x\"}')\n// after\nawait client.call_tool(\"search\", {\"query\": \"x\"})","handlingStrategy":"validation","validationCode":"if arguments is not None and not isinstance(arguments, dict):\n    arguments = json.loads(arguments) if isinstance(arguments, str) else dict(arguments)","typeGuard":"def is_arguments_dict(args) -> bool:\n    return args is None or isinstance(args, dict)","tryCatchPattern":"try:\n    result = await client.call_tool(name, args)\nexcept ValueError as e:\n    logger.error(f\"arguments must be a dict: {e}\")\n    raise","preventionTips":["Parse JSON strings into dicts before passing as arguments","Enforce dict typing at call sites with annotations and mypy","Default to None/{} when a tool takes no parameters"],"tags":["validation","type-mismatch","arguments"],"backgroundTag":"invalid-argument-value","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}