{"record":{"id":"3aeb315c29d97919","repo":"mastra-ai/mastra","slug":"ui-messages-require-a-data-property-when-using-dat","errorCode":null,"errorMessage":"UI Messages require a data property when using data- prefixed chunks \n ${JSON.stringify(part)}","messagePattern":"UI Messages require a data property when using data- prefixed chunks \n (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client-sdks/ai-sdk/src/helpers.ts","lineNumber":774,"sourceCode":"          type: 'tool-agent',\n          toolCallId: part.toolCallId,\n          payload: part.output,\n        };\n      } else if (part.output.from === 'WORKFLOW') {\n        return {\n          type: 'tool-workflow',\n          toolCallId: part.toolCallId,\n          payload: part.output,\n        };\n      } else if (part.output.from === 'NETWORK') {\n        return {\n          type: 'tool-network',\n          toolCallId: part.toolCallId,\n          payload: part.output,\n        };\n      } else if (isDataChunkType(part.output)) {\n        if (!('data' in part.output)) {\n          throw new Error(\n            `UI Messages require a data property when using data- prefixed chunks \\n ${JSON.stringify(part)}`,\n          );\n        }\n        const { type, data, id } = part.output;\n        return { type, data, ...(id !== undefined && { id }) } as InferUIMessageChunk<UI_MESSAGE>;\n      }\n      return;\n    }\n\n    case 'tool-error': {\n      return {\n        type: 'tool-output-error',\n        toolCallId: part.toolCallId,\n        errorText: onError(part.error),\n        ...(part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {}),\n        ...(part.dynamic != null ? { dynamic: part.dynamic } : {}),\n      };\n    }","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/ai-sdk/src/helpers.ts#L756-L792","documentation":"When converting a full stream to a UI message stream, a data-prefixed chunk's output (part.output) is recognized as a data chunk but lacks a `data` property. The AI SDK UI message format requires every data- chunk to carry its payload under `data`, so the converter throws with the offending part serialized.","triggerScenarios":"A tool-network or custom data chunk whose `output` object matches isDataChunkType (type starts with 'data-') but has fields like {type:'data-foo', value:...} instead of {type:'data-foo', data:...}.","commonSituations":"Custom tool writers emitting tool-network chunks with ad-hoc payload shapes, migration from older Mastra/AI SDK chunk formats where the payload lived under a different key, or typos like 'dat' or 'payload'.","solutions":["Rename the payload key on the chunk output to `data`","Ensure custom data chunks are shaped {type:'data-xxx', data:<payload>} (optional id allowed)","If using tool-network chunks, put the payload in part.output.data rather than a custom field","Check the AI SDK version's UIMessageChunk contract for data- chunks"],"exampleFix":"// before\nyield { type: 'data-weather', forecast: forecastData }\n// after\nyield { type: 'data-weather', data: forecastData }","handlingStrategy":"validation","validationCode":"function assertDataChunk(out: { type: string } & Record<string, unknown>) {\n  if (out.type?.startsWith('data-') && !('data' in out)) {\n    throw new Error(`data- chunk ${out.type} missing required \"data\" property`);\n  }\n}","typeGuard":"function hasDataProp<T extends { type: string }>(c: T): c is T & { data: unknown } {\n  return 'data' in c;\n}","tryCatchPattern":"try {\n  for await (const chunk of result.toUIMessageStream()) {\n    ui.messages.push(chunk);\n  }\n} catch (e) {\n  if (String(e.message).startsWith('UI Messages require a data property')) {\n    console.error('Malformed data chunk from server:', e.message);\n  }\n}","preventionTips":["Always shape custom data chunks as {type:'data-x', data, id?}","Use helper factories to create data chunks instead of raw literals","Add a unit test that streams your custom data chunks through toUIMessageStream"],"tags":["streaming","ai-sdk","data-chunks","validation"],"backgroundTag":"missing-data-property-on-data-chunk","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}