Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PydanticUserError: ConversationSummaryBufferMemory is not fully defined; you should define BaseCache, then call ConversationSummaryBufferMemory.model_rebuild(). #28257

Open
5 tasks done
LeadsiftAI opened this issue Nov 21, 2024 · 6 comments
Assignees
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate

Comments

@LeadsiftAI
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain.memory import ConversationSummaryBufferMemory

memory = ConversationSummaryBufferMemory(
    llm=chat,
    input_key="input",
    output_key="output",
    max_token_limit=1024,
    memory_key="chat_history",
)

Error Message and Stack Trace (if applicable)

{
"name": "PydanticUserError",
"message": "ConversationSummaryBufferMemory is not fully defined; you should define BaseCache, then call ConversationSummaryBufferMemory.model_rebuild().

For further information visit https://errors.pydantic.dev/2.10/u/class-not-fully-defined",
"stack": "---------------------------------------------------------------------------
PydanticUserError Traceback (most recent call last)
Cell In[45], line 3
1 from langchain.memory import ConversationSummaryBufferMemory
----> 3 memory = ConversationSummaryBufferMemory(
4 llm=chat,
5 input_key="input",
6 output_key="output",
7 max_token_limit=1024,
8 memory_key="chat_history",
9 )

File c:\xxxx\site-packages\langchain_core\_api\deprecation.py:216, in deprecated..deprecate..finalize..warn_if_direct_instance(self, *args, **kwargs)
214 warned = True
215 emit_warning()
--> 216 return wrapped(self, *args, **kwargs)

File xxxx\site-packages\langchain_core\_api\deprecation.py:216, in deprecated..deprecate..finalize..warn_if_direct_instance(self, *args, **kwargs)
214 warned = True
215 emit_warning()
--> 216 return wrapped(self, *args, **kwargs)

File xxxx\site-packages\langchain_core\_api\deprecation.py:216, in deprecated..deprecate..finalize..warn_if_direct_instance(self, *args, **kwargs)
214 warned = True
215 emit_warning()
--> 216 return wrapped(self, *args, **kwargs)

File xxxx\site-packages\langchain_core\load\serializable.py:125, in Serializable.init(self, *args, **kwargs)
123 def init(self, *args: Any, **kwargs: Any) -> None:
124 """"""
--> 125 super().init(*args, **kwargs)

File xxxx\site-packages\langchain_core\_api\deprecation.py:216, in deprecated..deprecate..finalize..warn_if_direct_instance(self, *args, **kwargs)
214 warned = True
215 emit_warning()
--> 216 return wrapped(self, *args, **kwargs)

[... skipping hidden 1 frame]

File xxxx\site-packages\pydantic\_internal\_mock_val_ser.py:100, in MockValSer.getattr(self, item)
98 # raise an AttributeError if item doesn't exist
99 getattr(self._val_or_ser, item)
--> 100 raise PydanticUserError(self._error_message, code=self._code)

PydanticUserError: ConversationSummaryBufferMemory is not fully defined; you should define BaseCache, then call ConversationSummaryBufferMemory.model_rebuild().

For further information visit https://errors.pydantic.dev/2.10/u/class-not-fully-defined"
}

Description

I've upgrade my project's langchain package to latest, and when i create ConversationSummaryBufferMemory, encountered the PydanticUserError

System Info

System Information

OS: Windows
OS Version: 10.0.22631
Python Version: 3.11.10 | packaged by Anaconda, Inc. | (main, Oct 3 2024, 07:22:26) [MSC v.1929 64 bit (AMD64)]

Package Information

langchain_core: 0.3.19
langchain: 0.3.7
langchain_community: 0.3.7
langsmith: 0.1.144
langchain_openai: 0.2.9
langchain_text_splitters: 0.3.2

Optional packages not installed

langgraph
langserve

Other Dependencies

aiohttp: 3.11.6
async-timeout: Installed. No version info available.
dataclasses-json: 0.6.7
httpx: 0.27.2
httpx-sse: 0.4.0
jsonpatch: 1.33
numpy: 1.26.4
openai: 1.55.0
orjson: 3.10.11
packaging: 24.2
pydantic: 2.10.0
pydantic-settings: 2.6.1
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.35
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.12.2

@langcarl langcarl bot added the investigate label Nov 21, 2024
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Nov 21, 2024
@miguelrgonzalez
Copy link

miguelrgonzalez commented Nov 21, 2024

I had the same issue, but in my case the error was raised when instantiating a custom Retriever.
The underlying issue is with the pydantic-settings version 2.6.1.
Downgrading fixed the problem for me.

"pydantic-core==2.23.4",
"pydantic-settings==2.6.0",

@LeadsiftAI
Copy link
Author

I had the same issue, but in my case the error was raised when instantiating a custom Retriever. The underlying issue is with the pydantic-settings version 2.6.1. Downgrading fixed the problem for me.

"pydantic-core==2.23.4",
"pydantic-settings==2.6.0",

@miguelrgonzalez thanks, i've downgrade my project's pydantic version to 2.9.2 and fixed

@eyurtsev eyurtsev self-assigned this Nov 21, 2024
@coolbeevip
Copy link
Contributor

same issue

"pydantic==2.10.1",
"pydantic_core==2.27.1",
"pydantic-settings==2.6.0",

@ahmed33033
Copy link

I got a similar issue as well, but with SQLDatabaseToolkit.

If you're using poetry, I simply changed my pydantic dependency to: pydantic = "2.9.2", and I ran the following command:

> poetry update

Updating dependencies
Resolving dependencies... (7.3s)

Package operations: 0 installs, 2 updates, 0 removals

  - Downgrading pydantic-core (2.27.1 -> 2.23.4)
  - Downgrading pydantic (2.10.1 -> 2.9.2)

@kuangdai
Copy link

Same here.

pydantic 2.10.0
pydantic_core 2.27.0
pydantic-settings 2.6.1

@thecodemancer
Copy link

Same here:

pydantic==2.9.2
    # via
    #   google-cloud-aiplatform
    #   google-generativeai
    #   langchain
    #   langchain-core
    #   langchain-google-genai
    #   langsmith
    #   openai
    #   pydantic-settings
pydantic-core==2.23.4
    # via pydantic
pydantic-settings==2.6.1
    # via langchain-community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate
Projects
None yet
Development

No branches or pull requests

7 participants