DatabaseError (databricks.sql.exc.DatabaseError) Invalid SessionHandle in LangChain SQL chain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 02:43 AM
When creating a SQL Chatbot with LangChain SQLDatabase chain, Databricks database, and OpenAI model, I got a "Invalid SessionHandle" Error.
Code of creating the SQL Chain:
<code>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 04:41 AM
I have tried the solutions. But they don't work.
When i tried :
from pyspark.sql import SparkSession
from databricks import sql
def get_db(_=None):
db = SQLDatabase.from_databricks(...)
spark = SparkSession.builder.appName("NewSession").getOrCreate()
sql_context = sql.Context(spark.sparkContext)
sql_context.sessionState().newSession()
return db
It returned : AttributeError: module 'databricks.sql' has no attribute 'Context'.
When I tried :
def get_chain():
global db
if db is None or not db.is_valid():
db = get_db()
chain = SQLDatabaseChain.from_llm(llm=llm, db=db, verbose=True)
return chain
It returned: AttributeError: 'SQLDatabase' object has no attribute 'is_valid'.

