{"record":{"id":"f549a3b2362acb4f","repo":"FlowiseAI/Flowise","slug":"invalid-media-content","errorCode":null,"errorMessage":"Invalid media content","messagePattern":"Invalid media content","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts","lineNumber":99,"sourceCode":"\nfunction messageContentMedia(content: MessageContentComplex): Part {\n    if ('mimeType' in content && 'data' in content) {\n        return {\n            inlineData: {\n                mimeType: content.mimeType as string,\n                data: content.data as string\n            }\n        }\n    }\n    if ('mimeType' in content && 'fileUri' in content) {\n        return {\n            fileData: {\n                mimeType: content.mimeType as string,\n                fileUri: content.fileUri as string\n            }\n        }\n    }\n    throw new Error('Invalid media content')\n}\n\nfunction inferToolNameFromPreviousMessages(message: any, previousMessages: BaseMessage[]): string | undefined {\n    return previousMessages\n        .map((msg) => {\n            if (AIMessage.isInstance(msg)) {\n                return msg.tool_calls ?? []\n            }\n            return []\n        })\n        .flat()\n        .find((toolCall) => {\n            return toolCall.id === message.tool_call_id\n        })?.name\n}\n\nfunction _getStandardContentBlockConverter(isMultimodalModel: boolean) {\n    const standardContentBlockConverter: StandardContentBlockConverter<{","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts#L81-L117","documentation":"Thrown by messageContentMedia() (line 99) when a content block of type 'media' matches neither the inline-data shape ({mimeType, data}) nor the file-data shape ({mimeType, fileUri}). This is Flowise's fallback media-to-Gemini-Part mapper used when content.type === 'media'. Any media block missing the required keys is rejected rather than silently dropped.","triggerScenarios":"A MessageContentComplex block with type 'media' is passed that lacks both the mimeType+data pair and the mimeType+fileUri pair.","commonSituations":"An upstream node emits a partial media object (e.g., only a url without mimeType), a custom tool returns malformed media content, or a content schema changed between library versions.","solutions":["Ensure each media content block contains either { type:'media', mimeType, data } (inline base64) or { type:'media', mimeType, fileUri } (remote file).","If you only have a URL, use the image_url content type instead so it is routed through the URL parser.","Validate the media block shape in the producing node/tool before sending it to the Gemini node."],"exampleFix":"// before (throws): { type: 'media', url: 'https://example.com/img.png' }\n// after:           { type: 'media', mimeType: 'image/png', fileUri: 'https://example.com/img.png' }","handlingStrategy":"validation","validationCode":"function isValidMedia(c: Record<string, unknown>): boolean {\n  const hasInline = typeof c.mimeType === 'string' && typeof c.data === 'string'\n  const hasFile = typeof c.mimeType === 'string' && typeof c.fileUri === 'string'\n  return hasInline || hasFile\n}\nfor (const part of contentParts) {\n  if (part?.type === 'media' && !isValidMedia(part)) {\n    throw new Error('media block must contain {mimeType,data} or {mimeType,fileUri}')\n  }\n}","typeGuard":"type MediaPart =\n  | { type: 'media'; mimeType: string; data: string }\n  | { type: 'media'; mimeType: string; fileUri: string }\nfunction isMediaPart(c: unknown): c is MediaPart {\n  if (typeof c !== 'object' || c === null || (c as any).type !== 'media') return false\n  const o = c as Record<string, unknown>\n  return (typeof o.mimeType === 'string' && typeof o.data === 'string')\n      || (typeof o.mimeType === 'string' && typeof o.fileUri === 'string')\n}","tryCatchPattern":"try {\n  return convertMessageContentToParts(message, isMultimodal, prev)\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid media content') {\n    // log the offending media block and skip or repair it\n  }\n  throw e\n}","preventionTips":["Normalize media blocks at the producer: always include mimeType plus either data or fileUri.","For URL-only sources, use the image_url content type instead of media.","Add a content-schema validator unit test for custom tool outputs."],"tags":["gemini","multimodal","content-blocks","validation"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}