crewAIInc/crewAI · error · ValueError

WEAVIATE_URL or WEAVIATE_API_KEY is not set

Error message

WEAVIATE_URL or WEAVIATE_API_KEY is not set

What it means

WeaviateVectorSearchTool._run requires both a cluster URL and an API key to call weaviate.connect_to_weaviate_cloud. If either weaviate_cluster_url or weaviate_api_key is empty/None at run time, it raises ValueError before attempting the connection.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/weaviate_tool/vector_search.py:113

        else:
            if click.confirm(
                "You are missing the 'weaviate-client' package. Would you like to install it?"
            ):
                subprocess.run(["uv", "pip", "install", "weaviate-client"], check=True)  # noqa: S607

            else:
                raise ImportError(
                    "You are missing the 'weaviate-client' package. Would you like to install it?"
                )

    def _run(self, query: str) -> str:
        if not WEAVIATE_AVAILABLE:
            raise ImportError(
                "You are missing the 'weaviate-client' package. Would you like to install it?"
            )

        if not self.weaviate_cluster_url or not self.weaviate_api_key:
            raise ValueError("WEAVIATE_URL or WEAVIATE_API_KEY is not set")

        client = weaviate.connect_to_weaviate_cloud(
            cluster_url=self.weaviate_cluster_url,
            auth_credentials=Auth.api_key(self.weaviate_api_key),
            headers=self.headers,
        )
        internal_docs = client.collections.get(self.collection_name)

        if not internal_docs:
            internal_docs = client.collections.create(
                name=self.collection_name,
                vectorizer_config=self.vectorizer,
                generative_config=self.generative_model,
            )

        response = internal_docs.query.hybrid(
            query=query, limit=self.limit, alpha=self.alpha
        )

View on GitHub (pinned to 754d7323be)

Solutions

  1. Provide both values explicitly: WeaviateVectorSearchTool(weaviate_cluster_url='https://your.weaviate.network', weaviate_api_key='...').
  2. Set and verify env vars (WEAVIATE_URL, WEAVIATE_API_KEY) at startup with an assertion.
  3. Log the resolved config (names only, never the key value) before running the tool to spot empty fields.

Example fix

# before
tool.run('query')  # one of cluster_url/api_key empty -> ValueError

# after
import os
url = os.environ['WEAVIATE_URL']
key = os.environ['WEAVIATE_API_KEY']
tool = WeaviateVectorSearchTool(
    weaviate_cluster_url=url, weaviate_api_key=key
)
tool.run('query')
Defensive patterns

Strategy: validation

Validate before calling

import os

url = os.environ.get('WEAVIATE_URL', '').strip()
key = os.environ.get('WEAVIATE_API_KEY', '').strip()
if not url or not key:
    raise SystemExit('WEAVIATE_URL and WEAVIATE_API_KEY must both be set')

Try / catch

try:
    out = tool.run(query)
except ValueError as e:
    if 'WEAVIATE_URL or WEAVIATE_API_KEY' in str(e):
        raise SystemExit('Provide weaviate_cluster_url and weaviate_api_key')
    raise

Prevention

When it happens

Trigger: Calling tool.run(query) after constructing the tool with an empty string, None, or missing weaviate_cluster_url/weaviate_api_key (they are declared required Fields, but defaults or empty strings can still slip through depending on construction path).

Common situations: Reading WEAVIATE_URL/WEAVIATE_API_KEY from env vars that are unset in the deployed environment; typos in kwarg names passing values that never land on the fields; config files with blank values.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/490df9d79c5bafc6. Report an issue: GitHub.