{"record":{"id":"740db5a8d8dfaab0","repo":"microsoft/semantic-kernel","slug":"failed-to-validate-google-ai-settings-e-740db5","errorCode":null,"errorMessage":"Failed to validate Google AI settings: {e}","messagePattern":"Failed to validate Google AI settings: (.+?)","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py","lineNumber":76,"sourceCode":"            client (Client | None): The Google AI Client to use for break glass scenarios. (Optional)\n            env_file_path (str | None): The path to the .env file. (Optional)\n            env_file_encoding (str | None): The encoding of the .env file. (Optional)\n\n        Raises:\n            ServiceInitializationError: If an error occurs during initialization.\n        \"\"\"\n        try:\n            google_ai_settings = GoogleAISettings(\n                embedding_model_id=embedding_model_id,\n                api_key=api_key,\n                cloud_project_id=project_id,\n                cloud_region=region,\n                use_vertexai=use_vertexai,\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 Google AI settings: {e}\") from e\n\n        if not google_ai_settings.embedding_model_id:\n            raise ServiceInitializationError(\"The Google AI embedding model ID is required.\")\n\n        if not client:\n            if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:\n                raise ServiceInitializationError(\"Project ID must be provided when use_vertexai is True.\")\n            if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:\n                raise ServiceInitializationError(\"Region must be provided when use_vertexai is True.\")\n            if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:\n                raise ServiceInitializationError(\"The API key is required when use_vertexai is False.\")\n\n        super().__init__(\n            ai_model_id=google_ai_settings.embedding_model_id,\n            service_id=service_id or google_ai_settings.embedding_model_id,\n            service_settings=google_ai_settings,\n            client=client,\n        )","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py#L58-L94","documentation":"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.","triggerScenarios":"Constructing GoogleAITextEmbedding with arguments or GOOGLE_AI_ environment variables that violate Pydantic field constraints (e.g. non-bool use_vertexai, malformed SecretStr api_key).","commonSituations":"Invalid .env values for GOOGLE_AI_ prefixed vars; passing a wrong type for an argument; env var naming mismatch causing a parse failure.","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."],"exampleFix":"# before: GOOGLE_AI_USE_VERTEXAI=1 (int-like, ambiguous)\n# after:  GOOGLE_AI_USE_VERTEXAI=true","handlingStrategy":"try-catch","validationCode":"from semantic_kernel.connectors.ai.google.google_ai.google_ai_settings import GoogleAISettings\nfrom pydantic import ValidationError\n\ntry:\n    GoogleAISettings()\nexcept ValidationError as e:\n    print(f'Embedding settings validation failed: {e}')","typeGuard":null,"tryCatchPattern":"try:\n    service = GoogleAITextEmbedding(...)\nexcept ServiceInitializationError as e:\n    if 'Failed to validate Google AI settings' in str(e):\n        logging.error(f'Settings invalid: {e}')\n    raise","preventionTips":["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)."],"tags":["google-ai","pydantic","validation","settings","configuration","embeddings"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}