{"record":{"id":"b8881f82bcca8ab5","repo":"Tencent/WeKnora","slug":"too-many-kb-ids","errorCode":null,"errorMessage":"too many KB IDs","messagePattern":"too many KB IDs","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/query_knowledge_graph.go","lineNumber":129,"sourceCode":"\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{\n\t\t\tSuccess: false,\n\t\t\tError:   \"query is required\",\n\t\t}, fmt.Errorf(\"invalid query\")\n\t}\n\n\t// Concurrently query all knowledge bases\n\ttype graphQueryResult struct {\n\t\tkbID    string","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/query_knowledge_graph.go#L111-L147","documentation":"QueryKnowledgeGraph caps knowledge_base_ids at 10 per call to bound concurrent KB queries. Supplying more than 10 IDs returns this error before any query executes. The limit pairs with the validation that KBs must exist in the tool's search targets when scopeEnforced is set.","triggerScenarios":"Calling query_knowledge_graph with 11+ KB IDs in knowledge_base_ids.","commonSituations":"Caller dumps every KB in the tenant into the array instead of selecting relevant ones; batch scripts iterate over all KBs in one call rather than paging in groups of 10.","solutions":["Split the KB list into batches of at most 10 and issue multiple calls","Pre-filter KBs to those likely relevant before calling","Increase the cap only by modifying the tool's validation (requires code change) if legitimately needed"],"exampleFix":"// before\nExecute(ctx, {\"query\": q, \"knowledge_base_ids\": allKBs}) // 25 KBs\n// after\nfor batch := range chunk(allKBs, 10) {\n    Execute(ctx, {\"query\": q, \"knowledge_base_ids\": batch})\n}","handlingStrategy":"validation","validationCode":"if len(kbIDs) > 10 { return fmt.Errorf(\"got %d KB ids, max is 10\", len(kbIDs)) }","typeGuard":"func withinKBLimit(ids []string) bool { return len(ids) >= 1 && len(ids) <= 10 }","tryCatchPattern":"res, err := tool.Execute(ctx, input)\nif err != nil && strings.Contains(err.Error(), \"too many KB IDs\") {\n    for _, batch := range chunk(kbIDs, 10) {\n        input[\"knowledge_base_ids\"] = batch\n        res, err = tool.Execute(ctx, input)\n        if err != nil { break }\n        mergeResults(all, res)\n    }\n}","preventionTips":["Batch KB IDs into groups of 10 before calling","Pre-filter KBs by relevance instead of passing all of them","Document the 10-KB cap in caller-side helpers","Remember scopeEnforced also requires KBs to exist in search targets"],"tags":["go","agent-tools","knowledge-graph","input-validation","limit-exceeded"],"backgroundTag":"parameter-limit-exceeded","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}