cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Machine Learning
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

port undefined error in SQLDatabase.from_databricks (langchain.sql_database)

Octavian1
Contributor

The following assignment:

from langchain.sql_database import SQLDatabase

dbase = SQLDatabase.from_databricks(
catalog=catalog,
schema=db,
host=host,
api_token=token,
)

fails with 

ValueError: invalid literal for int() with base 10: ''
because of
cls._assert_port(port),
in /lib/python3.10/site-packages/sqlalchemy/engine/url.py:211, in URL.create(cls, drivername, username, password, host, port, database, query)
as shown in the error trace.
 
Couldn't find any information regarding this (for instance, in the example given in: https://docs.gcp.databricks.com/en/large-language-models/langchain.html)
 
The token and host are OK. Also the catalog and schema have correct values.
 
Using langchain==0.1.5.

 

2 REPLIES 2

Kaniz
Community Manager
Community Manager

Hi @Octavian1Ensure that the port parameter youโ€™re passing to SQLDatabase.from_databricks is a valid integer. If itโ€™s empty or contains non-numeric characters, that could be the root cause.

  • In a Stack Overflow post, someone faced a similar issue while connecting SQLAlchemy (SQLDatabaseChain from langchain) to SingleStoreDB. They provided a workaround using a custom connection URL. 
  • Hereโ€™s an example snippet:
    from sqlalchemy import create_engine
    engine = create_engine(CONNECTION_URL)
    db = SQLDatabase(engine)
    
    You might need to adapt this approach to your specific use case1.
  • Ensure that your langchain version (0.1.5) is compatible with your environment and dependencies. Sometimes, upgrading to a newer version might resolve issues.
  • If you encounter any other issues, feel free to ask!

Hi @Kaniz 

You may be right regarding SQLAlchemy, the trace hints at something related:

> /lib/python3.10/site-packages/langchain_community/utilities/sql_database.py", line 133, in from_uri

> """Construct a SQLAlchemy engine from URI."""

But I don't get why in the SQLDatabase.from_databricks documentation there is no mention of any port parameter, neither in the example notebooks?

Thanks,

Octavian

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.