agentscope-ai/agentscope · error · AgentOrientedException
Input validation failed for tool '{tool_call.name}': {e.mess
Error message
Input validation failed for tool '{tool_call.name}': {e.message} What it means
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.
Source
Thrown at src/agentscope/agent/_agent.py:2306
try:
# Check if the tool is available
tool = await self.toolkit.check_tool_available(
tool_call.name,
self.state.tool_context.activated_groups,
)
# Try to parse the input with the tool schema
parsed_input = _json_loads_with_repair(
tool_call.input,
tool.input_schema,
)
# Validate the parsed input with the tool schema
# TODO: Maybe some logic to mix the validation error in runtime
try:
jsonschema.validate(parsed_input, tool.input_schema)
except jsonschema.ValidationError as e:
raise AgentOrientedException(
f"Input validation failed for tool '{tool_call.name}': "
f"{e.message}",
) from e
# The exceptions that
# - cannot found tool
# - tool not available
# - input parsing failure
except AgentOrientedException as e:
async for evt in self._handle_error_tool_call(
tool_call,
e.message,
state=ToolResultState.ERROR,
):
yield evt
return
View on GitHub (pinned to e90f1c7592)
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
Example fix
# before
input_schema = {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path", "mode"],
}
# after
input_schema = {
"type": "object",
"properties": {
"path": {"type": "string", "description": "File path to read"},
"mode": {"type": "string", "enum": ["r", "rb"], "default": "r"},
},
"required": ["path"],
} Defensive patterns
Strategy: validation
Validate before calling
import jsonschema
def tool_args_valid(args: dict, tool) -> bool:
try:
jsonschema.validate(args, tool.input_schema)
return True
except jsonschema.ValidationError:
return False Try / catch
from agentscope.exception import AgentOrientedException
try:
await agent.run(msg)
except AgentOrientedException as e:
if "Input validation failed" in str(e):
# feed the error back to the model to self-correct
msg = UserMsg(f"Tool call rejected: {e}") Prevention
- Keep tool schemas simple: few required fields, permissive types
- Write precise parameter descriptions
- Test schemas against sample model outputs before deploying
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid structured output from model {model_name}: {e}
- One or more tool calls raised an exception
- The injection template must contain the '{runtime_state}' pl
- Expected a 5-field cron expression, got {record.data.cron_ex
- Invalid values for MCP {card.name!r}: {e.message}
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/5284f0388485ee0f.
Report an issue: GitHub.