{"record":{"id":"2bf97bf4b34302c3","repo":"Tencent/WeKnora","slug":"invalid-query","errorCode":null,"errorMessage":"invalid query","messagePattern":"invalid query","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/query_knowledge_graph.go","lineNumber":142,"sourceCode":"\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\n\t\tkb      *types.KnowledgeBase\n\t\tresults []*types.SearchResult\n\t\terr     error\n\t}\n\n\tvar wg sync.WaitGroup\n\tvar mu sync.Mutex\n\tkbResults := make(map[string]*graphQueryResult)\n\n\tsearchParams := types.SearchParams{\n\t\tQueryText:  query,\n\t\tMatchCount: 10,\n\t}","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/query_knowledge_graph.go#L124-L160","documentation":"QueryKnowledgeGraph.Execute requires a non-empty query string to run against the KB graphs. An empty or missing query returns this error with ToolResult.Error 'query is required'. Fail-fast validation before concurrent KB queries are dispatched.","triggerScenarios":"Calling query_knowledge_graph with query absent, empty string, or whitespace-only after trimming.","commonSituations":"Agent emits an empty query argument; caller passes user text untrimmed and it contains only spaces; variable feeding the query was never populated.","solutions":["Provide a non-empty query string in the tool input","Trim and validate the query in the caller before invoking","Check that the upstream variable/prompt output feeding the query is non-empty"],"exampleFix":"// before\nExecute(ctx, {\"query\": \"\", \"knowledge_base_ids\": []string{\"kb-1\"}})\n// after\nq := strings.TrimSpace(userQuestion)\nif q == \"\" { return errors.New(\"query required\") }\nExecute(ctx, {\"query\": q, \"knowledge_base_ids\": []string{\"kb-1\"}})","handlingStrategy":"validation","validationCode":"q := strings.TrimSpace(input[\"query\"])\nif q == \"\" { return errors.New(\"query is required\") }","typeGuard":"func hasQuery(input map[string]any) bool {\n    q, ok := input[\"query\"].(string)\n    return ok && strings.TrimSpace(q) != \"\"\n}","tryCatchPattern":"res, err := tool.Execute(ctx, input)\nif err != nil && strings.Contains(err.Error(), \"invalid query\") {\n    return promptUserForQuery(), nil\n}","preventionTips":["Trim the query and reject whitespace-only strings","Populate the query from validated user input, never unset variables","Instruct the agent model that query is mandatory","Log outgoing params to catch silently-empty queries"],"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-08T10:18:20.063Z"}