{"record":{"id":"76d08552a61ea530","repo":"Tencent/WeKnora","slug":"missing-query-76d085","errorCode":null,"errorMessage":"missing query","messagePattern":"missing query","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/search_memory.go","lineNumber":102,"sourceCode":"}\n\n// Execute searches the user's own long-term memory.\nfunc (t *SearchMemoryTool) Execute(\n\tctx context.Context, args json.RawMessage,\n) (*types.ToolResult, error) {\n\tvar input SearchMemoryInput\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\tquery := strings.TrimSpace(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(\"missing query\")\n\t}\n\tif t.memoryService == nil {\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   \"long-term memory is not available\",\n\t\t}, fmt.Errorf(\"no memory service\")\n\t}\n\n\tlimit := input.Limit\n\tif limit <= 0 {\n\t\tlimit = types.MemorySearchDefaultItems\n\t}\n\tif limit > types.MemorySearchMaxItems {\n\t\tlimit = types.MemorySearchMaxItems\n\t}\n\n\tresult := t.memoryService.SearchMemory(ctx, query, limit)\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/search_memory.go#L84-L120","documentation":"SearchMemoryTool.Execute returns \"missing query\" when the tool input's Query field is empty or whitespace-only after TrimSpace. The library requires a non-empty search string to run a long-term-memory lookup, and it also returns a ToolResult with Success=false and Error=\"query is required\" alongside this Go error. It is a guard against issuing meaningless empty memory searches.","triggerScenarios":"Calling Execute on SearchMemoryTool with input.Query == \"\" or containing only whitespace (e.g. spaces/tabs/newlines), typically because the model emitted an empty query argument or the caller built ToolInput without setting Query.","commonSituations":"LLM providers emit an empty tool argument; code paths that construct the tool input programmatically forget to populate Query; templates or prompts that leave the query blank; deserialized JSON where the query key is missing.","solutions":["Set a non-empty Query string on the tool input before calling Execute.","Trim and validate the query in your own code before invoking the tool.","If the query originates from model output, re-prompt or fall back when the argument is blank."],"exampleFix":"// before\nres, err := tool.Execute(ctx, types.ToolInput{Query: \"\"})\n// after\nq := strings.TrimSpace(modelArg)\nif q == \"\" {\n    return errors.New(\"search_memory requires a non-empty query\")\n}\nres, err := tool.Execute(ctx, types.ToolInput{Query: q})","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(input.Query) == \"\" {\n    return errors.New(\"search_memory requires a non-empty query\")\n}","typeGuard":"func hasQuery(input types.ToolInput) bool { return strings.TrimSpace(input.Query) != \"\" }","tryCatchPattern":"res, err := tool.Execute(ctx, input)\nif err != nil && strings.Contains(err.Error(), \"missing query\") {\n    // prompt for or default a query before retrying\n}","preventionTips":["Always trim and check the query before tool invocation","Set tool schemas so the query argument is required for the model","Add a fallback default query for blank model output"],"tags":["validation","memory","tool-input"],"backgroundTag":"missing-required-argument","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}