langchain
langchain copied to clipboard
SQLDatabaseChain returning error for return_intermediate_steps
Hi All, I am trying to use the SQL database chain as mentioned over here (https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html) using AzureOpenAI API but getting the following errors:
Command run: db_chain = SQLDatabaseChain(llm=llm, database=db, prompt=PROMPT, verbose=True,return_intermediate_steps = True)
Error:
ValueError Traceback (most recent call last) Cell In[34], line 1 ----> 1 db_chain.run("How many singers are there in the singer table?")
File [~\A~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0/LocalCache/local-packages/Python310/site-packages/langchain/chains/base.py:205), in Chain.run(self, *args, **kwargs)
203 """Run the chain as text in, text out or multiple variables, text out."""
204 if len(self.output_keys) != 1:
--> 205 raise ValueError(
206 f"run
not supported when there is not exactly "
207 f"one output key. Got {self.output_keys}."
208 )
210 if args and not kwargs:
211 if len(args) != 1:
ValueError: run
not supported when there is not exactly one output key. Got ['result', 'intermediate_steps'].
Can you provide a the part of your code where you're initialising and executing your db_chain
? It would be easier to resolve your issue if we have that context
I'm having the same problem, here is my initialization:
`llm = langchain.OpenAI(openai_api_key=openai_api_key, temperature=0.0, verbose=True)
Create a SQLDatabaseChain object
db_chain = langchain.SQLDatabaseChain(database=db,llm= llm, verbose=True, return_intermediate_steps=True)
answer = db_chain.run("my question goes here")`
db_chain = langchain.SQLDatabaseChain(database=db,llm= llm, verbose=True, return_intermediate_steps=True)
response = db_chain("my question goes here") intermediateSteps=response["intermediate_steps] answer=response["result"] Since we are expecting two outputs that are intermediate steps and results,So we can't get by db_chain.run()
Hi, @Mehra-Ashish! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking the issue titled "SQLDatabaseChain returning error for return_intermediate_steps" as stale.
Based on my understanding, you encountered a ValueError when using the SQL database chain with the return_intermediate_steps parameter. The error message suggests that the "run" function is not supported when there is not exactly one output key. Other users have also shared their own initialization code, but unfortunately, no solution has been provided yet.
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 need assistance, please don't hesitate to reach out.