{"record":{"id":"b11134bfc3f2a395","repo":"JuliusBrussee/caveman","slug":"recordoutcome-values-must-be-a-non-empty-plain-ob","errorCode":null,"errorMessage":"recordOutcome: values must be a non-empty plain object","messagePattern":"recordOutcome: values must be a non-empty plain object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mastra/src/index.ts","lineNumber":650,"sourceCode":" *\n * Fails closed BEFORE any network call on a missing task id, a missing contract,\n * empty values, an evidence map that is empty or over the server's limit, a\n * confidence outside [0,1], or values that are not plain JSON. Exactly one\n * request is made — no retries — and a non-2xx response throws a\n * {@link CavemanOutcomeError} carrying the status and body verbatim.\n */\nexport async function recordOutcome(\n  client: CavemanOutcomeClient,\n  input: RecordOutcomeInput,\n): Promise<RecordOutcomeResult> {\n  const controlApiUrl = requireBaseUrl(client.controlApiUrl, \"recordOutcome: controlApiUrl\");\n  const token = requireNonEmpty(client.token, \"recordOutcome: token\");\n  const projectId = requireNonEmpty(client.projectId, \"recordOutcome: projectId\");\n  const taskId = requireNonEmpty(input.taskId, \"recordOutcome: taskId\");\n  const contract = requireNonEmpty(input.contract, \"recordOutcome: contract\");\n\n  if (!isPlainObject(input.values) || Object.keys(input.values).length === 0) {\n    throw new Error(\"recordOutcome: values must be a non-empty plain object\");\n  }\n  if (!isPlainObject(input.evidence)) {\n    throw new Error(\"recordOutcome: evidence must be a plain object\");\n  }\n  const evidenceRefs = Object.entries(input.evidence).map(([key, value]) => {\n    if (!key.trim()) throw new Error(\"recordOutcome: evidence keys must be non-empty\");\n    if (typeof value !== \"string\" && typeof value !== \"number\" && typeof value !== \"boolean\") {\n      throw new Error(`recordOutcome: evidence.${key} must be a string, number, or boolean`);\n    }\n    if (typeof value === \"number\" && !Number.isFinite(value)) {\n      throw new Error(`recordOutcome: evidence.${key} must be a finite number`);\n    }\n    const ref = `${key}:${String(value)}`;\n    if (!ref.slice(key.length + 1)) throw new Error(`recordOutcome: evidence.${key} must be non-empty`);\n    return ref;\n  });\n  if (evidenceRefs.length === 0) {\n    throw new Error(\"recordOutcome: evidence must contain at least one reference\");","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/packages/mastra/src/index.ts#L632-L668","documentation":"recordOutcome sends a scored outcome to the Caveman control API; the values field carries the actual scored fields, so it must be a plain object with at least one entry — each key/value becomes an outcome value the platform stores. Arrays, strings, null, Map instances, class instances, and the empty object {} are all rejected before any network call is made.","triggerScenarios":"recordOutcome(client, { taskId, contract, values: {} }) — or values passed as a JSON string ('{\"passed\":true}'), an array, or null.","commonSituations":"Building values dynamically and the source object ended up empty (e.g. all fields optional and none present); double-serializing JSON; any-typed payloads that bypass compile-time checks.","solutions":["Ensure values has at least one entry, e.g. { passed: true }","Pass a plain object literal — JSON.parse strings first, spread Maps with Object.fromEntries","Log the built values object right before the call when it is assembled dynamically"],"exampleFix":"// before\nrecordOutcome(client, { taskId, contract, values: JSON.stringify({ passed }) });\n\n// after\nrecordOutcome(client, { taskId, contract, values: { passed } });","handlingStrategy":"validation","validationCode":"function isPlainObject(v: unknown): v is Record<string, unknown> {\n  return typeof v === 'object' && v !== null &&\n    (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);\n}\n\nfunction valuesOk(v: unknown): boolean {\n  return isPlainObject(v) && Object.keys(v).length > 0;\n}","typeGuard":"function isRecordOutcomeValues(v: unknown): v is Record<string, string | number | boolean> {\n  return isPlainObject(v) && Object.keys(v).length > 0 &&\n    Object.values(v).every((x) => ['string', 'number', 'boolean'].includes(typeof x));\n}","tryCatchPattern":null,"preventionTips":["Type the values payload explicitly instead of any","Unit-test the payload builder for the empty case","JSON.parse stringified payloads and check the shape before sending"],"tags":["validation","api-misuse","outcome","mastra"],"backgroundTag":"schema-validation-failed","analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}