{"record":{"id":"5284f0388485ee0f","repo":"agentscope-ai/agentscope","slug":"input-validation-failed-for-tool-tool-call-name","errorCode":null,"errorMessage":"Input validation failed for tool '{tool_call.name}': {e.message}","messagePattern":"Input validation failed for tool '(.+?)': (.+?)","errorType":"exception","errorClass":"AgentOrientedException","httpStatus":null,"severity":"error","filePath":"src/agentscope/agent/_agent.py","lineNumber":2306,"sourceCode":"        try:\n            # Check if the tool is available\n            tool = await self.toolkit.check_tool_available(\n                tool_call.name,\n                self.state.tool_context.activated_groups,\n            )\n\n            # Try to parse the input with the tool schema\n            parsed_input = _json_loads_with_repair(\n                tool_call.input,\n                tool.input_schema,\n            )\n\n            # Validate the parsed input with the tool schema\n            # TODO: Maybe some logic to mix the validation error in runtime\n            try:\n                jsonschema.validate(parsed_input, tool.input_schema)\n            except jsonschema.ValidationError as e:\n                raise AgentOrientedException(\n                    f\"Input validation failed for tool '{tool_call.name}': \"\n                    f\"{e.message}\",\n                ) from e\n\n        # The exceptions that\n        #  - cannot found tool\n        #  - tool not available\n        #  - input parsing failure\n        except AgentOrientedException as e:\n            async for evt in self._handle_error_tool_call(\n                tool_call,\n                e.message,\n                state=ToolResultState.ERROR,\n            ):\n                yield evt\n\n            return\n","sourceCodeStart":2288,"sourceCodeEnd":2324,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/agent/_agent.py#L2288-L2324","documentation":"Raised as an AgentOrientedException when the arguments parsed for a tool call fail JSON-schema validation against the tool's declared input_schema. The agent rejects malformed LLM-generated tool arguments before invoking the tool function.","triggerScenarios":"The model emits a tool call whose arguments violate the tool's schema: missing required fields, wrong types (e.g. string where int expected), unknown enum values, or unparseable arguments coerced into an invalid dict.","commonSituations":"Weak models hallucinating argument names; a tool schema declaring required params the model doesn't reliably supply; overly strict schemas (e.g. strict additionalProperties) after a schema change; prompts not describing parameters clearly.","solutions":["Re-run/let the model retry: the failed validation is reported back to the model so it can correct arguments on the next turn","Loosen the tool's input_schema: make optional fields non-required, relax types, or accept extra properties","Improve the tool's parameter descriptions and docstring so the model knows expected shapes","Use a stronger model if argument hallucination is frequent"],"exampleFix":"# before\ninput_schema = {\n    \"type\": \"object\",\n    \"properties\": {\"path\": {\"type\": \"string\"}},\n    \"required\": [\"path\", \"mode\"],\n}\n\n# after\ninput_schema = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"path\": {\"type\": \"string\", \"description\": \"File path to read\"},\n        \"mode\": {\"type\": \"string\", \"enum\": [\"r\", \"rb\"], \"default\": \"r\"},\n    },\n    \"required\": [\"path\"],\n}","handlingStrategy":"validation","validationCode":"import jsonschema\n\ndef tool_args_valid(args: dict, tool) -> bool:\n    try:\n        jsonschema.validate(args, tool.input_schema)\n        return True\n    except jsonschema.ValidationError:\n        return False","typeGuard":null,"tryCatchPattern":"from agentscope.exception import AgentOrientedException\ntry:\n    await agent.run(msg)\nexcept AgentOrientedException as e:\n    if \"Input validation failed\" in str(e):\n        # feed the error back to the model to self-correct\n        msg = UserMsg(f\"Tool call rejected: {e}\")","preventionTips":["Keep tool schemas simple: few required fields, permissive types","Write precise parameter descriptions","Test schemas against sample model outputs before deploying"],"tags":["agentscope","tool-calls","jsonschema","validation"],"backgroundTag":"json-schema-validation-failed","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}