{"record":{"id":"de378811af1a5e91","repo":"microsoft/semantic-kernel","slug":"failed-to-validate-google-ai-settings-e","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_chat_completion.py","lineNumber":114,"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                gemini_model_id=gemini_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.gemini_model_id:\n            raise ServiceInitializationError(\"The Google AI Gemini 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.gemini_model_id,\n            service_id=service_id or google_ai_settings.gemini_model_id,\n            service_settings=google_ai_settings,\n            client=client,\n        )","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py#L96-L132","documentation":"Raised during GoogleAIChatCompletion.__init__ when constructing GoogleAISettings raises a pydantic ValidationError. The constructor wraps any pydantic validation failure (wrong types, extra required fields, env parsing) into a ServiceInitializationError with the underlying validation message.","triggerScenarios":"Constructing GoogleAIChatCompletion with arguments or environment variables that fail GoogleAISettings pydantic validation: wrong types (e.g. use_vertexai='true' string instead of bool), missing required env vars if settings were declared required, or malformed SecretStr for the API key.","commonSituations":"GOOGLE_AI_* environment variables misconfigured (wrong types, unparseable bool); passing a non-bool for use_vertexai; corrupted .env; version mismatch where GoogleAISettings added a required field.","solutions":["Read the wrapped ValidationError text in the exception: it lists the exact failing field(s) and reasons.","Correct the offending argument or environment variable (type/format) accordingly.","Provide explicit constructor arguments (gemini_model_id, api_key, etc.) to bypass env parsing and isolate the issue."],"exampleFix":"# before\nos.environ[\"GOOGLE_AI_USE_VERTEXAI\"] = \"yes\"  # not a valid bool\nsvc = GoogleAIChatCompletion()\n# after\nos.environ[\"GOOGLE_AI_USE_VERTEXAI\"] = \"true\"\nsvc = GoogleAIChatCompletion()","handlingStrategy":"try-catch","validationCode":"from pydantic import ValidationError\nfrom semantic_kernel.connectors.ai.google.google_ai.google_ai_settings import GoogleAISettings\n\ndef google_ai_settings_validate(**kwargs) -> bool:\n    try:\n        GoogleAISettings(**{k: v for k, v in kwargs.items() if v is not None})\n        return True\n    except ValidationError:\n        return False","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    svc = GoogleAIChatCompletion(gemini_model_id=mid, api_key=key, use_vertexai=vertex)\nexcept ServiceInitializationError as e:\n    if \"Failed to validate Google AI settings\" in str(e):\n        logger.error(\"Settings validation failed: %s\", e)\n    raise","preventionTips":["Pre-validate settings by constructing GoogleAISettings directly to surface the pydantic error first.","Ensure GOOGLE_AI_* env vars have correct types (bool for USE_VERTEXAI).","Provide explicit constructor arguments to isolate which field fails validation."],"tags":["google-ai","gemini","settings","pydantic","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}