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 VertexAITextCompletion.__init__ when VertexAISettings construction throws a pydantic ValidationError. The error wraps the validation detail into a ServiceInitializationError so text-completion service initialization fails fast with the underlying reason (project_id/region/env).
Source
Thrown at python/semantic_kernel/connectors/ai/google/vertex_ai/services/vertex_ai_text_completion.py:75
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 VertexAITextPromptExecutionSettings
@override
@trace_text_completion(VertexAIBase.MODEL_PROVIDER_NAME)View on GitHub (pinned to c028a0c7dc)
Solutions
- Inspect the embedded {e} to find the failing field(s).
- Provide project_id and region explicitly or via env/ .env.
- Confirm env_file_path is correct and the file has the expected keys.
Example fix
# before svc = VertexAITextCompletion() # after svc = VertexAITextCompletion(project_id='my-project', region='us-central1', 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()
except Exception as e:
print('config invalid:', e) Try / catch
try:
svc = VertexAITextCompletion(project_id=..., region=..., gemini_model_id=...)
except ServiceInitializationError as e:
raise Prevention
- Configure project_id and region before constructing the text-completion service.
- Validate env / .env contents in isolation.
- Confirm credentials are set up for Vertex AI.
When it happens
Trigger: Instantiating VertexAITextCompletion with missing/malformed project_id, region, or env configuration. Same root causes as the chat variant but on the text-completion constructor.
Common situations: Missing VERTEX_AI_PROJECT or region env var. Bad .env path/encoding. Credentials not configured for the text-completion flow.
Related errors
- Failed to validate Vertex AI settings: {e}
- The Vertex AI Gemini model ID is required.
- Failed to validate Vertex AI settings: {e}
- Project ID must be provided when use_vertexai is True.
- Region must be provided when use_vertexai is True.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/40a0f1006b1c63cf.
Report an issue: GitHub.