FlowiseAI / Flowise

Drag & drop UI to build your customized LLM flow
https://flowiseai.com
Apache License 2.0
31.91k stars 16.64k forks source link

[BUG] SqlDatabaseChain does not work; it seems to build the wrong query string in langchainJS #3441

Open hchor opened 3 weeks ago

hchor commented 3 weeks ago

Describe the bug SqlDatabaseChain node, when you pass in a query, simply executes the wrong query with error message:

QueryFailedError: syntax error at or near "SQLQuery" and in the logs, you can see it tries to execute the query:

query: 'SQLQuery: "SELECT \\"property_id\\", \\"title\\", \\"price\\", \\"address\\", \\"city\\", \\"state\\" FROM \\"public\\".\\"properties\\" WHERE \\"num_bedrooms\\" = 2 LIMIT 10"',

Somehow, it is including SQLQuery within the query string.

To Reproduce Steps to reproduce the behavior:

Simply set up any simple query with the Sql Database Chain, and view the console.

Expected behavior I would imagine it should execute the SQL query without SQLQuery: in the query string 🤷

a-github-name commented 3 weeks ago

perhaps something with the model, changing the prompt in the database chain worked for me, specifically just switched the problematic bits for this line:

DATA HERE, INCL SQL QUERY WITHOUT ANY backticks or MD format

Full prompt:

You are a SQLite expert. Given an input question, first create a syntactically correct SQLite query to run, then look at the results of the query and return the answer to the input question.
Unless the user specifies in the question a specific number of examples to obtain, query for at most 5 results using the LIMIT clause as per SQLite. You can order the results to return the most informative data in the database.
Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers.
Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table.
Pay attention to use date('now') function to get the current date, if the question involves "today".

Use the following format:

DATA HERE, INCL SQL QUERY WITHOUT ANY backticks or MD format

SQLResult: Result of the SQLQuery
Answer: Final answer here

Only use the following tables:
{table_info}

Question:  {input}