{"record":{"id":"c0772a2ca305823f","repo":"iflytek/astron-agent","slug":"update-tool-failed-to-validate-tool-tool-get-id-schema","errorCode":null,"errorMessage":"update tool: failed to validate tool {tool.get('id')} schema, reason {json.dumps(err)}","messagePattern":"update tool: failed to validate tool (.+?) schema, reason (.+?)","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"core/plugin/link/service/community/tools/http/management_server.py","lineNumber":295,"sourceCode":"def process_tools_for_update(\n    tools: List[Dict[str, Any]], app_id: Optional[str], span_context: Any\n) -> Tuple[Optional[List[Dict[str, Any]]], List[str]]:\n    \"\"\"Process tools for update, including validation.\"\"\"\n    update_tool = []\n    tool_ids = []\n\n    for tool in tools:\n        # Validate required fields\n        required_fields = [\"version\", \"name\", \"description\", \"openapi_schema\"]\n        for field in required_fields:\n            if field not in tool:\n                raise Exception(f\"no {field} attr found in tool info!\")\n\n        schema_content = tool.get(\"openapi_schema\", \"\")\n        if schema_content:\n            validated_schema, err = validate_openapi_schema(tool, span_context)\n            if err:\n                raise Exception(\n                    f\"update tool: failed to validate tool {tool.get('id')} schema, \"\n                    f\"reason {json.dumps(err)}\"\n                )\n            schema_content = validated_schema\n\n        update_tool.append(\n            {\n                \"app_id\": app_id,\n                \"tool_id\": tool.get(\"id\"),\n                \"name\": tool.get(\"name\"),\n                \"description\": tool.get(\"description\"),\n                \"open_api_schema\": schema_content,\n                \"version\": tool.get(\"version\", const.DEF_VER),\n                \"is_deleted\": const.DEF_DEL,\n            }\n        )\n        tool_ids.append(tool.get(\"id\") or \"\")\n","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/link/service/community/tools/http/management_server.py#L277-L313","documentation":"Generic Exception raised when validate_openapi_schema returns an error for a tool's openapi_schema during update. It wraps the validator's structured error list (JSON-serialized) so the caller knows which tool failed and why.","triggerScenarios":"update_version -> process_tools_for_update with a non-empty openapi_schema that fails validate_openapi_schema — invalid OpenAPI document (missing paths/info, wrong types, bad version string, unresolved $refs).","commonSituations":"Hand-authored or LLM-generated OpenAPI specs uploaded without validation; specs written against OpenAPI 2.0 (Swagger) syntax submitted to a 3.x validator; schema truncated by size limits or encoding issues.","solutions":["Validate the openapi_schema locally (e.g. with openapi-spec-validator) before submitting the update and fix reported violations.","Read the serialized 'err' payload in the exception — it lists the concrete validation failures to fix.","Ensure the schema uses OpenAPI 3.x structure (openapi: 3.0.x, paths, components.schemas) not Swagger 2.0.","Confirm the schema was not truncated or mangled in transit (compare lengths/hashes before and after upload)."],"exampleFix":"// before\nraise Exception(\n    f\"update tool: failed to validate tool {tool.get('id')} schema, \"\n    f\"reason {json.dumps(err)}\")\n// after\n# fix the spec client-side first:\n#   from openapi_spec_validator import validate\n#   validate(json.loads(tool[\"openapi_schema\"]))\n# then resubmit; keep server-side raise but return HTTP 422 with err details","handlingStrategy":"validation","validationCode":"from openapi_spec_validator import validate\nimport json\ndef schema_is_valid(tool: dict) -> bool:\n    try:\n        validate(json.loads(tool[\"openapi_schema\"]))\n        return True\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    process_tools_for_update(tools, span_context)\nexcept Exception as e:\n    return error_response(422, f\"schema invalid: {e}\")","preventionTips":["Validate OpenAPI specs client-side before upload","Ensure specs are OpenAPI 3.x, not Swagger 2.0","Check schema integrity (no truncation) after transport"],"tags":["openapi","schema-validation","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}