From 0758da894063c188540b46ea3554e60d3be292ed Mon Sep 17 00:00:00 2001 From: Yuki Oshima <39944763+os1ma@users.noreply.github.com> Date: Sun, 14 Apr 2024 07:58:47 +0900 Subject: [PATCH] community[patch]: Set default value for _ListSQLDatabaseToolInput tool_input (#20409) **Description:** `_ListSQLDatabaseToolInput` raise error if model returns `{}`. For example, gpt-4-turbo returns `{}` with SQL Agent initialized by `create_sql_agent`. So, I set default value `""` for `_ListSQLDatabaseToolInput` tool_input. This is actually a gpt-4-turbo issue, not a LangChain issue, but I thought it would be helpful to set a default value `""`. This problem is discussed in detail in the following Issue. **Issue:** https://github.com/langchain-ai/langchain/issues/20405 **Dependencies:** none Sorry, I did not add or change the test code, as tests for this components was not exist . However, I have tested the following code based on the [SQL Agent Document](https://python.langchain.com/docs/use_cases/sql/agents/), to make sure it works. ``` from langchain_community.agent_toolkits.sql.base import create_sql_agent from langchain_community.utilities.sql_database import SQLDatabase from langchain_openai import ChatOpenAI db = SQLDatabase.from_uri("sqlite:///Chinook.db") llm = ChatOpenAI(model="gpt-4-turbo", temperature=0) agent_executor = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True) result = agent_executor.invoke("List the total sales per country. Which country's customers spent the most?") print(result["output"]) ``` --- libs/community/langchain_community/tools/sql_database/tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/community/langchain_community/tools/sql_database/tool.py b/libs/community/langchain_community/tools/sql_database/tool.py index 2981f09eae..fa055a5a14 100644 --- a/libs/community/langchain_community/tools/sql_database/tool.py +++ b/libs/community/langchain_community/tools/sql_database/tool.py @@ -79,7 +79,7 @@ class InfoSQLDatabaseTool(BaseSQLDatabaseTool, BaseTool): class _ListSQLDataBaseToolInput(BaseModel): - tool_input: str = Field(..., description="An empty string") + tool_input: str = Field("", description="An empty string") class ListSQLDatabaseTool(BaseSQLDatabaseTool, BaseTool):