{"record":{"id":"c6fae95d72476557","repo":"langchain-ai/langchain","slug":"received-both-client-and-client-kwargs-pass","errorCode":null,"errorMessage":"Received both `client` and `client_kwargs`. Pass `client_kwargs` only when `client` is not provided.","messagePattern":"Received both `client` and `client_kwargs`\\. Pass `client_kwargs` only when `client` is not provided\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/document_loaders/langsmith.py","lineNumber":101,"sourceCode":"            limit: The maximum number of examples to return.\n            metadata: Metadata to filter by.\n            filter: A structured filter string to apply to the examples.\n            client: LangSmith Client.\n\n                If not provided will be initialized from below args.\n            client_kwargs: Keyword args to pass to LangSmith client init.\n\n                Should only be specified if `client` isn't.\n\n        Raises:\n            ValueError: If both `client` and `client_kwargs` are provided.\n        \"\"\"  # noqa: E501\n        if client and client_kwargs:\n            msg = (\n                \"Received both `client` and `client_kwargs`. \"\n                \"Pass `client_kwargs` only when `client` is not provided.\"\n            )\n            raise ValueError(msg)\n        self._client = client or LangSmithClient(**client_kwargs)\n        self.content_key = list(content_key.split(\".\")) if content_key else []\n        self.format_content = format_content or _stringify\n        self.dataset_id = dataset_id\n        self.dataset_name = dataset_name\n        self.example_ids = example_ids\n        self.as_of = as_of\n        self.splits = splits\n        self.inline_s3_urls = inline_s3_urls\n        self.offset = offset\n        self.limit = limit\n        self.metadata = metadata\n        self.filter = filter\n\n    @override\n    def lazy_load(self) -> Iterator[Document]:\n        for example in self._client.list_examples(\n            dataset_id=self.dataset_id,","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/document_loaders/langsmith.py#L83-L119","documentation":"`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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["If you have a client, drop `client_kwargs` entirely","If you only have connection settings, omit `client` and let kwargs build it","In factories, normalize: `LangSmithLoader(client=client) if client else LangSmithLoader(client_kwargs=kwargs)`","Add a config lint that the two fields are mutually exclusive"],"exampleFix":"# before\nloader = LangSmithLoader(client=my_client, client_kwargs={\"api_url\": url})\n\n# after\nloader = LangSmithLoader(client=my_client)\n# or\nloader = LangSmithLoader(client_kwargs={\"api_url\": url})","handlingStrategy":"validation","validationCode":"def make_loader(*, client=None, client_kwargs=None):\n    if client and client_kwargs:\n        raise ValueError('pass client OR client_kwargs, not both')\n    return LangSmithLoader(client=client, client_kwargs=client_kwargs or {})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make the two parameters mutually exclusive in your own config schema","Default client_kwargs to None (or {}) — never a pre-filled dict merged with an injected client","Unit-test the factory rejects both-supplied input"],"tags":["langsmith","document-loader","constructor","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}