JuliusBrussee/caveman · error

recordOutcome: values must be a non-empty plain object

Error message

recordOutcome: values must be a non-empty plain object

What it means

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.

Solutions

  1. Ensure values has at least one entry, e.g. { passed: true }
  2. Pass a plain object literal — JSON.parse strings first, spread Maps with Object.fromEntries
  3. Log the built values object right before the call when it is assembled dynamically

Example fix

// before
recordOutcome(client, { taskId, contract, values: JSON.stringify({ passed }) });

// after
recordOutcome(client, { taskId, contract, values: { passed } });
Defensive patterns

Strategy: validation

Validate before calling

function isPlainObject(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null &&
    (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
}

function valuesOk(v: unknown): boolean {
  return isPlainObject(v) && Object.keys(v).length > 0;
}

Type guard

function isRecordOutcomeValues(v: unknown): v is Record<string, string | number | boolean> {
  return isPlainObject(v) && Object.keys(v).length > 0 &&
    Object.values(v).every((x) => ['string', 'number', 'boolean'].includes(typeof x));
}

Prevention

When it happens

Trigger: recordOutcome(client, { taskId, contract, values: {} }) — or values passed as a JSON string ('{"passed":true}'), an array, or null.

Common situations: 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.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/b11134bfc3f2a395. Report an issue: GitHub.

Appendix: source

Thrown at packages/mastra/src/index.ts:650

 *
 * Fails closed BEFORE any network call on a missing task id, a missing contract,
 * empty values, an evidence map that is empty or over the server's limit, a
 * confidence outside [0,1], or values that are not plain JSON. Exactly one
 * request is made — no retries — and a non-2xx response throws a
 * {@link CavemanOutcomeError} carrying the status and body verbatim.
 */
export async function recordOutcome(
  client: CavemanOutcomeClient,
  input: RecordOutcomeInput,
): Promise<RecordOutcomeResult> {
  const controlApiUrl = requireBaseUrl(client.controlApiUrl, "recordOutcome: controlApiUrl");
  const token = requireNonEmpty(client.token, "recordOutcome: token");
  const projectId = requireNonEmpty(client.projectId, "recordOutcome: projectId");
  const taskId = requireNonEmpty(input.taskId, "recordOutcome: taskId");
  const contract = requireNonEmpty(input.contract, "recordOutcome: contract");

  if (!isPlainObject(input.values) || Object.keys(input.values).length === 0) {
    throw new Error("recordOutcome: values must be a non-empty plain object");
  }
  if (!isPlainObject(input.evidence)) {
    throw new Error("recordOutcome: evidence must be a plain object");
  }
  const evidenceRefs = Object.entries(input.evidence).map(([key, value]) => {
    if (!key.trim()) throw new Error("recordOutcome: evidence keys must be non-empty");
    if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
      throw new Error(`recordOutcome: evidence.${key} must be a string, number, or boolean`);
    }
    if (typeof value === "number" && !Number.isFinite(value)) {
      throw new Error(`recordOutcome: evidence.${key} must be a finite number`);
    }
    const ref = `${key}:${String(value)}`;
    if (!ref.slice(key.length + 1)) throw new Error(`recordOutcome: evidence.${key} must be non-empty`);
    return ref;
  });
  if (evidenceRefs.length === 0) {
    throw new Error("recordOutcome: evidence must contain at least one reference");

View on GitHub (pinned to 766dce6b13)