Reading Huge Database Tables Using LangChain

Hi All,

I am working on one solution where requirement is to create SQL queries from natural language using gpt-turbo-3.5 LLM. During this I am connecting AdventureWorks2017 database which has 60+ tables and tables are categorized based on the schemas.

I am using LangChain SqlDatabse to connect to my SQL Server databse. during this process we need to prepare the prompt with the databse tables and columns for generating SQL queries.
SQLDatabse module fetches tables which are under the dbo schema only and not fetching other tables under different schemas. While looking the code I see LanhChain SQLDatabse module is wrapper on the SQLDatabaseAlchemy. SQLDatabaseAlchemy support only single schema, there is no way to fetch tables under different schemas available in database.

Please suggest me how can I read all the tables from database under all the schemas. Down is the database snap shot.
image

1 Like

Hey! I am facing a similar issue. its fetching the tables under dbo schema only.

Have you found any solution?

1 Like

We had a similar challenge and have created a schemas property that accepts multiple schemas to be used with SQL server. You can refer to the code base here,

https://github.com/langchain-ai/langchain/issues/3036#issuecomment-1602004448

db = SQLDatabase.from_uri(sqlconn,schemas=["dbo","person","humanresources"])

1 Like