{"record":{"id":"c8be3f41d92db638","repo":"microsoft/semantic-kernel","slug":"failed-to-validate-mistral-ai-settings-e","errorCode":null,"errorMessage":"Failed to validate Mistral AI settings: {e}","messagePattern":"Failed to validate Mistral AI settings: (.+?)","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_text_embedding.py","lineNumber":66,"sourceCode":"            ai_model_id: : A string that is used to identify the model such as the model name.\n            api_key : The API key for the Mistral AI service deployment.\n            service_id : Service ID for the embedding completion service.\n            async_client : The Mistral AI client to use.\n            env_file_path : The path to the environment file.\n            env_file_encoding : The encoding of the environment file.\n\n        Raises:\n            ServiceInitializationError: If an error occurs during initialization.\n        \"\"\"\n        try:\n            mistralai_settings = MistralAISettings(\n                api_key=api_key,\n                embedding_model_id=ai_model_id,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as e:\n            raise ServiceInitializationError(f\"Failed to validate Mistral AI settings: {e}\") from e\n\n        if not mistralai_settings.embedding_model_id:\n            raise ServiceInitializationError(\"The MistralAI embedding 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        super().__init__(\n            service_id=service_id or mistralai_settings.embedding_model_id,\n            ai_model_id=ai_model_id or mistralai_settings.embedding_model_id,\n            async_client=async_client,\n        )\n\n    @override\n    async def generate_embeddings(\n        self,\n        texts: list[str],","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/mistral_ai/services/mistral_ai_text_embedding.py#L48-L84","documentation":"Raised as ServiceInitializationError at construction of MistralAITextEmbedding when instantiating the pydantic `MistralAISettings` raises a `ValidationError`. This happens BEFORE any network call: it means the supplied/loaded configuration is structurally invalid (e.g. api_key present but wrong type, env file unreadable, a field failing its validator). The full pydantic error list is interpolated into the message.","triggerScenarios":"Constructing `MistralAITextEmbedding(...)` where the merged config (constructor args + MISTRALAI_API_KEY/MISTRALAI_EMBEDDING_MODEL_ID env vars + .env file) fails pydantic validation: api_key is None where a SecretStr is required, a field fails format validation, or env_file_path points to a missing/unparseable file.","commonSituations":"Missing .env file pointed to by env_file_path, typo'd env var names, MISTRALAI_API_KEY set to an empty string, or a pydantic v1/v2 mismatch changing validator behavior.","solutions":["Read the interpolated `{e}`: pydantic lists each failing field and why - fix that field first.","Set MISTRALAI_API_KEY (and MISTRALAI_EMBEDDING_MODEL_ID) in the environment or a .env file at the project root.","Pass `api_key=` explicitly to the constructor to bypass env resolution.","Confirm the .env path in `env_file_path=` exists and uses the configured `env_file_encoding` (default utf-8)."],"exampleFix":"# before\nsvc = MistralAITextEmbedding()  # ValidationError -> ServiceInitializationError\n\n# after\nsvc = MistralAITextEmbedding(\n    api_key=os.environ['MISTRALAI_API_KEY'],\n    ai_model_id='mistral-embed',\n)","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.mistral_ai import MistralAISettings\nfrom pydantic import ValidationError\ntry:\n    s = MistralAISettings(api_key=os.environ.get('MISTRALAI_API_KEY'),\n                          embedding_model_id=os.environ.get('MISTRALAI_EMBEDDING_MODEL_ID'))\n    assert s.api_key and s.embedding_model_id\nexcept ValidationError as e:\n    raise SystemExit(f'Fix Mistral settings first: {e}')","typeGuard":"from semantic_kernel.exceptions import ServiceInitializationError\n\ndef is_mistral_settings_error(e: BaseException) -> bool:\n    return isinstance(e, ServiceInitializationError) and 'Failed to validate Mistral AI settings' in str(e)","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    svc = MistralAITextEmbedding()\nexcept ServiceInitializationError as e:\n    raise SystemExit(f'Mistral embedding service misconfigured: {e}') from e","preventionTips":["Put MISTRALAI_API_KEY and MISTRALAI_EMBEDDING_MODEL_ID in .env and load it explicitly.","Validate settings with pydantic before constructing the service in tests.","Confirm env_file_path exists and is utf-8."],"tags":["mistral-ai","embeddings","settings","configuration","pydantic","service-initialization-error"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}