{"record":{"id":"8ffb86734be17136","repo":"microsoft/semantic-kernel","slug":"failed-to-create-brave-settings","errorCode":null,"errorMessage":"Failed to create Brave settings.","messagePattern":"Failed to create Brave settings\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/brave.py","lineNumber":141,"sourceCode":"    ) -> None:\n        \"\"\"Initializes a new instance of the Brave Search class.\n\n        Args:\n            api_key: The Brave Search API key. If provided, will override\n                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. If provided,\n                the settings are read from this file path location.\n        \"\"\"\n        try:\n            settings = BraveSettings(\n                api_key=api_key,\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 Brave 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":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/brave.py#L123-L159","documentation":"The Brave connector constructs a BraveSettings (pydantic) object during initialization; if validation fails — most often because the required api_key is missing — pydantic raises ValidationError, which the connector re-raises as ServiceInitializationError. This prevents instantiating a connector that could never authenticate.","triggerScenarios":"Instantiating BraveSearch(connector) without an api_key argument and without a BRAVE api key available in environment variables or a .env file. The BraveSettings model requires api_key, so its absence triggers ValidationError caught at brave.py:140-141.","commonSituations":"Forgetting to set the Brave API key env var before creating the connector, pointing env_file_path at a missing/incorrect .env, or a typo in the env var name. Also after rotating/invalidating a key.","solutions":["Provide the key explicitly: BraveSearch(api_key=\"...\") or BraveSettings via constructor.","Set the expected environment variable (consult BraveSettings field aliases) or a .env file at the given env_file_path so the key loads.","Verify the key is present and non-empty before constructing the connector."],"exampleFix":"// before\nconnector = BraveSearch()  # no api_key anywhere\n// after\nconnector = BraveSearch(api_key=os.environ[\"BRAVE_API_KEY\"])\n","handlingStrategy":"validation","validationCode":"import os\napi_key = os.environ.get(\"BRAVE_API_KEY\") or os.environ.get(\"BRAVE_API_KEY\")  # per BraveSettings alias\nif not api_key:\n    raise ValueError(\"BRAVE_API_KEY not set; cannot initialize Brave connector\")","typeGuard":"def has_brave_key() -> bool:\n    return bool(os.environ.get(\"BRAVE_API_KEY\"))","tryCatchPattern":null,"preventionTips":["Set the Brave API key in the environment or a .env file before constructing the connector.","Pass api_key explicitly in tests to avoid env dependence.","Confirm the env var name matches BraveSettings aliases."],"tags":["brave","configuration","authentication","settings"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}