{"record":{"id":"97bee79ae3579114","repo":"agentscope-ai/agentscope","slug":"invalid-input-schema-self-tool-input-schema","errorCode":null,"errorMessage":"Invalid input_schema: {self.tool.input_schema}. ","messagePattern":"Invalid input_schema: (.+?)\\. ","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/tool/_types.py","lineNumber":52,"sourceCode":"    \"\"\"The base model used to extend the JSON schema of the original tool\n    function, so that we can dynamically adjust the tool function.\"\"\"\n\n    # Tools management fields\n    group: str | Literal[\"basic\"] = \"basic\"\n    \"\"\"The belonging group of the tool function\"\"\"\n    original_name: str | None = field(default=None)\n    \"\"\"The original name of the tool function when it has been renamed.\"\"\"\n\n    def __post_init__(self) -> None:\n        \"\"\"Validate the registered tool function after initialization.\"\"\"\n        # validate schema\n        if self.tool.input_schema is not None:\n            if not (\n                isinstance(self.tool.input_schema, dict)\n                and self.tool.input_schema.get(\"type\") == \"object\"\n                and isinstance(self.tool.input_schema.get(\"properties\"), dict)\n            ):\n                raise ValueError(\n                    f\"Invalid input_schema: {self.tool.input_schema}. \",\n                )\n\n    def get_tool_schema(\n        self,\n        extended_model: Type[BaseModel] | None = None,\n    ) -> dict:\n        \"\"\"Get the JSON schema of the tool function via the following steps:\n\n        1. Remove preset_kwargs from the JSON schema, since they are not\n        exposed to the agent.\n        2. If extended_model is provided, merge its schema with the\n        current function schema.\n\n        Args:\n            extended_model (`Type[BaseModel] | None`, optional):\n                The dynamic BaseModel used to extend the original function. If\n                provided, the given BaseModel will be merged into the original","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/tool/_types.py#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ntool = Tool(name='t', input_schema='{\"type\": \"object\"}')  # string, not dict\n# after\ntool = Tool(name='t', input_schema={'type': 'object', 'properties': {'x': {'type': 'string'}}})","handlingStrategy":"validation","validationCode":"def is_valid_tool_schema(s) -> bool:\n    return s is None or (isinstance(s, dict) and s.get('type') == 'object' and isinstance(s.get('properties'), dict))\n\nassert is_valid_tool_schema(schema)","typeGuard":"def is_valid_tool_schema(s) -> bool:\n    return s is None or (isinstance(s, dict) and s.get('type') == 'object' and isinstance(s.get('properties'), dict))","tryCatchPattern":null,"preventionTips":["Generate schemas from pydantic models via model_json_schema() rather than hand-writing","Unit-test tool construction to catch schema errors early"],"tags":["schema","validation","json-schema","tool"],"backgroundTag":"schema-validation-failed","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}