amaan784
New Contributor II

Following up on @Walter_C insights, I encountered the same issue and wanted to share the complete steps I took to fully resolve the issue:

1) Upgrade SQLAlchemy: Running the following command before any other code resolved the sqlalchemy.types error:

 

%pip install --upgrade sqlalchemy

2) Address LangChain Deprecation Warning: I received a deprecation warning for the OpenAI class in LangChain:


"LangChainDeprecationWarning
: The class `OpenAI` was deprecated in LangChain 0.0.10 and will be removed in 0.3.0. An updated version of the class exists in the langchain-openai package."

To resolve this:

  • I replaced: 

 

from langchain import OpenAI

 

with: 

 

from langchain_openai import OpenAI

 

  • Before this definitely install the necessary packages again, this time including langchain-openai:

 

%pip install --upgrade langchain databricks-sql-connector sqlalchemy langchain-openai

 

3) Update Method Call: I switched from using chain.run to chain.invoke as the run method was deprecated:

 

agent.invoke("What is the longest trip distance and how long did it take?")

 

I’ve uploaded the complete updated code to my GitHub. You can check it out here: Databricks Text to SQL using Langchain.ipynb 

After making these updates, everything worked smoothly. Hope this helps!