microsoft/semantic-kernel · error · ServiceInvalidExecutionSettingsError
Image Content URI needs to be set, because onnx can only wor
Error message
Image Content URI needs to be set, because onnx can only work with file paths
What it means
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.
Source
Thrown at python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py:195
def _chat_messages_to_dicts(self, chat_history: "ChatHistory") -> list[dict[str, Any]]:
return [
message.to_dict(role_key="role", content_key="content")
for message in chat_history.messages
if isinstance(message, ChatMessageContent)
]
def _get_images_from_history(self, chat_history: "ChatHistory") -> list[ImageContent] | None:
images = []
for message in chat_history.messages:
for image in message.items:
if isinstance(image, ImageContent):
if not self.enable_multi_modality:
raise ServiceInvalidExecutionSettingsError("The model does not support multi-modality")
if image.uri:
images.append(image)
else:
raise ServiceInvalidExecutionSettingsError(
"Image Content URI needs to be set, because onnx can only work with file paths"
)
return images if len(images) else None
def _get_audios_from_history(self, chat_history: "ChatHistory") -> list[AudioContent] | None:
audios = []
for message in chat_history.messages:
for audio in message.items:
if isinstance(audio, AudioContent):
if not self.enable_multi_modality:
raise ServiceInvalidExecutionSettingsError("The model does not support multi-modality")
if audio.uri:
audios.append(audio)
else:
raise ServiceInvalidExecutionSettingsError(
"Audio Content URI needs to be set, because onnx can only work with file paths"
)
return audios if len(audios) else NoneView on GitHub (pinned to c028a0c7dc)
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
Example fix
// before ImageContent(data=base64_encoded_string) // after ImageContent(uri='file:///tmp/image.png')
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.contents import ImageContent
def validate_image_uris(chat_history):
for msg in chat_history.messages:
for item in msg.items:
if isinstance(item, ImageContent) and not item.uri:
raise ValueError('ImageContent must have a uri for ONNX models') Type guard
from semantic_kernel.contents import ImageContent
def all_images_have_uri(chat_history) -> bool:
return all(
item.uri for msg in chat_history.messages
for item in msg.items if isinstance(item, ImageContent)
) Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceInvalidExecutionSettingsError
try:
result = await chat.get_chat_message_contents(chat_history=history, settings=settings)
except ServiceInvalidExecutionSettingsError as e:
if 'Image Content URI needs to be set' in str(e):
for msg in history.messages:
for item in msg.items:
if isinstance(item, ImageContent) and not item.uri:
item.uri = 'file:///tmp/resolved_image.png'
result = await chat.get_chat_message_contents(chat_history=history, settings=settings) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The model does not support multi-modality
- Audio Content URI needs to be set, because onnx can only wor
- ImageContent in function result must contain binary data.
- When using a multi-modal model, a template must be specified
- ImageContent cannot be converted to ResponseContentPart. Onl
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/b3f33f3fce416d92.
Report an issue: GitHub.