langchain-ai / langchain

šŸ¦œšŸ”— Build context-aware reasoning applications
https://python.langchain.com
MIT License
95.19k stars 15.44k forks source link

PydanticUserError: `SQLDatabaseToolkit` is not fully defined; you should define `BaseCache`, then call `SQLDatabaseToolkit.model_rebuild()`. #28284

Open yadav-shivani opened 7 hours ago

yadav-shivani commented 7 hours ago

Checked other resources

Example Code

from langchain_community.agent_toolkits.sql.toolkit import SQLDatabaseToolkit
from langchain_community.utilities.sql_database import SQLDatabase
from langchain_openai import ChatOpenAI
from langchain_community.agent_toolkits import create_sql_agent

db = SQLDatabase.from_uri("sqlite:///Chinook.db")
llm = llm_chat()# LLM of your choice

# Initialize your SQLDatabaseToolkit
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
agent_executor = create_sql_agent(llm_chat(), toolkit=toolkit,max_iterations=11,verbose=True,handle_parsing_errors=True)

Error Message and Stack Trace (if applicable)

image

Description

  1. I am trying to build a sql agent which can query over tabular data using create_sql_agent and SQLDatabaseToolkit from Langchain.
  2. My code was working fine till day before. Since yesterday SQLDatabasetoolkit function is throwing error.
  3. I will use the build agent to query database but right now cannot even built the toolkit. I am new to this, not sure where to make changes. I believe it is something related to update.

Any help is highly appreciated :)

System Info

System Information

OS: Linux OS Version: #1 SMP Tue Oct 22 16:38:23 UTC 2024 Python Version: 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0]

Package Information

langchain_core: 0.3.19 langchain: 0.3.7 langchain_community: 0.3.7 langsmith: 0.1.144 langchain_aws: 0.2.7 langchain_text_splitters: 0.3.2

Optional packages not installed

langgraph langserve

Other Dependencies

aiohttp: 3.11.7 async-timeout: Installed. No version info available. boto3: 1.34.131 dataclasses-json: 0.6.7 httpx: 0.27.0 httpx-sse: 0.4.0 jsonpatch: 1.33 numpy: 1.26.4 orjson: 3.10.11 packaging: 23.2 pydantic: 2.10.1 pydantic-settings: 2.6.1 PyYAML: 6.0.1 requests: 2.31.0 requests-toolbelt: 1.0.0 SQLAlchemy: 2.0.31 tenacity: 8.4.1 typing-extensions: 4.12.2

ksteimel commented 40 minutes ago

I had a similar issue and downgrading pydantic to 2.9.2 resolved it for me.

ahmed33033 commented 30 minutes ago

28257 mentions a very similar issue!