Skip to content

langchain: use langchain_core as version sentinel instead of umbrella#1656

Open
joaquinhuigomez wants to merge 1 commit into
langfuse:mainfrom
joaquinhuigomez:fix/langchain-core-version-sentinel
Open

langchain: use langchain_core as version sentinel instead of umbrella#1656
joaquinhuigomez wants to merge 1 commit into
langfuse:mainfrom
joaquinhuigomez:fix/langchain-core-version-sentinel

Conversation

@joaquinhuigomez
Copy link
Copy Markdown

@joaquinhuigomez joaquinhuigomez commented May 16, 2026

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 umbrella imports scoped inside the v0 branch where they are actually needed.

Fixes langfuse/langfuse#13651

Greptile Summary

This PR replaces langchain.__version__ with langchain_core.__version__ as the version sentinel that decides whether to use v0 or v1 LangChain imports, removing the hard dependency on the langchain umbrella package for users who only need v1 symbols (which all live in langchain_core).

  • The v1 import path (langchain_core.__version__.startswith(\"1\")) is now entirely self-contained within langchain_core, which is the correct and sufficient package for those users.
  • The v0 fallback branch still imports from the langchain umbrella, but the single except ImportError handler now emits "please install langchain-core" for any import failure — including failures from the v0 umbrella imports — giving incorrect guidance to users who already have langchain_core installed but are missing langchain.

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| F
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
langfuse/langchain/CallbackHandler.py:88-91
**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.

Reviews (1): Last reviewed commit: "langchain: use langchain_core as version..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

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
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

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'"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use langchain_core.__version__ instead of requiring the langchain umbrella package as a version sentinel in CallbackHandler

1 participant