{"record":{"id":"56469bbfc0a9ed96","repo":"microsoft/semantic-kernel","slug":"failed-to-create-google-settings","errorCode":null,"errorMessage":"Failed to create Google settings.","messagePattern":"Failed to create Google settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"critical","filePath":"python/semantic_kernel/connectors/google_search.py","lineNumber":181,"sourceCode":"\n        Args:\n            api_key: The Google Search API key. If provided, will override\n                the value in the env vars or .env file.\n            search_engine_id: The Google search engine ID.\n                If provided, will override the value in the env vars or .env file.\n            env_file_path: The optional path to the .env file. If provided,\n                the settings are read from this file path location.\n            env_file_encoding: The optional encoding of the .env file.\n        \"\"\"\n        try:\n            settings = GoogleSearchSettings(\n                api_key=api_key,\n                engine_id=search_engine_id,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as ex:\n            raise ServiceInitializationError(\"Failed to create Google settings.\") from ex\n\n        super().__init__(settings=settings)  # type: ignore[call-arg]\n\n    @override\n    async def search(\n        self,\n        query: str,\n        output_type: type[str] | type[TSearchResult] | Literal[\"Any\"] = str,\n        *,\n        filter: OptionalOneOrList[Callable | str] = None,\n        skip: int = 0,\n        top: int = 5,\n        include_total_count: bool = False,\n        **kwargs: Any,\n    ) -> \"KernelSearchResults[TSearchResult]\":\n        options = SearchOptions(filter=filter, skip=skip, top=top, include_total_count=include_total_count, **kwargs)\n        results = await self._inner_search(query=query, options=options)\n        return KernelSearchResults(","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/google_search.py#L163-L199","documentation":"GoogleSearch.__init__ builds a GoogleSearchSettings object, which loads api_key (a required pydantic SecretStr) from the constructor arg or the env var GOOGLE_SEARCH_API_KEY (settings prefix GOOGLE_SEARCH_). If validation fails the pydantic ValidationError is caught and re-raised as ServiceInitializationError. This is a startup/configuration failure: the connector cannot be constructed without a valid API key.","triggerScenarios":"Instantiating GoogleSearch() with no api_key argument and no GOOGLE_SEARCH_API_KEY environment variable or .env entry; passing an empty string or a value of the wrong type; pointing env_file_path at a missing/unreadable file.","commonSituations":"Forgot to export the env var locally; .env not on the loaded path; CI/containers missing the secret; wrong prefix (e.g. GOOGLE_API_KEY instead of GOOGLE_SEARCH_API_KEY); key revoked or pasted with stray whitespace.","solutions":["Set the env var GOOGLE_SEARCH_API_KEY (and optionally GOOGLE_SEARCH_ENGINE_ID) in your shell, container, or .env.","Pass the key explicitly: GoogleSearch(api_key='...', search_engine_id='...').","If using a .env file, pass env_file_path='/path/to/.env' and confirm it is readable and uses the GOOGLE_SEARCH_ prefix."],"exampleFix":"# before\nsearch = GoogleSearch()  # no env var, no .env -> ValidationError -> [1302]\n\n# after\nimport os\nos.environ['GOOGLE_SEARCH_API_KEY'] = '<your key>'\nos.environ['GOOGLE_SEARCH_ENGINE_ID'] = '<your cx>'\nsearch = GoogleSearch(env_file_path='.env')","handlingStrategy":"validation","validationCode":"import os\n\ndef ensure_google_settings_present():\n    if not os.environ.get('GOOGLE_SEARCH_API_KEY'):\n        raise RuntimeError('Set GOOGLE_SEARCH_API_KEY (or pass api_key=) before creating GoogleSearch')\n    # engine_id is optional at settings level but required for real queries","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    google = GoogleSearch(env_file_path='.env')\nexcept ServiceInitializationError as ex:\n    # ex.__cause__ is the pydantic ValidationError listing missing fields\n    raise SystemExit(f'Google Search misconfigured: {ex.__cause__.errors()}') from ex","preventionTips":["Store GOOGLE_SEARCH_API_KEY in a .env or secret manager, never in code.","Use the GOOGLE_SEARCH_ prefix exactly (not GOOGLE_).","Fail fast at startup with an explicit check rather than at first search."],"tags":["google-search","config","secrets","initialization","pydantic"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}