{"record":{"id":"885359ca5be0a468","repo":"mastra-ai/mastra","slug":"ui-messages-require-a-data-property-when-using-dat-885359","errorCode":null,"errorMessage":"UI Messages require a data property when using data- prefixed chunks \n ${JSON.stringify(output)}","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/transformers.ts","lineNumber":1186,"sourceCode":"            )\n            .filter(Boolean);\n        }\n\n        const transformedChunk = convertFullStreamChunkToUIMessageStream({\n          part: part as any,\n          sendReasoning: streamOptions?.sendReasoning,\n          sendSources: streamOptions?.sendSources,\n          onError(error) {\n            return safeParseErrorObject(error);\n          },\n        });\n\n        return transformedChunk;\n      }\n\n      if (output && isDataChunkType(output)) {\n        if (!('data' in output)) {\n          throw new Error(\n            `UI Messages require a data property when using data- prefixed chunks \\n ${JSON.stringify(output)}`,\n          );\n        }\n        const { type, data, id } = output;\n        return { type, data, ...(id !== undefined && { id }) };\n      }\n      return null;\n    }\n    default: {\n      // return the chunk as is if it's not a known type\n      if (isDataChunkType(payload)) {\n        if (!('data' in payload)) {\n          throw new Error(\n            `UI Messages require a data property when using data- prefixed chunks \\n ${JSON.stringify(payload)}`,\n          );\n        }\n        const { type, data, id } = payload;\n","sourceCodeStart":1168,"sourceCodeEnd":1204,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/ai-sdk/src/transformers.ts#L1168-L1204","documentation":"The AI SDK stream transformer converts custom 'data-' prefixed chunks into UI message parts. A data- chunk must carry a 'data' property holding its payload; this library throws when a data- typed chunk arrives without one, since it cannot build a valid UI data part from it.","triggerScenarios":"Emitting a chunk like { type: 'data-myThing' } (or calling writer.write with such an object) from a tool/agent without including { data: ... } in the chunk, in the agent stream transformer path (transformers.ts:1186).","commonSituations":"Custom data chunk creation where 'data' is omitted because it's undefined/null at runtime; mistyping the payload field name (e.g. 'payload' instead of 'data'); spreading an object that drops the data key when empty.","solutions":["Always include a data property on data- prefixed chunks: { type: 'data-foo', data: {...} }.","Guard the payload before writing: skip or default the chunk if data is undefined.","Check the field name — the payload must be under 'data', not 'payload' or 'value'.","Log the offending chunk (included in the error JSON) to find the emitter."],"exampleFix":"// before\nwriter.write({ type: 'data-weather', id: 'w1' }); // missing data\n// after\nwriter.write({ type: 'data-weather', id: 'w1', data: { forecast: 'sunny' } });","handlingStrategy":"type-guard","validationCode":"if (chunk.type.startsWith('data-') && !('data' in chunk)) {\n  throw new Error(`data chunk ${chunk.type} missing data property`);\n}","typeGuard":"function hasDataProp(c: { type: string }): c is { type: string; data: unknown } {\n  return 'data' in c && c.data !== undefined;\n}","tryCatchPattern":"try {\n  writer.write(chunk);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('require a data property')) {\n    console.error('Bad chunk:', e.message);\n  } else throw e;\n}","preventionTips":["Type custom data chunks as { type: `data-${string}`; data: unknown }.","Never emit data- chunks conditionally without their data field.","Centralize chunk creation in helper functions that enforce the shape."],"tags":["streaming","data-chunks","ui-messages","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"}