From 3e30a5d96774519f671f65d0fc57b2bedc3e08b1 Mon Sep 17 00:00:00 2001 From: Sumanth Donthula <46747610+sumanthdonthula@users.noreply.github.com> Date: Sun, 25 Jun 2023 14:04:24 -0500 Subject: [PATCH] updated sql_database.py for returning sorted table names. (#6692) Added code to get the tables info in sorted order in methods get_usable_table_names and get_table_info. Linked to Issue: #6640 --- langchain/sql_database.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/langchain/sql_database.py b/langchain/sql_database.py index 088d7374b00..5bdfd8cc565 100644 --- a/langchain/sql_database.py +++ b/langchain/sql_database.py @@ -230,8 +230,8 @@ class SQLDatabase: def get_usable_table_names(self) -> Iterable[str]: """Get names of tables available.""" if self._include_tables: - return self._include_tables - return self._all_tables - self._ignore_tables + return sorted(self._include_tables) + return sorted(self._all_tables - self._ignore_tables) def get_table_names(self) -> Iterable[str]: """Get names of tables available.""" @@ -290,6 +290,7 @@ class SQLDatabase: if has_extra_info: table_info += "*/" tables.append(table_info) + tables.sort() final_str = "\n\n".join(tables) return final_str