JuliusBrussee/caveman · error
cave_tool_search_query_required
cave_tool_search_query_required
Error message
cave_tool_search_query_required
What it means
The built-in `cave_search_tools` recovery tool throws `cave_tool_search_query_required` when the model calls it with a `query` that is empty or whitespace-only after trimming/lowercasing. The tool searches the original, un-compacted tool definitions stored in the engine, so without a query it cannot rank or select anything. The throw happens inside `execute` and surfaces as a normal tool-call error in the agent loop.
Solutions
- Supply a non-empty `query` string containing terms from the tool name/description you are looking for.
- If a caller wraps this tool, validate the query is non-blank before forwarding and retry with a real query.
- If the model repeatedly sends empty queries, restate the task or the needed tool name in the prompt so it can form a search term.
Example fix
// before
await agent.run("find a tool", { /* model calls cave_search_tools with query: "" */ });
// after
await agent.run("Use cave_search_tools with a non-empty query, e.g. query=\"read file\", to locate the file-reading tool."); Defensive patterns
Strategy: validation
Validate before calling
function canSearch(query: unknown): query is string {
return typeof query === "string" && query.trim().length > 0;
}
if (!canSearch(args.query)) throw new Error("supply a non-empty query for cave_search_tools"); Type guard
const hasQuery = (p: unknown): p is { query: string } =>
typeof p === "object" && p !== null && typeof (p as { query?: unknown }).query === "string"; Try / catch
try {
await tools.cave_search_tools.execute(id, { query });
} catch (e) {
if ((e as Error).message === "cave_tool_search_query_required") {
return tools.cave_search_tools.execute(id, { query: fallbackQuery });
}
throw e;
} Prevention
- Never pass user/model-supplied strings to the query without trimming and checking non-empty.
- Prompt the model with an example non-empty query for the tool.
- Validate tool arguments at the wrapper level before forwarding to execute.
When it happens
Trigger: Calling `cave_search_tools` with `{ query: "" }`, `{ query: " " }`, or when the model omits/garbles the query parameter so the trimmed string is empty.
Common situations: A model hallucinating an empty argument during context-compaction recovery; a wrapper that passes through an unset variable as the query; string interpolation producing an empty string.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- invalid_recovery_arguments
- Recovery requires its scoped handle
- apiKey, baseURL, and agent are required
- arm must be or
- artifact_id is required
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/bedbf2202c9e6af9.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/runtime.ts:3067
};
},
};
}
function toolSchemaSearchTool(
handles: ReadonlySet<string>,
engineBin: string | undefined,
trace?: MutableTransformTrace[],
): AgentTool<TSchema> {
return {
name: "cave_search_tools",
label: "cave_search_tools",
description: "Search exact original tool definitions when compacted annotations are insufficient.",
parameters: Type.Object({ query: Type.String() }),
executionMode: "parallel",
async execute(_toolCallId, params) {
const query = (params as { query: string }).query.trim().toLowerCase();
if (query === "") throw new Error("cave_tool_search_query_required");
const terms = tokenize(query);
const hits: Array<{ score: number; value: Record<string, unknown>; handle: string }> = [];
for (const handle of handles) {
const original = await engineRetrieve(handle, undefined, engineBin);
let parsed: unknown;
try {
parsed = JSON.parse(new TextDecoder().decode(original));
} catch {
continue;
}
if (!isRecord(parsed) || typeof parsed.name !== "string" ||
typeof parsed.description !== "string" || !isRecord(parsed.input)) continue;
const haystack = `${parsed.name} ${parsed.description} ${JSON.stringify(parsed.input)}`.toLowerCase();
const score = terms.reduce((total, term) => total + (haystack.includes(term) ? 1 : 0), 0);
if (score > 0) hits.push({ score, value: parsed, handle });
}
hits.sort((first, second) => second.score - first.score ||
String(first.value.name).localeCompare(String(second.value.name)));View on GitHub (pinned to 3ee70a1026)