{"record":{"id":"79ce4bbe5c909aea","repo":"crewAIInc/crewAI","slug":"tavily-client-is-not-initialized-ensure-tavily-p-79ce4b","errorCode":null,"errorMessage":"Tavily client is not initialized. Ensure 'tavily-python' is installed and API key is set.","messagePattern":"Tavily client is not initialized\\. Ensure 'tavily-python' is installed and API key is set\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/tavily_research_tool/tavily_research_tool.py","lineNumber":148,"sourceCode":"                )\n\n    @staticmethod\n    def _stringify_response(response: Any) -> str:\n        if isinstance(response, str):\n            return response\n        return json.dumps(response, indent=2)\n\n    def _run(\n        self,\n        input: str,\n        model: Literal[\"mini\", \"pro\", \"auto\"] | None = None,\n        output_schema: dict[str, Any] | None = None,\n        stream: bool | None = None,\n        citation_format: Literal[\"numbered\", \"mla\", \"apa\", \"chicago\"] | None = None,\n    ) -> str | Generator[bytes, None, None]:\n        \"\"\"Synchronously creates Tavily research tasks or streams results.\"\"\"\n        if not self._client:\n            raise ValueError(\n                \"Tavily client is not initialized. Ensure 'tavily-python' is \"\n                \"installed and API key is set.\"\n            )\n\n        use_stream = self.stream if stream is None else stream\n        result = self._client.research(\n            input=input,\n            model=self.model if model is None else model,\n            output_schema=self.output_schema\n            if output_schema is None\n            else output_schema,\n            stream=use_stream,\n            citation_format=(\n                self.citation_format if citation_format is None else citation_format\n            ),\n        )\n\n        if use_stream:","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/tavily_research_tool/tavily_research_tool.py#L130-L166","documentation":"TavilyResearchTool._run raises this ValueError when self._client is None before calling client.research(...) to create/stream a Tavily research task. The client only exists if tavily-python was importable at __init__ time, so None indicates a tool built without its dependency (or with a swallowed init failure).","triggerScenarios":"Invoking tool.run(input=..., model=..., stream=...) on an instance whose __init__ never built a TavilyClient — tavily-python missing at construction, or init interrupted.","commonSituations":"Stale tool instances from before the package was installed; TAVILY_API_KEY missing at construction in code paths that assume lazy init.","solutions":["Install tavily-python and set TAVILY_API_KEY, then create a fresh TavilyResearchTool.","Assert tool._client is not None before invoking run().","Rebuild tools after any environment/dependency change instead of reusing instances."],"exampleFix":"# before\nout = tool._run(\"research quantum error correction\")  # -> ValueError\n\n# after\nif not tool._client:\n    tool = TavilyResearchTool()\nout = tool._run(\"research quantum error correction\")","handlingStrategy":"type-guard","validationCode":"if not getattr(tool, \"_client\", None):\n    raise RuntimeError(\"TavilyResearchTool uninitialized; rebuild after installing tavily-python\")","typeGuard":"def research_ready(tool) -> bool:\n    \"\"\"True when the sync Tavily research client exists.\"\"\"\n    return getattr(tool, \"_client\", None) is not None","tryCatchPattern":"try:\n    out = tool._run(input=\"...\")\nexcept ValueError as e:\n    if \"Tavily client is not initialized\" in str(e):\n        tool = TavilyResearchTool()\n        out = tool._run(input=\"...\")\n    else:\n        raise","preventionTips":["Verify tavily-python import and TAVILY_API_KEY before tool construction.","Guard on _client before run(); rebuild the tool if it is None.","Never reuse tool instances across dependency/environment changes."],"tags":["tavily","not-initialized","lifecycle","crewai-tools"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}