microsoft/semantic-kernel · error · ServiceInitializationError

Invalid settings for OnnxGenAITextCompletion: {e}

Error message

Invalid settings for OnnxGenAITextCompletion: {e}

What it means

Raised by the OnnxGenAITextCompletion constructor when OnnxGenAISettings(...) raises a Pydantic ValidationError during settings construction. The original error is embedded in the message via f-string. Note this error does NOT chain the exception ('from e' is absent), so the traceback context may be less detailed than the chat-completion equivalent (error 1128).

Source

Thrown at python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_text_completion.py:55

        env_file_encoding: str | None = None,
    ) -> None:
        """Initializes a new instance of the OnnxGenAITextCompletion class.

        Args:
            ai_model_path : Local path to the ONNX model Folder.
            ai_model_id : The ID of the AI model. Defaults to None.
            env_file_path : Use the environment settings file as a fallback
                to environment variables.
            env_file_encoding : The encoding of the environment settings file.
        """
        try:
            settings = OnnxGenAISettings(
                text_model_folder=ai_model_path,
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
            )
        except ValidationError as e:
            raise ServiceInitializationError(f"Invalid settings for OnnxGenAITextCompletion: {e}")

        if settings.text_model_folder is None:
            raise ServiceInitializationError(
                "AI model path is not provided. Please provide the 'ai_model_path' parameter in the constructor. "
                "OR set the 'ONNX_GEN_AI_TEXT_MODEL_FOLDER' environment variable."
            )

        if ai_model_id is None:
            ai_model_id = settings.text_model_folder

        super().__init__(
            ai_model_id=ai_model_id,
            ai_model_path=settings.text_model_folder,
        )

    @override
    async def _inner_get_text_contents(
        self,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Read the full message which embeds the ValidationError string
  2. Fix the offending .env entry or environment variable
  3. Verify env_file_path and env_file_encoding are correct
Defensive patterns

Strategy: validation

Validate before calling

from pydantic import ValidationError
from semantic_kernel.connectors.ai.onnx.onnx_gen_ai_settings import OnnxGenAISettings

try:
    test = OnnxGenAISettings(text_model_folder='/path/to/model')
except ValidationError as e:
    print(f'OnnxGenAI text settings invalid: {e}')
    raise

text = OnnxGenAITextCompletion(ai_model_path='/path/to/model')

Try / catch

from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError

try:
    text = OnnxGenAITextCompletion()
except ServiceInitializationError as e:
    logger.error('OnnxGenAI text settings error: %s', e)
    raise

Prevention

When it happens

Trigger: Constructing OnnxGenAITextCompletion with settings that fail Pydantic validation — corrupt .env file, unexpected types for ONNX_GEN_AI_TEXT_MODEL_FOLDER, or env_file_encoding mismatch.

Common situations: Malformed .env file entries; env_file_path pointing at a non-existent file; environment variable with encoding issues; running in a container where env vars are set to non-string types.

Related errors


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