Skip to content

Commit

Permalink
Getting SQL cmd directly from SQLDatabase Chain. (#7940)
Browse files Browse the repository at this point in the history
- Description: Get SQL Cmd directly generated by SQL-Database Chain
without executing it in the DB engine.
- Issue: #4853 
- Tag maintainer: @hinthornw,@baskaryan

---------

Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
  • Loading branch information
keenborder786 and hwchase17 committed Jul 21, 2023
1 parent 5a084e1 commit 355b7d8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions langchain/chains/sql_database/base.py
Expand Up @@ -41,6 +41,8 @@ class SQLDatabaseChain(Chain):
"""Number of results to return from the query"""
input_key: str = "query" #: :meta private:
output_key: str = "result" #: :meta private:
return_sql: bool = False
"""Will return sql-command directly without executing it"""
return_intermediate_steps: bool = False
"""Whether or not to return the intermediate steps along with the final answer."""
return_direct: bool = False
Expand Down Expand Up @@ -117,6 +119,8 @@ def _call(
callbacks=_run_manager.get_child(),
**llm_inputs,
).strip()
if self.return_sql:
return {self.output_key: sql_cmd}
if not self.use_query_checker:
_run_manager.on_text(sql_cmd, color="green", verbose=self.verbose)
intermediate_steps.append(
Expand Down

0 comments on commit 355b7d8

Please sign in to comment.