microsoft/semantic-kernel · error · ServiceInitializationError

Failed to validate Vertex AI settings: {e}

Error message

Failed to validate Vertex AI settings: {e}

What it means

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.

Source

Thrown at python/semantic_kernel/connectors/ai/google/vertex_ai/services/vertex_ai_chat_completion.py:103

        Args:
            project_id (str): The Google Cloud project ID.
            region (str): The Google Cloud region.
            gemini_model_id (str): The Gemini model ID.
            service_id (str): The Vertex AI service ID.
            env_file_path (str): The path to the environment file.
            env_file_encoding (str): The encoding of the environment file.
        """
        try:
            vertex_ai_settings = VertexAISettings(
                project_id=project_id,
                region=region,
                gemini_model_id=gemini_model_id,
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
            )
        except ValidationError as e:
            raise ServiceInitializationError(f"Failed to validate Vertex AI settings: {e}") from e
        if not vertex_ai_settings.gemini_model_id:
            raise ServiceInitializationError("The Vertex AI Gemini model ID is required.")

        super().__init__(
            ai_model_id=vertex_ai_settings.gemini_model_id,
            service_id=service_id or vertex_ai_settings.gemini_model_id,
            service_settings=vertex_ai_settings,
        )

    # region Overriding base class methods

    # Override from AIServiceClientBase
    @override
    def get_prompt_execution_settings_class(self) -> type["PromptExecutionSettings"]:
        return VertexAIChatPromptExecutionSettings

    @override
    @trace_chat_completion(VertexAIBase.MODEL_PROVIDER_NAME)

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Read the full {e} validation error to identify which field(s) failed (project_id, region, etc.).
  2. Set the required environment variables (e.g. VERTEX_AI_PROJECT, VERTEX_AI_LOCATION/region) or pass them explicitly to the constructor.
  3. Verify the env_file_path points to a readable .env with the correct keys and encoding.
  4. Ensure you are authenticated to Google Cloud (gcloud auth application-default login) if credentials are part of the settings chain.

Example fix

# before
svc = VertexAIChatCompletion()  # no env set
# after
import os
os.environ['VERTEX_AI_PROJECT'] = 'my-project'
os.environ['VERTEX_AI_LOCATION'] = 'us-central1'
svc = VertexAIChatCompletion(gemini_model_id='gemini-1.5-pro')
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.connectors.ai.google.vertex_ai.vertex_ai_settings import VertexAISettings
try:
    s = VertexAISettings()  # reads env / .env
    print(s.project_id, s.region)
except Exception as e:
    print('config invalid:', e)

Try / catch

try:
    svc = VertexAIChatCompletion(project_id=..., region=..., gemini_model_id=...)
except ServiceInitializationError as e:
    # read e.__cause__ for the ValidationError detail
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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