{"record":{"id":"e2184236f46a263b","repo":"mastra-ai/mastra","slug":"query-is-required-for-mode-search","errorCode":null,"errorMessage":"query is required for mode=\"search\"","messagePattern":"query is required for mode=\"search\"","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/tools/om-tools.ts","lineNumber":1386,"sourceCode":"      if (!memory) {\n        throw new Error('Memory instance is required for recall');\n      }\n\n      if (explicitThreadId === 'current' && !currentThreadId) {\n        throw new Error('Could not resolve current thread.');\n      }\n\n      // Search mode\n      if (mode === 'search') {\n        // Schema validation rejects mode=\"search\" when search is disabled, but\n        // validation is skipped for resumed runs and builder-validated input —\n        // a stale search call on those paths would otherwise reach\n        // Memory.searchMessages and throw. Return guidance instead.\n        if (!searchEnabled) {\n          return { results: SEARCH_NOT_CONFIGURED_MESSAGE, count: 0 };\n        }\n        if (!query) {\n          throw new Error('query is required for mode=\"search\"');\n        }\n        if (!resourceId) {\n          throw new Error('Resource ID is required for recall');\n        }\n        return searchMessagesForResource({\n          memory,\n          resourceId,\n          currentThreadId: currentThreadId || undefined,\n          query,\n          topK: limit ?? 10,\n          before,\n          after,\n          threadScope: !isResourceScope ? currentThreadId || undefined : resolvedExplicitThreadId || undefined,\n        });\n      }\n\n      // Thread listing mode\n      if (mode === 'threads') {","sourceCodeStart":1368,"sourceCodeEnd":1404,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/tools/om-tools.ts#L1368-L1404","documentation":"In the recall tool's search mode (om-tools.ts:1385-1387), query is mandatory: semantic search forwards it to Memory.searchMessages. This runtime guard exists because input validation can be skipped on resumed runs and builder-validated input, so a search call without a query string would otherwise crash deeper in the stack; the tool throws this explicit error instead.","triggerScenarios":"LLM invokes the recall tool with mode='search' but no query (or empty query) in inputData on a path where JSON-schema validation was bypassed (resumed workflows, pre-validated tool args).","commonSituations":"Model hallucinating incomplete tool arguments; persisted/resumed agent runs replaying a search call with truncated input; programmatic tool invocation constructing inputData by hand without query; prompt designs that encourage search without a search term.","solutions":["Ensure prompts/tool descriptions guide the model to always supply a query when mode='search'.","In code that invokes the tool programmatically, include query: recallToolArgs = { mode: 'search', query: '...' }.","Catch the error in a tool-middleware and re-prompt the model to provide a search term.","On resumed runs, re-validate inputData (query non-empty string) before executing the search branch."],"exampleFix":"// before\nawait tool.execute({ mode: 'search' });\n// after\nif (args.mode === 'search' && !args.query) {\n  throw new Error('mode=\"search\" requires a non-empty query');\n}\nawait tool.execute(args);","handlingStrategy":"validation","validationCode":"// before executing a search-mode recall call\nif (args.mode === 'search' && (typeof args.query !== 'string' || args.query.trim().length === 0)) {\n  throw new Error('mode=\"search\" requires a non-empty query');\n}","typeGuard":"function isSearchInput(\n  args: { mode?: string; query?: string }\n): args is { mode: 'search'; query: string } {\n  return args.mode === 'search' && typeof args.query === 'string' && args.query.trim().length > 0;\n}","tryCatchPattern":"try {\n  return await recallExecute(inputData, context);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('query is required')) {\n    return { error: 'Provide a search query when using mode=\"search\".' };\n  }\n  throw err;\n}","preventionTips":["Re-validate inputData on resumed/replayed tool runs even if schema validation ran originally.","Write tool descriptions that require query for search so models supply it.","Sanitize empty/whitespace queries to undefined upstream and handle once."],"tags":["memory","validation","search","tool-arguments"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}