mastra-ai/mastra · error · MastraError
INVALID_DATA_ITEM
INVALID_DATA_ITEM
Error message
Invalid data item at index ${i}: must have 'input', 'inputs', or 'turns' property What it means
Each item in an eval dataset must be an object containing at least one of `input`, `inputs`, or `turns`. `validateEvalsInputs` iterates the data array and throws a MastraError (id INVALID_DATA_ITEM, category USER) at the first index that is null/non-object or lacks all three keys. This is a dataset shape contract enforced before running the experiment.
Source
Thrown at packages/core/src/evals/run/index.ts:690
): void {
const hasGates = !!gates && gates.length > 0;
if (data.length === 0) {
throw new MastraError({
domain: 'SCORER',
id: 'RUN_EXPERIMENT_FAILED_NO_DATA_PROVIDED',
category: 'USER',
text: 'Failed to run experiment: Data array is empty',
});
}
// Tracks whether any data item carries per-turn gates/scorers, which (like
// top-level scorers/gates) satisfies the "at least one scorer or gate" rule.
let hasAnyTurnAssertions = false;
for (let i = 0; i < data.length; i++) {
const item = data[i];
if (!item || typeof item !== 'object' || (!('input' in item) && !('inputs' in item) && !('turns' in item))) {
throw new MastraError({
domain: 'SCORER',
id: 'INVALID_DATA_ITEM',
category: 'USER',
text: `Invalid data item at index ${i}: must have 'input', 'inputs', or 'turns' property`,
});
}
if ('inputs' in item) {
if (!Array.isArray(item.inputs) || item.inputs.length === 0) {
throw new MastraError({
domain: 'SCORER',
id: 'INVALID_DATA_ITEM',
category: 'USER',
text: `Invalid data item at index ${i}: 'inputs' must be a non-empty array`,
});
}
if (isWorkflow(target)) {
throw new MastraError({
domain: 'SCORER',View on GitHub (pinned to 75dd419e61)
Solutions
- Give every data item an `input` key (or `inputs` for multi-input, `turns` for conversations)
- Normalize the dataset before calling runEvals: map raw records into `{ input: ... }` shape
- Validate/parse the dataset with a schema (zod) before running to catch bad indices early
- Check for holes/undefined entries created by `map`/`filter` on sparse arrays
Example fix
// before
const data = [
{ prompt: 'What is 2+2?' }, // wrong key -> INVALID_DATA_ITEM
];
// after
const data = [
{ input: 'What is 2+2?' },
]; Defensive patterns
Strategy: validation
Validate before calling
function isValidDataItem(item) {
return !!item && typeof item === 'object'
&& ('input' in item || 'inputs' in item || 'turns' in item);
}
data.forEach((item, i) => { if (!isValidDataItem(item)) throw new Error(`Bad eval item at index ${i}`); }); Type guard
function isEvalDataItem(item: unknown): item is { input?: unknown; inputs?: unknown; turns?: unknown } {
return typeof item === 'object' && item !== null
&& ('input' in item || 'inputs' in item || 'turns' in item);
}
const valid: EvalItem[] = data.filter(isEvalDataItem); Try / catch
try {
await mastra.runEvals({ data, scorers, target });
} catch (e) {
if (e instanceof MastraError && e.id === 'INVALID_DATA_ITEM') {
console.error(e.message); // names the offending index — fix that record's shape
} else throw e;
} Prevention
- Standardize dataset items on the `input` key in a shared type/zod schema
- Validate the whole dataset with a schema before calling runEvals
- When migrating formats, normalize records to the current shape instead of mixing keys
When it happens
Trigger: Calling runEvals with items like `null`, strings/numbers, `{}` (missing keys), or objects using the wrong key such as `{ prompt: ... }` or `{ messages: ... }` — thrown at the first offending index `i`.
Common situations: Hand-written datasets with inconsistent key names; migrating from an older eval format (`inputs` -> `input` or the new `turns` for multi-turn); mapping over an array that produced `undefined` entries; JSON parse producing scalars for some lines of a JSONL file.
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
- ${label} contains an unsupported field.
- Invalid state update: ${messages}
- SchemaValidationError(field, this.formatErrors(result.error)
- RUN_EXPERIMENT_FAILED_NO_DATA_PROVIDED
- NO_SCORERS_PROVIDED
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/16743bb41c55f496.
Report an issue: GitHub.