langchain: AttributeError: module 'langchain' has no attribute 'verbose'

System Info

langchain==0.0.157

Who can help?

No response

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

When I try to run llm = OpenAI(temperature=0)

AttributeError                            Traceback (most recent call last)
Cell In[11], line 1
----> 1 llm = OpenAI(temperature=0)
      3 # Initialize a ConversationBufferMemory object to store the chat history
      4 memory = ConversationBufferMemory(memory_key="chat_history") 

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/pydantic/main.py:339, in pydantic.main.BaseModel.__init__()

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/pydantic/main.py:1066, in pydantic.main.validate_model()

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/pydantic/fields.py:439, in pydantic.fields.ModelField.get_default()

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/langchain/llms/base.py:26, in _get_verbosity()
     25 def _get_verbosity() -> bool:
---> 26     return langchain.verbose

AttributeError: module 'langchain' has no attribute 'verbose'

Expected behavior

Don’t get the error

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 6
  • Comments: 18

Most upvoted comments

This issue seems to have resurfaced in version 0.0.234 of langchain. The suggested solution in the issue works only temporarily, meaning the issue popped up after some time again.

Some kind of race condition bug?

Seems to be fixable by explicitly

import langchain
langchain.verbose = False

before trying to initialize llm.

I also faced this issue. In my case it was my folder structure messing with the imports. I had a folder called langchain within my project. After I renamed it it worked fine.

Just in case someone gets this error now, the only thing that worked for me was updating langchain’s version. In my case I’m using poetry as my package manager and did:

poetry update langchain

If you’re using pip just use:

pip install --upgrade langchain

I tried using the langchain.verbose = False workaround that was mentioned here but it ended up triggering the same error later.