microsoft/semantic-kernel · error · ServiceInitializationError
Failed to validate Google AI settings: {e}
Error message
Failed to validate Google AI settings: {e} What it means
Raised in the GoogleAITextEmbedding constructor when GoogleAISettings(...) fails Pydantic validation. The ValidationError string is included in the message. Mirrors the text-completion constructor: field-level Pydantic errors (types, formats) prevent the settings model from being built, which is fatal for embedding service construction.
Source
Thrown at python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py:76
client (Client | None): The Google AI Client to use for break glass scenarios. (Optional)
env_file_path (str | None): The path to the .env file. (Optional)
env_file_encoding (str | None): The encoding of the .env file. (Optional)
Raises:
ServiceInitializationError: If an error occurs during initialization.
"""
try:
google_ai_settings = GoogleAISettings(
embedding_model_id=embedding_model_id,
api_key=api_key,
cloud_project_id=project_id,
cloud_region=region,
use_vertexai=use_vertexai,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as e:
raise ServiceInitializationError(f"Failed to validate Google AI settings: {e}") from e
if not google_ai_settings.embedding_model_id:
raise ServiceInitializationError("The Google AI embedding model ID is required.")
if not client:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:
raise ServiceInitializationError("Region must be provided when use_vertexai is True.")
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
raise ServiceInitializationError("The API key is required when use_vertexai is False.")
super().__init__(
ai_model_id=google_ai_settings.embedding_model_id,
service_id=service_id or google_ai_settings.embedding_model_id,
service_settings=google_ai_settings,
client=client,
)View on GitHub (pinned to c028a0c7dc)
Solutions
- Inspect the full ValidationError text in the error message to find the failing field.
- Correct the env var or constructor argument to satisfy the declared Pydantic type.
- Load and validate settings in isolation first to surface the exact validation failure.
Example fix
# before: GOOGLE_AI_USE_VERTEXAI=1 (int-like, ambiguous) # after: GOOGLE_AI_USE_VERTEXAI=true
Defensive patterns
Strategy: try-catch
Validate before calling
from semantic_kernel.connectors.ai.google.google_ai.google_ai_settings import GoogleAISettings
from pydantic import ValidationError
try:
GoogleAISettings()
except ValidationError as e:
print(f'Embedding settings validation failed: {e}') Try / catch
try:
service = GoogleAITextEmbedding(...)
except ServiceInitializationError as e:
if 'Failed to validate Google AI settings' in str(e):
logging.error(f'Settings invalid: {e}')
raise Prevention
- Pre-validate GoogleAISettings during startup before building the embedding service.
- Check all GOOGLE_AI_ env vars parse to the declared Pydantic types.
- Keep .env values typed strictly (bools as true/false, no stray whitespace).
When it happens
Trigger: Constructing GoogleAITextEmbedding with arguments or GOOGLE_AI_ environment variables that violate Pydantic field constraints (e.g. non-bool use_vertexai, malformed SecretStr api_key).
Common situations: Invalid .env values for GOOGLE_AI_ prefixed vars; passing a wrong type for an argument; env var naming mismatch causing a parse failure.
Related errors
- Failed to validate Google AI settings: {e}
- Failed to validate Mistral AI settings: {e}
- Failed to create NVIDIA settings.
- Unsupported service name: {service_name}
- Failed to initialize the Amazon Bedrock Agent settings: {e}
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/740db5a8d8dfaab0.
Report an issue: GitHub.