langchain
langchain copied to clipboard
SQL databasechain InvalidRequestError
System Info
langchain==0.0.164 python=3.11 system: Ubuntu
Who can help?
@eyurtsev @agola11
Information
- [X] The official example notebooks/scripts
- [ ] My own modified scripts
Related Components
- [X] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [X] Tools / Toolkits
- [X] Chains
- [X] Callbacks/Tracing
- [ ] Async
Reproduction
- pip install langchain==0.0.164
- pip install pandas
test.db is a valid data base that I can querry using sqlalchemy , "sqlite:///test.db" is a correct path to the database.
- Using chains
from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
db = SQLDatabase.from_uri("sqlite:///test.db")
llm = OpenAI(temperature=0)
db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True, return_direct=True)
db_chain("what is the average voltage in BOT table?")
- When using Agents
from langchain.agents import create_sql_agent
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
from langchain.sql_database import SQLDatabase
from langchain.llms.openai import OpenAI
from langchain.agents import AgentExecutor
db = SQLDatabase.from_uri("sqlite:///test.db")
toolkit = SQLDatabaseToolkit(db=db)
agent_executor = create_sql_agent(
llm=OpenAI(temperature=0),
toolkit=toolkit,
verbose=True
)
agent_executor.run("what is the average voltage in BOT table?")
Expected behavior
Error Message when using sqlchain:
`> Entering new SQLDatabaseChain chain... what is the average voltage in BOT table? SQLQuery: Output exceeds the size limit. Open the full output data in a text editor--------------------------------------------------------------------------- InvalidRequestError Traceback (most recent call last) Cell In[5], line 2 1 db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True, return_direct=True) ----> 2 db_chain("what is the average voltage in BOT table?")
File ~/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/base.py:140, in Chain.call(self, inputs, return_only_outputs, callbacks) 138 except (KeyboardInterrupt, Exception) as e: 139 run_manager.on_chain_error(e) --> 140 raise e 141 run_manager.on_chain_end(outputs) 142 return self.prep_outputs(inputs, outputs, return_only_outputs)
File ~/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/base.py:134, in Chain.call(self, inputs, return_only_outputs, callbacks) 128 run_manager = callback_manager.on_chain_start( 129 {"name": self.class.name}, 130 inputs, 131 ) 132 try: 133 outputs = ( --> 134 self._call(inputs, run_manager=run_manager) 135 if new_arg_supported 136 else self._call(inputs) 137 ) 138 except (KeyboardInterrupt, Exception) as e: ... 688 rbody, rcode, resp.data, rheaders, stream_error=stream_error 689 ) 690 return resp
InvalidRequestError: Invalid URL (POST /completions)`
Error message when using agents
Error: `
ValidationError Traceback (most recent call last) Cell In[9], line 2 1 db = SQLDatabase.from_uri("sqlite:///test.db") ----> 2 toolkit = SQLDatabaseToolkit(db=db) 4 agent_executor = create_sql_agent( 5 llm=OpenAI(temperature=0), 6 toolkit=toolkit, 7 verbose=True 8 ) 9 agent_executor.run("what is the average voltage in BOT table?")
File ~/anaconda3/envs/langchain/lib/python3.11/site-packages/pydantic/main.py:341, in pydantic.main.BaseModel.init()
ValidationError: 1 validation error for SQLDatabaseToolkit llm field required (type=value_error.missing)
`
The SQLDatabaseToolkit
signature has apparently been updated since the documentation; it is now required to pass in llm
as well. Change your code to:
llm = OpenAI(temperature=0)
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
agent_executor = create_sql_agent(
llm=OpenAI(temperature=0),
toolkit=toolkit,
verbose=True
)
Followed your instruction, still the same error.
`db = SQLDatabase.from_uri("sqlite:///test.db") llm = OpenAI(temperature=0) toolkit = SQLDatabaseToolkit(db=db, llm= llm)
agent_executor = create_sql_agent( llm=llm, toolkit=toolkit, verbose=True ) agent_executor.run("what is the average voltage in BOT table?")`
error:
`> Entering new AgentExecutor chain... Output exceeds the size limit. Open the full output data in a text editor--------------------------------------------------------------------------- InvalidRequestError Traceback (most recent call last) Cell In[14], line 10 3 toolkit = SQLDatabaseToolkit(db=db, llm= llm) 5 agent_executor = create_sql_agent( 6 llm=llm, 7 toolkit=toolkit, 8 verbose=True 9 ) ---> 10 agent_executor.run("what is the average voltage in BOT table?")
File ~/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/base.py:236, in Chain.run(self, callbacks, *args, **kwargs)
234 if len(args) != 1:
235 raise ValueError("run
supports only one positional argument.")
--> 236 return self(args[0], callbacks=callbacks)[self.output_keys[0]]
238 if kwargs and not args:
239 return self(kwargs, callbacks=callbacks)[self.output_keys[0]]
File ~/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/base.py:140, in Chain.call(self, inputs, return_only_outputs, callbacks) 138 except (KeyboardInterrupt, Exception) as e: 139 run_manager.on_chain_error(e) --> 140 raise e 141 run_manager.on_chain_end(outputs) 142 return self.prep_outputs(inputs, outputs, return_only_outputs) ... 688 rbody, rcode, resp.data, rheaders, stream_error=stream_error 689 ) 690 return resp
InvalidRequestError: Invalid URL (POST /completions)`
same issue here man.how to solve it?
same error
+1
Worked for me...
Hi, @sahand68. I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
Based on the information provided, it seems that the issue you reported is related to the SQL databasechain in the langchain library. The error messages indicate issues with the URL and a missing field. wpride suggested updating the code to include llm
as a required parameter in the SQLDatabaseToolkit
signature. However, it seems that even after following the instructions, you and other users are still encountering the same error.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your understanding and contribution to the LangChain project. If you have any further questions or concerns, please don't hesitate to reach out.
Hi,
My issue is resolved by updating to the current version.
Best, Sahand,
On Fri, Sep 15, 2023, 9:05 AM dosu-beta[bot] @.***> wrote:
Hi, @sahand68 https://github.com/sahand68. I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
Based on the information provided, it seems that the issue you reported is related to the SQL databasechain in the langchain library. The error messages indicate issues with the URL and a missing field. wpride suggested updating the code to include llm as a required parameter in the SQLDatabaseToolkit signature. However, it seems that even after following the instructions, you and other users are still encountering the same error.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you for your understanding and contribution to the LangChain project. If you have any further questions or concerns, please don't hesitate to reach out.
— Reply to this email directly, view it on GitHub https://github.com/langchain-ai/langchain/issues/4469#issuecomment-1721519765, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJRG4YT7QSVIYF46XQTJPT3X2R4EHANCNFSM6AAAAAAX5CYATI . You are receiving this because you were mentioned.Message ID: @.***>
Thank you for letting us know, @sahand68! We're glad to hear that your issue has been resolved by updating to the current version. We'll go ahead and close this issue now. If you have any more questions or need further assistance, feel free to reach out.
#error: ValidationError: 1 validation error for SQLDatabaseToolkit Getting same issue , in my case issue is not getting resolved , is it because i am using gemini or different model from OpenAI, even i have followed all the recomendations from the chat , but still it is same, how to resolve the same issue using gemini pro model? genai.configure(api_key='my Api key') model = genai.GenerativeModel(model_name='gemini-pro') #llm = OpenAI(temperature=0) mydb = SQLDatabase.from_uri('sqlite:///test.db')
llm = {'model': model} toolkit=SQLDatabaseToolkit(db=mydb) agent_executer = create_sql_agent( llm=llm, toolkit=toolkit, handle_parsing_error=True, verbose=True )