{"record":{"id":"5c3975a9061b59dc","repo":"microsoft/semantic-kernel","slug":"failed-to-validate-google-ai-settings-e-5c3975","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_completion.py","lineNumber":85,"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":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py#L67-L103","documentation":"Raised in the GoogleAITextCompletion constructor when GoogleAISettings(...) fails Pydantic validation. The ValidationError (wrapped in ServiceInitializationError with the detail string) reports which fields failed type or format validation. GoogleAISettings is a Pydantic KernelBaseSettings model with prefix GOOGLE_AI_ that validates api_key (SecretStr), use_vertexai (bool), and related fields at construction time.","triggerScenarios":"Constructing GoogleAITextCompletion with arguments or environment variables that fail Pydantic field validation — e.g. passing a non-bool to use_vertexai, a malformed value for api_key, or an env var that cannot be coerced to the declared type.","commonSituations":"GOOGLE_AI_USE_VERTEXAI set to a non-bool string that Pydantic cannot coerce; GOOGLE_AI_API_KEY empty after SecretStr validation; passing incompatible keyword argument types; partial/invalid .env file.","solutions":["Read the full ValidationError message (in the {e} substitution) to identify the exact field that failed.","Fix the offending environment variable or constructor argument to match the declared Pydantic type.","Validate your .env file values independently before constructing the service."],"exampleFix":"# before: env has GOOGLE_AI_USE_VERTEXAI=yes (ambiguous)\n# after:  env has 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'Settings validation failed: {e}')","typeGuard":null,"tryCatchPattern":"try:\n    service = GoogleAITextCompletion(...)\nexcept ServiceInitializationError as e:\n    if 'Failed to validate Google AI settings' in str(e):\n        # the inner ValidationError details are in the message\n        logging.error(f'Google AI settings invalid: {e}')\n        # fix env/args then retry construction\n    raise","preventionTips":["Validate GoogleAISettings() in isolation during startup to surface Pydantic errors before building services.","Use a .env loader in tests to confirm every GOOGLE_AI_ variable parses correctly.","Keep use_vertexai as a strict bool in your .env (true/false)."],"tags":["google-ai","pydantic","validation","settings","configuration","text-completion"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}