mastra-ai/mastra · error · Error

Inputs cannot be null or undefined

Error message

Inputs cannot be null or undefined

What it means

The completeness scorer validates that both the input messages and output messages of the run contain non-null, non-undefined text content before measuring completeness. It checks every input and output message's extracted text content; if any message yields null or undefined content, it throws rather than producing a misleadingly low score. This is a fail-fast guard against malformed run data.

Source

Thrown at packages/evals/src/scorers/code/completeness/index.ts:101

    type: 'agent',
  })
    .preprocess(async ({ run }) => {
      const isInputInvalid =
        !run.input ||
        run.input.inputMessages.some((i: MastraDBMessage) => {
          const content = getTextContentFromMastraDBMessage(i);
          return content === null || content === undefined;
        });

      const isOutputInvalid =
        !run.output ||
        run.output.some((i: MastraDBMessage) => {
          const content = getTextContentFromMastraDBMessage(i);
          return content === null || content === undefined;
        });

      if (isInputInvalid || isOutputInvalid) {
        throw new Error('Inputs cannot be null or undefined');
      }

      const input = run.input?.inputMessages.map(i => getTextContentFromMastraDBMessage(i)).join(', ') || '';
      const output = run.output?.map(i => getTextContentFromMastraDBMessage(i)).join(', ') || '';

      const inputToProcess = input;
      const outputToProcess = output;

      const inputDoc = nlp(inputToProcess.trim());
      const outputDoc = nlp(outputToProcess.trim());

      // Extract and log elements
      const inputElements = extractElements(inputDoc);
      const outputElements = extractElements(outputDoc);

      return {
        inputElements,
        outputElements,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure every input and output message in the scored run contains text content (assistant messages should end with a text part)
  2. Filter out messages with null/undefined content before calling the scorer
  3. If runs legitimately end with tool calls, append or require a final textual assistant response before scoring
  4. Log the offending run's messages to find which message lacks text content and fix its construction

Example fix

// before
await completenessScorer.run({ input: { inputMessages: messages }, output });

// after
const hasText = (m: MastraDBMessage) => getTextContentFromMastraDBMessage(m) != null;
const usable = output.filter(hasText);
if (usable.length) await completenessScorer.run({ input: { inputMessages: messages.filter(hasText) }, output: usable });
Defensive patterns

Strategy: validation

Validate before calling

import { getTextContentFromMastraDBMessage } from '@mastra/core/';
const isValid = (msgs: MastraDBMessage[]) => msgs.every(m => getTextContentFromMastraDBMessage(m) != null);
if (!isValid(run.input?.inputMessages ?? []) || !isValid(run.output ?? [])) {
  throw new Error('Run contains messages without text content; fix before scoring');
}

Type guard

function hasTextContent(m: MastraDBMessage): boolean {
  return getTextContentFromMastraDBMessage(m) !== null && getTextContentFromMastraDBMessage(m) !== undefined;
}

Try / catch

try {
  await completenessScorer.run(run);
} catch (err) {
  if ((err as Error).message === 'Inputs cannot be null or undefined') {
    console.warn('Skipping run: message without text content');
    return null;
  }
  throw err;
}

Prevention

When it happens

Trigger: Running completenessScorer on a run whose input or output messages contain a message where getTextContentFromMastraDBMessage returns null/undefined — e.g. a message with no content parts, only tool calls with no text, or an empty content array.

Common situations: Scoring runs that ended in tool-call-only turns with no final assistant text; passing hand-built run objects in tests with placeholder messages; version drift where message content shape changed and the extractor no longer finds text.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/bbfc2430db81167a. Report an issue: GitHub.