Langchain SQLDatabase not fetching column names from table in Unity Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
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.

