diff --git a/llama-index-core/llama_index/core/utilities/sql_wrapper.py b/llama-index-core/llama_index/core/utilities/sql_wrapper.py index b8c8a54105301324e9d562ac02906d90b2f627fa..dbe74bdc0a5532d39c93f651e6d70d7e7e780260 100644 --- a/llama-index-core/llama_index/core/utilities/sql_wrapper.py +++ b/llama-index-core/llama_index/core/utilities/sql_wrapper.py @@ -150,10 +150,19 @@ class SQLDatabase: def get_single_table_info(self, table_name: str) -> str: """Get table info for a single table.""" # same logic as table_info, but with specific table names - template = ( - "Table '{table_name}' has columns: {columns}, " - "and foreign keys: {foreign_keys}." - ) + template = "Table '{table_name}' has columns: {columns}, " + try: + # try to retrieve table comment + table_comment = self._inspector.get_table_comment( + table_name, schema=self._schema + )["text"] + if table_comment: + template += f"with comment: ({table_comment}) " + except NotImplementedError: + # get_table_comment raises NotImplementedError for a dialect that does not support comments. + pass + + template += "and foreign keys: {foreign_keys}." columns = [] for column in self._inspector.get_columns(table_name, schema=self._schema): if column.get("comment"):