cancel
Showing results for 
Search instead for 
Did you mean: 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results for 
Search instead for 
Did you mean: 

Langchain SQLDatabase not fetching column names from table in Unity Catalog

ericy
New Contributor

I am building a text-to-sql agent using Langchain API.

I created a SQLDatabase using:

 

db = SQLDatabase.from_databricks(catalog="`my-catalog-name`", schema="my_schema", host="...", api_token="...", warehouse_id="12345678")

When I call db.get_table_info() I get the following error:

sqlalchemy.exc.DatabaseError: (databricks.sql.exc.ServerOperationError) [UNRESOLVED_COLUMN.WITHOUT_SUGGESTION] A column, variable, or function parameter with name `FROM` cannot be resolved. SQLSTATE: 42703; line 2 pos 0
[SQL: SELECT
FROM my_table
LIMIT %(param_1)s]
[parameters: {'param_1': 3}]
(Background on this error at: https://sqlalche.me/e/14/4xp6)

Stepping through the code I found that SQLDatabase is not fetching the table columns. However, if I execute the following command using a connection from db._engine.connect(), I can retrieve the table column definitions:

schema_query = """
SELECT
table_name,
column_name,
data_type
FROM `my-catalog-name`.information_schema.columns
WHERE table_schema = 'my_schema'
ORDER BY table_name, ordinal_position
"""

Not sure what I am missing.

Any help would be greatly appreciated.

0 REPLIES 0

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now