{"record":{"id":"8762f54787e05c9d","repo":"microsoft/semantic-kernel","slug":"failed-to-validate-vertex-ai-settings-e","errorCode":null,"errorMessage":"Failed to validate Vertex AI settings: {e}","messagePattern":"Failed to validate Vertex AI settings: (.+?)","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/vertex_ai/services/vertex_ai_chat_completion.py","lineNumber":103,"sourceCode":"\n        Args:\n            project_id (str): The Google Cloud project ID.\n            region (str): The Google Cloud region.\n            gemini_model_id (str): The Gemini model ID.\n            service_id (str): The Vertex AI service ID.\n            env_file_path (str): The path to the environment file.\n            env_file_encoding (str): The encoding of the environment file.\n        \"\"\"\n        try:\n            vertex_ai_settings = VertexAISettings(\n                project_id=project_id,\n                region=region,\n                gemini_model_id=gemini_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 Vertex AI settings: {e}\") from e\n        if not vertex_ai_settings.gemini_model_id:\n            raise ServiceInitializationError(\"The Vertex AI Gemini model ID is required.\")\n\n        super().__init__(\n            ai_model_id=vertex_ai_settings.gemini_model_id,\n            service_id=service_id or vertex_ai_settings.gemini_model_id,\n            service_settings=vertex_ai_settings,\n        )\n\n    # region Overriding base class methods\n\n    # Override from AIServiceClientBase\n    @override\n    def get_prompt_execution_settings_class(self) -> type[\"PromptExecutionSettings\"]:\n        return VertexAIChatPromptExecutionSettings\n\n    @override\n    @trace_chat_completion(VertexAIBase.MODEL_PROVIDER_NAME)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/vertex_ai/services/vertex_ai_chat_completion.py#L85-L121","documentation":"Raised by VertexAIChatCompletion.__init__ when constructing VertexAISettings raises a pydantic ValidationError. This wraps the underlying validation failure (project_id/region/gemini_model_id/env constraints) into a ServiceInitializationError so the service fails fast at construction with the original validation detail in the message.","triggerScenarios":"Instantiating VertexAIChatCompletion with missing or malformed configuration: no project_id, invalid region, or an env file / environment variables that don't satisfy VertexAISettings validators. The wrapped {e} carries the specific pydantic error list.","commonSituations":"Missing VERTEX_AI_PROJECT / GOOGLE_CLOUD_PROJECT env var. No Application Default Credentials or region set. Typo in .env keys. Wrong env file path passed to the constructor.","solutions":["Read the full {e} validation error to identify which field(s) failed (project_id, region, etc.).","Set the required environment variables (e.g. VERTEX_AI_PROJECT, VERTEX_AI_LOCATION/region) or pass them explicitly to the constructor.","Verify the env_file_path points to a readable .env with the correct keys and encoding.","Ensure you are authenticated to Google Cloud (gcloud auth application-default login) if credentials are part of the settings chain."],"exampleFix":"# before\nsvc = VertexAIChatCompletion()  # no env set\n# after\nimport os\nos.environ['VERTEX_AI_PROJECT'] = 'my-project'\nos.environ['VERTEX_AI_LOCATION'] = 'us-central1'\nsvc = VertexAIChatCompletion(gemini_model_id='gemini-1.5-pro')","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.ai.google.vertex_ai.vertex_ai_settings import VertexAISettings\ntry:\n    s = VertexAISettings()  # reads env / .env\n    print(s.project_id, s.region)\nexcept Exception as e:\n    print('config invalid:', e)","typeGuard":null,"tryCatchPattern":"try:\n    svc = VertexAIChatCompletion(project_id=..., region=..., gemini_model_id=...)\nexcept ServiceInitializationError as e:\n    # read e.__cause__ for the ValidationError detail\n    raise","preventionTips":["Set VERTEX_AI_PROJECT and region via env or .env before constructing the service.","Run Application Default Credentials (gcloud auth application-default login).","Unit-test settings construction in isolation to surface validation errors early."],"tags":["vertex-ai","configuration","settings","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}