{"record":{"id":"6bb1121922d4b4ad","repo":"JuliusBrussee/caveman","slug":"filter-monitor-has-unknown-key-s-monitorunknown-sort-join","errorCode":null,"errorMessage":"filter monitor has unknown key(s): ${monitorUnknown.sort().join(\", \")}","messagePattern":"filter monitor has unknown key\\(s\\): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/agent-mcp.ts","lineNumber":492,"sourceCode":"    if (key === \"status_class\" && value.some((entry) => ![\"2xx\", \"4xx\", \"5xx\"].includes(entry as string))) {\n      throw new Error(\"filter status_class values must be 2xx, 4xx, or 5xx\");\n    }\n  }\n  for (const key of [\"min_cost_usd\", \"max_cost_usd\", \"min_total_tokens\", \"max_total_tokens\", \"min_latency_ms\", \"max_latency_ms\"]) {\n    const value = filters[key];\n    if (value !== undefined && (typeof value !== \"number\" || !Number.isFinite(value))) {\n      throw new Error(`filter ${key} must be a finite number`);\n    }\n  }\n  for (const key of [\"has_error\", \"compressed\"]) {\n    const value = filters[key];\n    if (value !== undefined && typeof value !== \"boolean\") throw new Error(`filter ${key} must be a boolean`);\n  }\n  const monitor = filters.monitor;\n  if (monitor !== undefined) {\n    if (!monitor || typeof monitor !== \"object\" || Array.isArray(monitor)) throw new Error(\"filter monitor must be an object\");\n    const monitorUnknown = Object.keys(monitor).filter((key) => key !== \"id\" && key !== \"verdict\");\n    if (monitorUnknown.length > 0) throw new Error(`filter monitor has unknown key(s): ${monitorUnknown.sort().join(\", \")}`);\n    if (typeof monitor.id !== \"string\" || monitor.id.trim() === \"\") throw new Error(\"filter monitor.id is required\");\n    if (typeof monitor.verdict !== \"string\" || ![\"pass\", \"fail\", \"error\"].includes(monitor.verdict)) {\n      throw new Error(\"filter monitor.verdict must be pass, fail, or error\");\n    }\n  }\n}\n\nfunction optionalEnum(args: JSONObject, key: string, values: string[]): void {\n  const value = args[key];\n  if (value !== undefined && (typeof value !== \"string\" || !values.includes(value))) {\n    throw new Error(`${key} must be one of ${values.join(\", \")}`);\n  }\n}\n\nfunction validateTraceSearch(args: JSONObject): void {\n  validateTraceFilters(args);\n  for (const key of [\"from\", \"to\"]) {\n    const value = args[key];","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/agent-mcp.ts#L474-L510","documentation":"The trace_search tool's validateTraceFilters rejects a `monitor` filter object containing keys other than `id` and `verdict`. The library whitelists exactly these two sub-fields to keep the filter schema strict, so any extra key (typo, renamed field, or nested object) produces this error listing the offending keys sorted alphabetically.","triggerScenarios":"Calling the trace_search MCP tool with arguments like {\"filter\":{\"monitor\":{\"id\":\"m_1\",\"verdict\":\"pass\",\"note\":\"x\"}}} — any key in filter.monitor besides id/verdict, including null-valued extras or typos like \"verdicts\" or \"monitorId\".","commonSituations":"Copying a filter shape from a different endpoint that allows more monitor fields; adding UI metadata (label, comment) into the filter object; version drift where a newer API surface accepts more keys than this CLI's validator.","solutions":["Remove every key from filter.monitor except `id` and `verdict`.","Fix typos so keys are exactly `id` and `verdict`.","Move extra data (notes, labels) out of the filter into another argument or tool field.","Check the tool's input schema for the currently allowed monitor keys."],"exampleFix":"// before\n{ \"filter\": { \"monitor\": { \"id\": \"m_1\", \"verdict\": \"pass\", \"reason\": \"ok\" } } }\n// after\n{ \"filter\": { \"monitor\": { \"id\": \"m_1\", \"verdict\": \"pass\" } } }","handlingStrategy":"validation","validationCode":"const ALLOWED = new Set([\"id\", \"verdict\"]);\nif (filter.monitor && Object.keys(filter.monitor).some(k => !ALLOWED.has(k)))\n  throw new Error(\"filter.monitor may only contain id and verdict\");","typeGuard":"function isValidMonitorFilter(m) {\n  return typeof m === \"object\" && m !== null && !Array.isArray(m) &&\n    Object.keys(m).every(k => k === \"id\" || k === \"verdict\");\n}","tryCatchPattern":"try {\n  await traceSearch(args);\n} catch (e) {\n  if (String(e.message).startsWith(\"filter monitor has unknown key\")) {\n    args.filter.monitor = { id: args.filter.monitor.id, verdict: args.filter.monitor.verdict };\n    return traceSearch(args);\n  }\n  throw e;\n}","preventionTips":["Define the monitor filter as a typed object with only id/verdict fields.","Build filters via a factory function instead of ad-hoc object literals.","Validate against the tool's JSON schema before each call."],"tags":["validation","mcp","filter","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}