langchain-ai/langchain · error · ValueError

Received both `client` and `client_kwargs`. Pass `client_kwa

Error message

Received both `client` and `client_kwargs`. Pass `client_kwargs` only when `client` is not provided.

What it means

`LangSmithLoader.__init__` (document_loaders/langsmith.py) rejects initialization with both a prebuilt `client` and `client_kwargs`: the kwargs exist only to construct a client when one isn't supplied, and passing both makes the intended client ambiguous. It is a fail-fast `ValueError` before any network call.

Source

Thrown at libs/core/langchain_core/document_loaders/langsmith.py:101

            limit: The maximum number of examples to return.
            metadata: Metadata to filter by.
            filter: A structured filter string to apply to the examples.
            client: LangSmith Client.

                If not provided will be initialized from below args.
            client_kwargs: Keyword args to pass to LangSmith client init.

                Should only be specified if `client` isn't.

        Raises:
            ValueError: If both `client` and `client_kwargs` are provided.
        """  # noqa: E501
        if client and client_kwargs:
            msg = (
                "Received both `client` and `client_kwargs`. "
                "Pass `client_kwargs` only when `client` is not provided."
            )
            raise ValueError(msg)
        self._client = client or LangSmithClient(**client_kwargs)
        self.content_key = list(content_key.split(".")) if content_key else []
        self.format_content = format_content or _stringify
        self.dataset_id = dataset_id
        self.dataset_name = dataset_name
        self.example_ids = example_ids
        self.as_of = as_of
        self.splits = splits
        self.inline_s3_urls = inline_s3_urls
        self.offset = offset
        self.limit = limit
        self.metadata = metadata
        self.filter = filter

    @override
    def lazy_load(self) -> Iterator[Document]:
        for example in self._client.list_examples(
            dataset_id=self.dataset_id,

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. If you have a client, drop `client_kwargs` entirely
  2. If you only have connection settings, omit `client` and let kwargs build it
  3. In factories, normalize: `LangSmithLoader(client=client) if client else LangSmithLoader(client_kwargs=kwargs)`
  4. Add a config lint that the two fields are mutually exclusive

Example fix

# before
loader = LangSmithLoader(client=my_client, client_kwargs={"api_url": url})

# after
loader = LangSmithLoader(client=my_client)
# or
loader = LangSmithLoader(client_kwargs={"api_url": url})
Defensive patterns

Strategy: validation

Validate before calling

def make_loader(*, client=None, client_kwargs=None):
    if client and client_kwargs:
        raise ValueError('pass client OR client_kwargs, not both')
    return LangSmithLoader(client=client, client_kwargs=client_kwargs or {})

Prevention

When it happens

Trigger: `LangSmithLoader(client=Client(...), client_kwargs={"api_url": ...})` — truthy `client` AND truthy `client_kwargs`; config-driven code that always fills both fields; templates that pass `client_kwargs` unconditionally and later add an explicit client.

Common situations: Copy-pasting examples that mix the two styles; defaulting `client_kwargs` to `{...}` in shared factory code while also accepting injected clients (note: empty dict `{}` is falsy and passes, non-empty does not); settings objects that populate every field.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/c6fae95d72476557. Report an issue: GitHub.