{"record":{"id":"9c72ff8973336364","repo":"microsoft/semantic-kernel","slug":"failed-to-create-mistralai-settings","errorCode":null,"errorMessage":"Failed to create MistralAI settings.","messagePattern":"Failed to create MistralAI settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_chat_completion.py","lineNumber":94,"sourceCode":"            ai_model_id : MistralAI model name, see\n                https://docs.mistral.ai/getting-started/models/\n            service_id : Service ID tied to the execution settings.\n            api_key : The optional API key to use. If provided will override,\n                the env vars or .env file value.\n            async_client : An existing client to use.\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        \"\"\"\n        try:\n            mistralai_settings = MistralAISettings(\n                api_key=api_key,\n                chat_model_id=ai_model_id,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise ServiceInitializationError(\"Failed to create MistralAI settings.\", ex) from ex\n\n        if not mistralai_settings.chat_model_id:\n            raise ServiceInitializationError(\"The MistralAI chat model ID is required.\")\n\n        if not async_client:\n            async_client = Mistral(\n                api_key=mistralai_settings.api_key.get_secret_value(),\n            )\n\n        super().__init__(\n            async_client=async_client,\n            service_id=service_id or mistralai_settings.chat_model_id,\n            ai_model_id=ai_model_id or mistralai_settings.chat_model_id,\n        )\n\n    # region Overriding base class methods\n\n    # Override from AIServiceClientBase","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_chat_completion.py#L76-L112","documentation":"Raised by MistralAIChatCompletion.__init__ when constructing MistralAISettings raises a pydantic ValidationError. The constructor wraps the validation failure (api_key, chat_model_id, env) into a ServiceInitializationError chained from the cause, failing fast at service creation.","triggerScenarios":"Instantiating MistralAIChatCompletion with missing/malformed api_key or model id and no env fallback. A .env file that doesn't satisfy MistralAISettings validators.","commonSituations":"MISTRAL_API_KEY not set. Wrong env file path/encoding. Empty/malformed api_key or model id passed explicitly.","solutions":["Inspect the chained cause (ValidationError detail) to find the failing field.","Set MISTRAL_API_KEY (and model id) via env / .env, or pass api_key and ai_model_id explicitly.","Verify env_file_path is correct and readable."],"exampleFix":"# before\nsvc = MistralAIChatCompletion()\n# after\nsvc = MistralAIChatCompletion(ai_model_id='mistral-large-latest', api_key=os.environ['MISTRAL_API_KEY'])","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.mistral_ai.mistral_ai_settings import MistralAISettings\ntry:\n    s = MistralAISettings(api_key=..., chat_model_id=...)\nexcept Exception as e:\n    print('config invalid:', e)","typeGuard":null,"tryCatchPattern":"try:\n    svc = MistralAIChatCompletion(api_key=..., ai_model_id=...)\nexcept ServiceInitializationError as e:\n    raise","preventionTips":["Set MISTRAL_API_KEY and a model id via env / .env or pass explicitly.","Validate MistralAISettings construction in isolation.","Confirm env_file_path correctness."],"tags":["mistral-ai","configuration","settings","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}