{"record":{"id":"0cefc49614d7ba46","repo":"Tencent/WeKnora","slug":"missing-query-parameter","errorCode":null,"errorMessage":"missing query parameter","messagePattern":"missing query parameter","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/grep_chunks.go","lineNumber":109,"sourceCode":"\t\tlogger.Errorf(ctx, \"[Tool][GrepChunks] Failed to parse args: %v\", err)\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// Resolve the canonical single-string `query`, falling back to legacy\n\t// aliases. Legacy array inputs are joined with `|` so they degrade into\n\t// a single alternation regex — preserving the previous \"match ANY\"\n\t// semantics without requiring multiple DB scans.\n\tquery := strings.TrimSpace(input.Query)\n\n\tif query == \"\" {\n\t\tlogger.Errorf(ctx, \"[Tool][GrepChunks] Missing or empty query parameter\")\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   \"query parameter is required and must be a non-empty regex string\",\n\t\t}, fmt.Errorf(\"missing query parameter\")\n\t}\n\n\t// Compile with (?i) prefix for case-insensitive Go-side matching.\n\t// Compilation also validates the regex syntax before we send it to the DB.\n\tre, err := regexp.Compile(\"(?i)\" + query)\n\tif err != nil {\n\t\tlogger.Errorf(ctx, \"[Tool][GrepChunks] Invalid regex %q: %v\", query, err)\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   fmt.Sprintf(\"invalid regex query %q: %v\", query, err),\n\t\t}, err\n\t}\n\tqueries := []string{query}\n\tcompiled := []*regexp.Regexp{re}\n\n\t// Result count is controlled by the backend, not the caller — keep it\n\t// bounded so the LLM context stays small regardless of regex breadth.\n\tconst limit = 30","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/grep_chunks.go#L91-L127","documentation":"GrepChunks.Execute requires a non-empty 'query' parameter before doing any work. When query is empty or missing it returns this error and a ToolResult explaining that a non-empty regex string is required. It is a fail-fast input validation guard before regex compilation and DB dispatch.","triggerScenarios":"Invoking the grep_chunks tool with query=\"\", query absent from the input map, or a value that trims to nothing.","commonSituations":"LLM agent emits an empty query argument; calling code builds the params map conditionally and omits the key; template/variable interpolation yields an empty string.","solutions":["Pass a non-empty query string in the tool input","Validate/trim the query in the caller before invoking the tool","Check that the variable feeding the query is actually populated (logging/prompt output may be empty)"],"exampleFix":"// before\nExecute(ctx, map[string]any{\"query\": \"\"})\n// after\nq := strings.TrimSpace(userQuery)\nif q == \"\" { return errors.New(\"query required\") }\nExecute(ctx, map[string]any{\"query\": q})","handlingStrategy":"validation","validationCode":"q := strings.TrimSpace(params[\"query\"])\nif q == \"\" { return errors.New(\"query must be a non-empty regex string\") }\nif _, err := regexp.Compile(\"(?i)\" + q); err != nil { return fmt.Errorf(\"invalid regex: %w\", err) }","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(), \"missing query parameter\") {\n    return retryWithDefaults(ctx, input) // supply a query or report to user\n}","preventionTips":["Always trim and check the query before tool invocation","Pre-compile the regex caller-side to catch syntax errors too","Ensure agent prompts instruct the model to always supply a query","Log tool inputs to catch empty-variable cases"],"tags":["go","agent-tools","input-validation","missing-parameter"],"backgroundTag":"missing-required-argument","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}