langchain: use langchain_core as version sentinel instead of umbrella#1656
Open
joaquinhuigomez wants to merge 1 commit into
Open
langchain: use langchain_core as version sentinel instead of umbrella#1656joaquinhuigomez wants to merge 1 commit into
joaquinhuigomez wants to merge 1 commit into
Conversation
CallbackHandler imported the langchain umbrella package purely to read langchain.__version__ and pick the v1 vs v0 branch. The v1 branch then does all of its imports from langchain_core, never touching the umbrella. Anyone using LangGraph or any langchain-* provider package already pulls langchain_core as a transitive dependency, so requiring the umbrella here forced an unnecessary install on v1 users. Switch the sentinel to langchain_core.__version__ and keep the langchain umbrella imports scoped inside the v0 branch where they are actually needed. The ModuleNotFoundError message is updated to match. Fixes langfuse/langfuse#13651
Comment on lines
88
to
91
| except ImportError: | ||
| raise ModuleNotFoundError( | ||
| "Please install langchain to use the Langfuse langchain integration: 'pip install langchain'" | ||
| "Please install langchain_core to use the Langfuse langchain integration: 'pip install langchain-core'" | ||
| ) |
Contributor
There was a problem hiding this comment.
Misleading error message when
langchain umbrella is missing on the v0 path
A user who has langchain_core 0.x installed (e.g. via LangGraph) but does not have the langchain umbrella will enter the v0 branch and immediately hit an ImportError on from langchain.callbacks.base import .... That error is caught here and re-raised telling them pip install langchain-core — but langchain-core is already present. The real fix is pip install langchain. This is exactly the class of user the PR description says will benefit from this change, so they are particularly likely to hit it on a 0.x core install.
Prompt To Fix With AI
This is a comment left during a code review.
Path: langfuse/langchain/CallbackHandler.py
Line: 88-91
Comment:
**Misleading error message when `langchain` umbrella is missing on the v0 path**
A user who has `langchain_core` 0.x installed (e.g. via LangGraph) but does not have the `langchain` umbrella will enter the v0 branch and immediately hit an `ImportError` on `from langchain.callbacks.base import ...`. That error is caught here and re-raised telling them `pip install langchain-core` — but `langchain-core` is already present. The real fix is `pip install langchain`. This is exactly the class of user the PR description says will benefit from this change, so they are particularly likely to hit it on a 0.x core install.
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CallbackHandlerimported thelangchainumbrella package purely to readlangchain.__version__and pick the v1 vs v0 branch. The v1 branch then does all of its imports fromlangchain_core, never touching the umbrella. Anyone using LangGraph or anylangchain-*provider package already pullslangchain_coreas a transitive dependency, so requiring the umbrella here forced an unnecessary install on v1 users.Switch the sentinel to
langchain_core.__version__and keep the umbrella imports scoped inside the v0 branch where they are actually needed.Fixes langfuse/langfuse#13651
Greptile Summary
This PR replaces
langchain.__version__withlangchain_core.__version__as the version sentinel that decides whether to use v0 or v1 LangChain imports, removing the hard dependency on thelangchainumbrella package for users who only need v1 symbols (which all live inlangchain_core).langchain_core.__version__.startswith(\"1\")) is now entirely self-contained withinlangchain_core, which is the correct and sufficient package for those users.langchainumbrella, but the singleexcept ImportErrorhandler now emits "please install langchain-core" for any import failure — including failures from the v0 umbrella imports — giving incorrect guidance to users who already havelangchain_coreinstalled but are missinglangchain.Confidence Score: 3/5
Safe for v1 users, but the generic catch-all error handler now gives wrong installation advice to v0 users who have langchain_core without the langchain umbrella.
The v1 happy path is correct and the motivation is sound. The catch block, however, now misleads v0 users: if langchain_core is present but the langchain umbrella is not, the ImportError from the v0 branch is caught and tells the user to reinstall the package they already have, rather than pointing them to the actual missing package.
langfuse/langchain/CallbackHandler.py — specifically the shared except ImportError block that catches errors from both the sentinel import and the v0-branch umbrella imports.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[import langchain_core] -->|ImportError| E["raise ModuleNotFoundError\n'pip install langchain-core'"] A -->|success| B{"langchain_core.__version__\n.startswith('1')?"} B -->|True - v1 path| C["Import all symbols\nfrom langchain_core.*"] B -->|False - v0 path| D["Import from langchain.* umbrella\n+ langchain_core.*"] D -->|ImportError - langchain umbrella missing| E2["raise ModuleNotFoundError\n'pip install langchain-core'\n(wrong: langchain_core is already present)"] C --> F[Handler available] D -->|success| FPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "langchain: use langchain_core as version..." | Re-trigger Greptile