agentscope-ai/agentscope · error · ValueError
Invalid input_schema: {self.tool.input_schema}.
Error message
Invalid input_schema: {self.tool.input_schema}. What it means
ToolMetadata's __post_init__ validates that a tool's input_schema, if provided, is a JSON-Schema object of type 'object' with a dict 'properties' entry — the shape OpenAI-style function-calling APIs require. Anything else (missing 'type', non-dict, wrong type value) is rejected.
Source
Thrown at src/agentscope/tool/_types.py:52
"""The base model used to extend the JSON schema of the original tool
function, so that we can dynamically adjust the tool function."""
# Tools management fields
group: str | Literal["basic"] = "basic"
"""The belonging group of the tool function"""
original_name: str | None = field(default=None)
"""The original name of the tool function when it has been renamed."""
def __post_init__(self) -> None:
"""Validate the registered tool function after initialization."""
# validate schema
if self.tool.input_schema is not None:
if not (
isinstance(self.tool.input_schema, dict)
and self.tool.input_schema.get("type") == "object"
and isinstance(self.tool.input_schema.get("properties"), dict)
):
raise ValueError(
f"Invalid input_schema: {self.tool.input_schema}. ",
)
def get_tool_schema(
self,
extended_model: Type[BaseModel] | None = None,
) -> dict:
"""Get the JSON schema of the tool function via the following steps:
1. Remove preset_kwargs from the JSON schema, since they are not
exposed to the agent.
2. If extended_model is provided, merge its schema with the
current function schema.
Args:
extended_model (`Type[BaseModel] | None`, optional):
The dynamic BaseModel used to extend the original function. If
provided, the given BaseModel will be merged into the originalView on GitHub (pinned to e90f1c7592)
Solutions
- Make the schema a dict literal like {'type': 'object', 'properties': {...}}
- If generating from pydantic, use Model.model_json_schema() and ensure the top level is an object schema (it normally is)
- Pass None instead of {} if the tool takes no arguments
Example fix
# before
tool = Tool(name='t', input_schema='{"type": "object"}') # string, not dict
# after
tool = Tool(name='t', input_schema={'type': 'object', 'properties': {'x': {'type': 'string'}}}) Defensive patterns
Strategy: validation
Validate before calling
def is_valid_tool_schema(s) -> bool:
return s is None or (isinstance(s, dict) and s.get('type') == 'object' and isinstance(s.get('properties'), dict))
assert is_valid_tool_schema(schema) Type guard
def is_valid_tool_schema(s) -> bool:
return s is None or (isinstance(s, dict) and s.get('type') == 'object' and isinstance(s.get('properties'), dict)) Prevention
- Generate schemas from pydantic models via model_json_schema() rather than hand-writing
- Unit-test tool construction to catch schema errors early
When it happens
Trigger: Setting tool input_schema to a non-dict, a schema without {'type': 'object'}, or where 'properties' is not a dict — e.g. passing a pydantic model's model_json_schema() result whose top level is not an object schema, or a list/JSON string.
Common situations: Hand-writing schemas and omitting 'type': 'object'; passing a JSON string instead of a parsed dict; wrapping the schema in {'parameters': ...} or {'schema': ...} by mistake; schema versions that emit 'properties' differently.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- The field `{key}` already exists in the original function sc
- Invalid logging level: {level}. Must be one of 'INFO', 'DEBU
- The 'reserve_ratio' of the context config must be smaller th
- The 'context_buffer_ratio' of the injection config must be s
- Input validation failed for tool '{tool_call.name}': {e.mess
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/97bee79ae3579114.
Report an issue: GitHub.