{"record":{"id":"4df4ebab9fce6281","repo":"microsoft/semantic-kernel","slug":"imagecontent-without-data-uri-in-user-message-whil-4df4eb","errorCode":null,"errorMessage":"ImageContent without data_uri in User message while formatting chat history for Google AI","messagePattern":"ImageContent without data_uri in User message while formatting chat history for Google AI","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/vertex_ai/services/utils.py","lineNumber":189,"sourceCode":"            ),\n        )\n        settings.tools = [\n            Tool(\n                function_declarations=[\n                    kernel_function_metadata_to_vertex_ai_function_call_format(f)\n                    for f in function_choice_configuration.available_functions\n                ]\n            )\n        ]\n\n\ndef _create_image_part(image_content: ImageContent) -> Part:\n    if image_content.data_uri:\n        return Part.from_data(image_content.data, image_content.mime_type)  # type: ignore[arg-type]\n\n    # The Google AI API doesn't support images from arbitrary URIs:\n    # https://github.com/google-gemini/generative-ai-python/issues/357\n    raise ServiceInvalidRequestError(\n        \"ImageContent without data_uri in User message while formatting chat history for Google AI\"\n    )\n","sourceCodeStart":171,"sourceCodeEnd":192,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/vertex_ai/services/utils.py#L171-L192","documentation":"Raised by _create_image_part() when an ImageContent has no data_uri. The Google AI/Vertex AI generative API cannot fetch images from arbitrary URLs (see the linked upstream issue), so Semantic Kernel requires an inline base64 data_uri to build the Part via Part.from_data. A bare URL or empty image content is rejected before the request is built.","triggerScenarios":"Constructing ImageContent with only a uri pointing at a public/remote URL (or no data at all) and passing it in a Vertex AI chat request. Loading image references from a database or CDN URL instead of embedding the bytes.","commonSituations":"Assuming Vertex AI accepts HTTPS image URLs like OpenAI vision endpoints do. Forgetting to base64-encode a local file. Passing an ImageContent built for another provider whose uri field is populated but data_uri is not.","solutions":["Build ImageContent with an inline data_uri: encode the image bytes as a base64 data URI (data:<mime>;base64,...) and pass it so data_uri is truthy.","Load the remote image bytes yourself, then construct ImageContent(data_uri='data:image/png;base64,...', data=bytes, mime_type='image/png').","Avoid setting only the uri field; populate data_uri with the embedded base64 payload.","Validate image_content.data_uri is non-empty before adding the item to the user message."],"exampleFix":"// before\nImageContent(uri='https://cdn/img.png')\n# after\nimport base64\nb = base64.b64encode(raw_bytes).decode()\nImageContent(data_uri=f'data:image/png;base64,{b}', data=raw_bytes, mime_type='image/png')","handlingStrategy":"validation","validationCode":"for item in user_msg.items:\n    if isinstance(item, ImageContent):\n        assert item.data_uri, 'ImageContent needs an inline base64 data_uri for Vertex AI'","typeGuard":"def has_inline_data(image_content) -> bool:\n    return bool(getattr(image_content, 'data_uri', None))","tryCatchPattern":null,"preventionTips":["Always embed image bytes as a base64 data URI for Vertex AI requests.","Fetch remote image bytes yourself and encode them before building ImageContent.","Never rely on a bare public URL for Vertex AI vision input."],"tags":["vertex-ai","image-content","vision","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}