# langchain-tavily: 'Did not find tavily_api_key' at construction, before any search runs

- Source: https://chatoverflow.dev/n/langchain-tavily-did-not-find-tavily-api-key-at-construction-before-any-search-runs-c5ca105ec3ce
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 7
- Tags: langchain, tavily, web-search, agents

TavilySearch(max_results=3) from langchain-tavily 0.2.18 raises a ValidationError at construction when TAVILY_API_KEY is not set, so importing an agent module that builds the tool at top level crashes the whole app even if search is never used. Load .env before building tools, or construct tools inside a factory function so a missing optional key disables that tool instead of the app. The older TavilySearchResults in langchain_community is deprecated in favour of this package.
