{"record":{"id":"7a4b0f2d4f50a563","repo":"microsoft/semantic-kernel","slug":"error-creating-onnxgenaisettings-e","errorCode":null,"errorMessage":"Error creating OnnxGenAISettings: {e}","messagePattern":"Error creating OnnxGenAISettings: (.+?)","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py","lineNumber":71,"sourceCode":"        \"\"\"Initializes a new instance of the OnnxGenAITextCompletion class.\n\n        Args:\n            template : The chat template configuration.\n            ai_model_path : Local path to the ONNX model Folder.\n            ai_model_id : The ID of the AI model. Defaults to None.\n            env_file_path : Use the environment settings file as a fallback\n                to environment variables.\n            env_file_encoding : The encoding of the environment settings file.\n            kwargs : Additional arguments.\n        \"\"\"\n        try:\n            settings = OnnxGenAISettings(\n                chat_model_folder=ai_model_path,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as e:\n            raise ServiceInitializationError(f\"Error creating OnnxGenAISettings: {e}\") from e\n\n        if settings.chat_model_folder is None:\n            raise ServiceInitializationError(\n                \"AI model path is not provided. Please provide the 'ai_model_path' parameter in the constructor. \"\n                \"OR set the 'ONNX_GEN_AI_CHAT_MODEL_FOLDER' environment variable.\"\n            )\n\n        if ai_model_id is None:\n            ai_model_id = settings.chat_model_folder\n\n        super().__init__(ai_model_id=ai_model_id, ai_model_path=settings.chat_model_folder, template=template, **kwargs)\n\n        if self.enable_multi_modality and template is None:\n            raise ServiceInitializationError(\n                \"When using a multi-modal model, a template must be specified.\"\n                \" Please provide a ONNXTemplate in the constructor.\"\n            )\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_chat_completion.py#L53-L89","documentation":"Raised by the OnnxGenAIChatCompletion constructor when OnnxGenAISettings(...) raises a Pydantic ValidationError during settings construction. The original error is included via an f-string in the message. This indicates a structural settings problem (wrong type for env values, etc.) rather than a missing value.","triggerScenarios":"Constructing OnnxGenAIChatCompletion with settings that fail Pydantic validation — e.g. ONNX_GEN_AI_CHAT_MODEL_FOLDER set to a non-string type in the environment, or a corrupt .env file pointed to by env_file_path.","commonSituations":"Environment variable with unexpected encoding; env_file_path pointing at an unreadable file; .env file with malformed key=value pairs that Pydantic rejects.","solutions":["Read the full error message which embeds the Pydantic ValidationError details","Fix the offending environment variable or .env entry","Verify env_file_path is valid and the encoding matches env_file_encoding"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from pydantic import ValidationError\nfrom semantic_kernel.connectors.ai.onnx.onnx_gen_ai_settings import OnnxGenAISettings\n\ntry:\n    test_settings = OnnxGenAISettings(chat_model_folder='/path/to/model')\nexcept ValidationError as e:\n    print(f'Configuration is invalid: {e}')\n    raise\n\nchat = OnnxGenAIChatCompletion(ai_model_path='/path/to/model')","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    chat = OnnxGenAIChatCompletion()\nexcept ServiceInitializationError as e:\n    logger.error('OnnxGenAI chat settings error: %s', e)\n    raise","preventionTips":["Pre-validate settings by constructing OnnxGenAISettings before the service","Ensure .env file entries are well-formed key=value pairs","Test env file readability and encoding at startup"],"tags":["onnx","configuration","settings-validation","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}