{"record":{"id":"09068b9be6a03a19","repo":"mastra-ai/mastra","slug":"ui-messages-require-a-data-property-when-using-dat-09068b","errorCode":null,"errorMessage":"UI Messages require a data property when using data- prefixed chunks \n ${JSON.stringify(payload)}","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":1199,"sourceCode":"        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\n        return {\n          type,\n          data,\n          ...(id !== undefined && { id }),\n        };\n      }\n      return null;\n    }\n  }\n}\n\ntype TransformNetworkResult = InferUIMessageChunk<UIMessage> | NetworkDataPart | DataChunkType | WorkflowStepDataPart;\n","sourceCodeStart":1181,"sourceCodeEnd":1217,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/ai-sdk/src/transformers.ts#L1181-L1217","documentation":"Same family as the other data-chunk errors: in the default branch of the stream transformer, an unknown chunk that is recognized as a data- prefixed type must contain a 'data' property to be convertible to a UI message part. This variant runs on the plain payload path of transformers.ts.","triggerScenarios":"Writing a custom data chunk ({ type: 'data-x', ... }) through the agent stream-to-UIMessage transformer without a data property; the chunk passes isDataChunkType but lacks 'data'.","commonSituations":"Server-side tool output objects accidentally forwarded as chunks without wrapping; conditionally-built chunk objects where data is left out on some branches; refactors renaming the payload key.","solutions":["Ensure every data- chunk includes data: { type: 'data-x', data: {...} }.","Validate chunk shape before writing to the stream (typeof chunk.data !== 'undefined').","If the chunk is meant to be opaque, prefix the type differently so it is not treated as a data chunk.","Inspect the JSON in the error message to identify which emitter produced it."],"exampleFix":"// before\nreturn { type: 'data-notification' };\n// after\nreturn { type: 'data-notification', data: { message: 'Done' } };","handlingStrategy":"type-guard","validationCode":"if (isDataChunkType(payload) && !('data' in payload)) {\n  throw new Error(`data chunk ${payload.type} missing data`);\n}","typeGuard":"function isCompleteDataChunk(p: unknown): p is { type: string; data: unknown; id?: string } {\n  return typeof p === 'object' && p !== null && 'type' in p && String((p as any).type).startsWith('data-') && 'data' in p;\n}","tryCatchPattern":"try {\n  return transformChunk(payload);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('require a data property')) {\n    return null; // skip malformed chunk\n  }\n  throw e;\n}","preventionTips":["Validate chunk shape before writing to any stream.","Use a discriminated union type for all chunk kinds.","Don't rename the payload key away from 'data'."],"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"}