{"record":{"id":"d5e62e37c383c2b7","repo":"Tencent/WeKnora","slug":"knowledge-base-ids-is-required","errorCode":null,"errorMessage":"knowledge_base_ids is required","messagePattern":"knowledge_base_ids is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/query_knowledge_graph.go","lineNumber":121,"sourceCode":"}\n\n// Execute performs the knowledge graph query with concurrent KB processing\nfunc (t *QueryKnowledgeGraphTool) Execute(ctx context.Context, args json.RawMessage) (*types.ToolResult, error) {\n\t// Parse args from json.RawMessage\n\tvar input QueryKnowledgeGraphInput\n\tif err := json.Unmarshal(args, &input); err != nil {\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   fmt.Sprintf(\"Failed to parse args: %v\", err),\n\t\t}, err\n\t}\n\n\t// Extract knowledge_base_ids array\n\tif len(input.KnowledgeBaseIDs) == 0 {\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   \"knowledge_base_ids is required and must be a non-empty array\",\n\t\t}, fmt.Errorf(\"knowledge_base_ids is required\")\n\t}\n\n\t// Validate max 10 KBs\n\tif len(input.KnowledgeBaseIDs) > 10 {\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   \"knowledge_base_ids must contain at most 10 KB IDs\",\n\t\t}, fmt.Errorf(\"too many KB IDs\")\n\t}\n\tif t.scopeEnforced {\n\t\tif err := validateKnowledgeBaseIDsInSearchTargets(t.searchTargets, input.KnowledgeBaseIDs); err != nil {\n\t\t\treturn &types.ToolResult{Success: false, Error: err.Error()}, err\n\t\t}\n\t}\n\n\tquery := input.Query\n\tif query == \"\" {\n\t\treturn &types.ToolResult{","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/query_knowledge_graph.go#L103-L139","documentation":"QueryKnowledgeGraph.Execute requires knowledge_base_ids to be a non-empty array since graph queries run per-KB. When the array is empty or missing it returns this error with a ToolResult explaining the requirement. Pure input validation before any KB is contacted.","triggerScenarios":"Calling query_knowledge_graph with knowledge_base_ids absent, empty array [], or a non-array value that decodes to a nil slice.","commonSituations":"Agent model omits the field in the tool-call JSON; caller builds params without the key; refactors renamed the parameter so old keys are ignored.","solutions":["Pass at least one KB ID in knowledge_base_ids","Validate the array is non-empty in the caller before invoking","Discover valid KB IDs via a list-knowledge-bases tool or config"],"exampleFix":"// before\nExecute(ctx, map[string]any{\"query\": \"who authored X\"})\n// after\nExecute(ctx, map[string]any{\"query\": \"who authored X\", \"knowledge_base_ids\": []string{\"kb-1\"}})","handlingStrategy":"validation","validationCode":"kbIDs, _ := input[\"knowledge_base_ids\"].([]string)\nif len(kbIDs) == 0 { return errors.New(\"knowledge_base_ids must be a non-empty array\") }","typeGuard":"func hasKBIDs(input map[string]any) bool {\n    ids, ok := input[\"knowledge_base_ids\"].([]string)\n    return ok && len(ids) > 0\n}","tryCatchPattern":"res, err := tool.Execute(ctx, input)\nif err != nil && strings.Contains(err.Error(), \"knowledge_base_ids is required\") {\n    return res, nil // ToolResult.Error documents the requirement\n}","preventionTips":["Always include knowledge_base_ids in graph query params","Discover valid KB IDs via a listing tool or config first","Instruct the agent model that knowledge_base_ids is mandatory","Share the non-empty KB list across related tool calls"],"tags":["go","agent-tools","knowledge-graph","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}