langchain: Issue: Supabase python client pydantic dependency mismatch

Issue you’d like to raise.

When using supabase client I get dependency errors, which I believe originate from the pydantic library

Supabase uses requires pydantic<3.0,>=2.1.0 Langchain requires (I guess) 1.10.12

With langchain compatible pydantic versions, supabase errors out.

from supabase.client import Client, create_client
supabase_url = os.environ.get("SUPABASE_URL")
supabase_key = os.environ.get("SUPABASE_SERVICE_KEY")
supabase: Client = create_client(supabase_url, supabase_key)
ImportError: cannot import name 'field_validator' from 'pydantic' 

But if I upgrade pydantic, langchain starts erroring out.

from langchain.vectorstores.pgvector import PGVector
PydanticUserError: If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`. Note that `@root_validator` is deprecated and should be replaced with `@model_validator`.

Is there any quick fix for this?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 15

Most upvoted comments

Answer generated by a 🤖

Answer

Hello,

Thank you for bringing this to our attention. It seems like there’s a conflict between the versions of Pydantic required by LangChain and the Supabase Python client.

As a workaround, you can use separate virtual environments for each project to isolate their dependencies. This way, each project can use its own version of the Pydantic library without causing conflicts. Here’s how you can do it:

  1. Create a new virtual environment for each project:
python3 -m venv langchain_env
python3 -m venv supabase_env
  1. Activate the virtual environment:
# For LangChain
source langchain_env/bin/activate

# For Supabase
source supabase_env/bin/activate
  1. Install the dependencies in the activated environment:
# For LangChain
pip install -r langchain_requirements.txt

# For Supabase
pip install -r supabase_requirements.txt

Remember to replace langchain_requirements.txt and supabase_requirements.txt with the actual paths to your requirements files.

By using separate virtual environments, you can manage dependencies for each project independently, thus avoiding conflicts between different versions of the same library.

This solution was also suggested in a similar issue: Issue: Can not import the Langchain modules.

As for the exact version of Pydantic that LangChain is currently compatible with, I wasn’t able to find this information in the repository. It’s possible that this information is available elsewhere or I may have missed it.

I hope this helps! If you have any other questions or need further clarification, feel free to ask.

Best, Dosu

Sources


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Answer generated by a 🤖

Answer

Hello,

I understand the issue you’re facing with the dependency conflict between LangChain and the Supabase Python client. I found a similar issue in the LangChain repository (Issue: Can not import the Langchain modules.) which might be related to your problem.

As for your question, one way to resolve this conflict without using separate virtual environments is to use the poetry add command with the -E option to specify a version of Pydantic that is compatible with both LangChain and Supabase. In your case, you can try specifying Pydantic version 2.1.0. Here is the command you can use:

poetry add pydantic@2.1.0

This command will update the pyproject.toml file and the poetry.lock file to use Pydantic version 2.1.0.

However, this solution assumes that LangChain is compatible with Pydantic version 2.1.0. I wasn’t able to find a definitive answer within the repository regarding LangChain’s compatibility with Pydantic version 2.1.0. If LangChain is not compatible with Pydantic version 2.1.0, you may need to consider other solutions such as using docker containers to isolate the dependencies of LangChain and Supabase.

Please try this solution and let me know if it works for you or if you need further assistance.

Sources


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Hi all! As of langchain==0.0.267 the pydantic version is uncapped and we should largely be cross-compatible with pydantic v1 and v2. There are still some known pydantic v2 failure modes explained in https://github.com/langchain-ai/langchain/discussions/9337, and some potentially unknown failure modes.

We’d love to hear if the latest version unblocks your use cases or if you’re still running into issues!

cc @Srajangpt1 @rahulnyk @moazvolga

I managed to get it work as well, with older langchain and supabase versions. Successfully integrated supabase db with langchain chatbot. Here’s my requirements.txt as well. The key is to use: supabase==1.0.0 ,langchain==0.0.202, httpx==0.23.3, pydantic==1.10.9.

requirements.txt

@eyurtsev @baskaryan would it be possible to update on this issue. This is literally making impossible to use langchain. Unless we bump the version of pydantic.

@rahulnyk we’re taking a look at how to handle this