{"record":{"id":"b3f33f3fce416d92","repo":"microsoft/semantic-kernel","slug":"image-content-uri-needs-to-be-set-because-onnx-ca","errorCode":null,"errorMessage":"Image Content URI needs to be set, because onnx can only work with file paths","messagePattern":"Image Content URI needs to be set, because onnx can only work with file paths","errorType":"exception","errorClass":"ServiceInvalidExecutionSettingsError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py","lineNumber":195,"sourceCode":"\n    def _chat_messages_to_dicts(self, chat_history: \"ChatHistory\") -> list[dict[str, Any]]:\n        return [\n            message.to_dict(role_key=\"role\", content_key=\"content\")\n            for message in chat_history.messages\n            if isinstance(message, ChatMessageContent)\n        ]\n\n    def _get_images_from_history(self, chat_history: \"ChatHistory\") -> list[ImageContent] | None:\n        images = []\n        for message in chat_history.messages:\n            for image in message.items:\n                if isinstance(image, ImageContent):\n                    if not self.enable_multi_modality:\n                        raise ServiceInvalidExecutionSettingsError(\"The model does not support multi-modality\")\n                    if image.uri:\n                        images.append(image)\n                    else:\n                        raise ServiceInvalidExecutionSettingsError(\n                            \"Image Content URI needs to be set, because onnx can only work with file paths\"\n                        )\n        return images if len(images) else None\n\n    def _get_audios_from_history(self, chat_history: \"ChatHistory\") -> list[AudioContent] | None:\n        audios = []\n        for message in chat_history.messages:\n            for audio in message.items:\n                if isinstance(audio, AudioContent):\n                    if not self.enable_multi_modality:\n                        raise ServiceInvalidExecutionSettingsError(\"The model does not support multi-modality\")\n                    if audio.uri:\n                        audios.append(audio)\n                    else:\n                        raise ServiceInvalidExecutionSettingsError(\n                            \"Audio Content URI needs to be set, because onnx can only work with file paths\"\n                        )\n        return audios if len(audios) else None","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py#L177-L213","documentation":"Raised inside _get_images_from_history when the model IS multi-modal (enable_multi_modality is True) but an ImageContent item has a falsy .uri attribute. The ONNX runtime's Pybind layer can only load images from file paths (OnnxRuntimeGenAi.Images.open), not from base64 data or byte buffers. Raised as ServiceInvalidExecutionSettingsError.","triggerScenarios":"Adding ImageContent(data='base64...') to chat history for a vision ONNX model without setting the uri. The formatter checks image.uri and rejects None/empty.","commonSituations":"Creating ImageContent with only base64 data (as required by Ollama) and reusing it with ONNX; loading images from a URL or byte stream without writing to a temp file; ONNX's limitation of file-path-only image loading not accounted for.","solutions":["Set image.uri to a local file path when using ONNX vision models","If you have base64 or bytes, write to a temp file and set uri to that path","Use ImageContent(uri='file:///path/to/image.png') instead of data-only construction"],"exampleFix":"// before\nImageContent(data=base64_encoded_string)\n// after\nImageContent(uri='file:///tmp/image.png')","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents import ImageContent\n\ndef validate_image_uris(chat_history):\n    for msg in chat_history.messages:\n        for item in msg.items:\n            if isinstance(item, ImageContent) and not item.uri:\n                raise ValueError('ImageContent must have a uri for ONNX models')","typeGuard":"from semantic_kernel.contents import ImageContent\n\ndef all_images_have_uri(chat_history) -> bool:\n    return all(\n        item.uri for msg in chat_history.messages\n        for item in msg.items if isinstance(item, ImageContent)\n    )","tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInvalidExecutionSettingsError\n\ntry:\n    result = await chat.get_chat_message_contents(chat_history=history, settings=settings)\nexcept ServiceInvalidExecutionSettingsError as e:\n    if 'Image Content URI needs to be set' in str(e):\n        for msg in history.messages:\n            for item in msg.items:\n                if isinstance(item, ImageContent) and not item.uri:\n                    item.uri = 'file:///tmp/resolved_image.png'\n        result = await chat.get_chat_message_contents(chat_history=history, settings=settings)","preventionTips":["Always set ImageContent.uri to a local file path for ONNX vision models","Write base64 image data to a temp file and use its path if only data is available","Pre-validate all image URIs exist on disk before calling the service"],"tags":["onnx","multimodal","image-content","uri","execution-settings"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}