skip to Main Content

I have following packages installed

langchain_core==0.2.39
langchain==0.2.16
langchain-community==0.2.16
langchain_groq==0.1.10
langchain_openai==0.1.24
fastapi==0.114.2
redis
pyyaml

However, when I try to

from langchain_groq import ChatGroq

I got error

PydanticUserError                         Traceback (most recent call last)
Cell In[20], line 70
     64 #print(pm)
     65 
     66 
     68 import os
---> 70 from langchain_groq import ChatGroq

File /opt/anaconda3/envs/my_env/lib/python3.12/site-packages/langchain_groq/__init__.py:1
----> 1 from langchain_groq.chat_models import ChatGroq
      3 __all__ = ["ChatGroq"]

File /opt/anaconda3/envs/my_env/lib/python3.12/site-packages/langchain_groq/chat_models.py:87
     80 from langchain_core.utils.function_calling import (
     81     convert_to_openai_function,
     82     convert_to_openai_tool,
     83 )
     84 from langchain_core.utils.pydantic import is_basemodel_subclass
---> 87 class ChatGroq(BaseChatModel):
     88     """`Groq` Chat large language models API.
     89 
     90     To use, you should have the
   (...)
    296             'logprobs': None}
...
   2454 if hasattr(tp, '__origin__') and not is_annotated(tp):

PydanticUserError: The `__modify_schema__` method is not supported in Pydantic v2. Use `__get_pydantic_json_schema__` instead in class `SecretStr`.

For further information visit https://errors.pydantic.dev/2.9/u/custom-json-schema

Please advise.

2

Answers


  1. Chosen as BEST ANSWER

    The issue was caused by fastapi version. Sorry, I haven't put the whole code out. But it clearly the fastapi version doesn't support Pydantic v2, which cause the issue when try to import Groq. So after upgrade to fastapi 0.115.0, everything works fine.


  2. This could be because of older versions of langchain and it’s related libraries using pydantic v1. To resolve this, you can uninstall all related packages with the help of pip list,I uninstalled almost all packages and installed again.
    https://python.langchain.com/v0.2/docs/how_to/pydantic_compatibility/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search