microsoft/semantic-kernel · error · ServiceInvalidExecutionSettingsError

Audio Content URI needs to be set, because onnx can only wor

Error message

Audio Content URI needs to be set, because onnx can only work with file paths

What it means

Raised inside _get_audios_from_history when the model IS multi-modal but an AudioContent item has a falsy .uri attribute. Like images, the ONNX runtime can only load audio from file paths (OnnxRuntimeGenAi.Audios.open), not from in-memory data. Raised as ServiceInvalidExecutionSettingsError.

Source

Thrown at python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py:210

                    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 None

    @override
    def get_prompt_execution_settings_class(self) -> type["PromptExecutionSettings"]:
        """Create a request settings object."""
        return OnnxGenAIPromptExecutionSettings

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set audio.uri to a local file path for ONNX models
  2. Write in-memory audio to a temp file and reference its path via uri
  3. Use AudioContent(uri='file:///tmp/audio.wav')

Example fix

// before
AudioContent(data=audio_bytes)
// after
AudioContent(uri='file:///tmp/audio.wav')
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.contents import AudioContent

def validate_audio_uris(chat_history):
    for msg in chat_history.messages:
        for item in msg.items:
            if isinstance(item, AudioContent) and not item.uri:
                raise ValueError('AudioContent must have a uri for ONNX models')

Type guard

from semantic_kernel.contents import AudioContent

def all_audios_have_uri(chat_history) -> bool:
    return all(
        item.uri for msg in chat_history.messages
        for item in msg.items if isinstance(item, AudioContent)
    )

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 'Audio Content URI needs to be set' in str(e):
        for msg in history.messages:
            for item in msg.items:
                if isinstance(item, AudioContent) and not item.uri:
                    item.uri = 'file:///tmp/resolved_audio.wav'
        result = await chat.get_chat_message_contents(chat_history=history, settings=settings)

Prevention

When it happens

Trigger: Adding AudioContent with data but no uri to chat history for a multi-modal ONNX model. The check fires on audio.uri being falsy.

Common situations: Creating AudioContent from a byte buffer or base64 without writing to disk; reusing audio objects from another connector that uses data instead of uri; ONNX file-path-only limitation not accounted for.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/6933190b6e1ad6d6. Report an issue: GitHub.