{"record":{"id":"52400fa714e67005","repo":"crewAIInc/crewAI","slug":"tavily-client-is-not-initialized-ensure-tavily-p","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_extractor_tool/tavily_extractor_tool.py","lineNumber":139,"sourceCode":"                raise ImportError(\n                    \"The 'tavily-python' package is required to use the TavilyExtractorTool. \"\n                    \"Please install it with: uv add tavily-python\"\n                )\n\n    def _run(\n        self,\n        urls: list[str] | str,\n    ) -> str:\n        \"\"\"Synchronously extracts content from the given URL(s).\n\n        Args:\n            urls: The URL(s) to extract data from.\n\n        Returns:\n            A JSON string containing the extracted data.\n        \"\"\"\n        if not self.client:\n            raise ValueError(\n                \"Tavily client is not initialized. Ensure 'tavily-python' is installed and API key is set.\"\n            )\n\n        return json.dumps(\n            self.client.extract(\n                urls=urls,\n                extract_depth=self.extract_depth,\n                include_images=self.include_images,\n                timeout=self.timeout,\n            ),\n            indent=2,\n        )\n\n    async def _arun(\n        self,\n        urls: list[str] | str,\n    ) -> str:\n        \"\"\"Asynchronously extracts content from the given URL(s).","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/tavily_extractor_tool/tavily_extractor_tool.py#L121-L157","documentation":"Raised by TavilyExtractorTool._run when self.client is None at call time. self.client is only built in __init__ when TAVILY_AVAILABLE is true; if construction took the install-prompt path (or the object was assembled unusually, e.g. via __new__ or failed init), _run refuses to call Tavily's extract API without a client.","triggerScenarios":"Calling tool._run(urls) (or tool.run) on a TavilyExtractorTool whose __init__ never set self.client — i.e. tavily-python was not importable at construction time, or TAVILY_API_KEY-dependent client creation was skipped.","commonSituations":"Tool object created before tavily-python was installed (client stayed None) and then used after install without re-instantiation; partial init where an exception in __init__ left the object half-configured.","solutions":["Install tavily-python and create a NEW TavilyExtractorTool instance (the old one will never gain a client).","Verify TAVILY_API_KEY / the api_key argument is set at construction time.","Check tool.client is truthy before invoking run(); treat None as 'rebuild the tool'."],"exampleFix":"# before\nresult = tool._run(\"https://example.com\")  # client is None -> ValueError\n\n# after\nif not tool.client:\n    tool = TavilyExtractorTool(api_key=...)  # rebuild after installing tavily-python\nresult = tool._run(\"https://example.com\")","handlingStrategy":"type-guard","validationCode":"if not getattr(tool, \"client\", None):\n    raise RuntimeError(\"TavilyExtractorTool has no client; re-create it after installing tavily-python\")","typeGuard":"def extractor_ready(tool) -> bool:\n    \"\"\"True when the sync Tavily client is initialized.\"\"\"\n    return getattr(tool, \"client\", None) is not None","tryCatchPattern":"try:\n    out = tool._run(urls)\nexcept ValueError as e:\n    if \"Tavily client is not initialized\" in str(e):\n        tool = TavilyExtractorTool(api_key=os.environ[\"TAVILY_API_KEY\"])\n        out = tool._run(urls)\n    else:\n        raise","preventionTips":["Always construct Tavily tools after tavily-python and TAVILY_API_KEY are confirmed present.","Discard and rebuild tool instances after dependency changes; never reuse half-initialized tools.","In CrewAI factories, assert the client attribute before attaching the tool to an agent."],"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"}