SQL Agent table name error while taking actions #17945
Replies: 3 comments 5 replies
-
🤖 Hey there @TheLancelot! 😄 Great to see you diving into the depths of LangChain again. How's everything going on your end? Based on the information you've provided and the similar issues I found in the LangChain repository, it seems like the problem might be related to how the table names are being processed. In a similar issue #7457, the problem was that the single quotes around table names in the Example Input of from langchain.agents.agent_toolkits.sql.toolkit import SQLDatabaseToolkit
from langchain.tools import BaseTool
from langchain.tools.sql_database.tool import (
InfoSQLDatabaseTool,
ListSQLDatabaseTool,
QuerySQLCheckerTool,
QuerySQLDataBaseTool,
)
class CustomSQLDatabaseToolkit(SQLDatabaseToolkit):
def get_tools(self) -> list[BaseTool]:
list_tables_tool = ListSQLDatabaseTool(db=self.db)
table_schema_tool_description = (
"Use this tool to get the schema of specific tables. "
"Input to this tool is a comma-separated list of tables, output is the "
"schema and sample rows for those tables. "
"Be sure that the tables actually exist by calling "
f"{list_tables_tool.name} first! "
"Example Input: table1, table2, table3" # NOTE: removed the single quotes here
)
table_schema_tool = InfoSQLDatabaseTool(
db=self.db,
description=table_schema_tool_description,
)
# ... rest of the toolkit setup ...
return [
list_tables_tool,
table_schema_tool,
# ... other tools ...
] In another similar issue #12458, the solution was to modify the def get_schema(_):
table_info = db.get_table_info()
for table in table_info:
if table['name'] == 'table_products':
table['name'] = 'products'
elif table['name'] == 'table_cocktails':
table['name'] = 'cocktails'
return table_info Please try these solutions and let me know if they solve your problem. If not, could you provide more information about your database schema and the exact error message you're getting? This will help me better understand the issue and find a solution. Sources
|
Beta Was this translation helpful? Give feedback.
-
@TheLancelot, did you fix this issue? |
Beta Was this translation helpful? Give feedback.
-
Has anyone found a solution for this that works on 8b models? To have the model dictate a new line issue or single quote issue seems like an enormous amount of overhead to parse a small piece of code:
The Observation portion of the system prompt has a newline in it possibly and is confusing both Meta/Llama3 8b and Hermes/Llama 8b. It shouldn't take a 70b model to do this right? |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am using the Langchain SQL agent to answer queries about an sql database. The database has only one table called as pollution_data and in the question I am asking the agent to describe the table.
On running, the agent stops due to iteration limit.
As seen in the verbose, highlighted in the backticks below
this error keeps repeating until iteration limit, the problem obviously is it is considering \nObservation to be a part of the database tablename even if it knows the actual table name in the previous iteration
How do i fix this?
System Info
Package Information
Beta Was this translation helpful? Give feedback.
All reactions