-
Notifications
You must be signed in to change notification settings - Fork 15.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLDatabase chain having issue running queries on the database after connecting #1103
Comments
I found the same issue. It doesn't happen in 0.0.84. I still can't figure out why it's happening. |
@hwchase17 @jzluo @gocampo
|
@nanditamohan Hi, this is an issue with the prompt, not SQLAlchemy. #1242 should fix this |
hwchase17
pushed a commit
that referenced
this issue
Feb 23, 2023
…h SQL Server (#1242) The current prompt specifically instructs the LLM to use the `LIMIT` clause. This will cause issues with MS SQL Server, which uses `SELECT TOP` instead of `LIMIT`. The generated SQL will use `LIMIT`; the instruction to "always limit... using the LIMIT clause" seems to override the "create a syntactically correct mssql query to run" portion. Reported here: #1103 (comment) I don't have access to a SQL Server instance to test, but removing that part of the prompt in OpenAI Playground results in the correct `SELECT TOP` syntax, whereas keeping it in results in the `LIMIT` clause, even when instructing it to generate syntactically correct mssql. It's also still correctly using `LIMIT` in my MariaDB database. I think in this case we can assume that the model will select the appropriate method based on the dialect specified. In general, it would be nice to be able to test a suite of SQL dialects for things like dialect-specific syntax and other issues we've run into in the past, but I'm not quite sure how to best approach that yet.
zachschillaci27
pushed a commit
to zachschillaci27/langchain
that referenced
this issue
Mar 8, 2023
) langchain-ai#1081 introduced a method to get DDL (table definitions) in a manner specific to sqlite3, thus breaking compatibility with other non-sqlite3 databases. This uses the sqlite3 command if the detected dialect is sqlite, and otherwise uses the standard SQL `SHOW CREATE TABLE`. This should fix langchain-ai#1103.
zachschillaci27
pushed a commit
to zachschillaci27/langchain
that referenced
this issue
Mar 8, 2023
…h SQL Server (langchain-ai#1242) The current prompt specifically instructs the LLM to use the `LIMIT` clause. This will cause issues with MS SQL Server, which uses `SELECT TOP` instead of `LIMIT`. The generated SQL will use `LIMIT`; the instruction to "always limit... using the LIMIT clause" seems to override the "create a syntactically correct mssql query to run" portion. Reported here: langchain-ai#1103 (comment) I don't have access to a SQL Server instance to test, but removing that part of the prompt in OpenAI Playground results in the correct `SELECT TOP` syntax, whereas keeping it in results in the `LIMIT` clause, even when instructing it to generate syntactically correct mssql. It's also still correctly using `LIMIT` in my MariaDB database. I think in this case we can assume that the model will select the appropriate method based on the dialect specified. In general, it would be nice to be able to test a suite of SQL dialects for things like dialect-specific syntax and other issues we've run into in the past, but I'm not quite sure how to best approach that yet.
mikeknoop
pushed a commit
to zapier/langchain-nla-util
that referenced
this issue
Mar 9, 2023
…h SQL Server (#1242) The current prompt specifically instructs the LLM to use the `LIMIT` clause. This will cause issues with MS SQL Server, which uses `SELECT TOP` instead of `LIMIT`. The generated SQL will use `LIMIT`; the instruction to "always limit... using the LIMIT clause" seems to override the "create a syntactically correct mssql query to run" portion. Reported here: langchain-ai/langchain#1103 (comment) I don't have access to a SQL Server instance to test, but removing that part of the prompt in OpenAI Playground results in the correct `SELECT TOP` syntax, whereas keeping it in results in the `LIMIT` clause, even when instructing it to generate syntactically correct mssql. It's also still correctly using `LIMIT` in my MariaDB database. I think in this case we can assume that the model will select the appropriate method based on the dialect specified. In general, it would be nice to be able to test a suite of SQL dialects for things like dialect-specific syntax and other issues we've run into in the past, but I'm not quite sure how to best approach that yet.
ZinedineDumas
added a commit
to ZinedineDumas/React-Python
that referenced
this issue
Jul 17, 2023
…h SQL Server (#1242) The current prompt specifically instructs the LLM to use the `LIMIT` clause. This will cause issues with MS SQL Server, which uses `SELECT TOP` instead of `LIMIT`. The generated SQL will use `LIMIT`; the instruction to "always limit... using the LIMIT clause" seems to override the "create a syntactically correct mssql query to run" portion. Reported here: langchain-ai/langchain#1103 (comment) I don't have access to a SQL Server instance to test, but removing that part of the prompt in OpenAI Playground results in the correct `SELECT TOP` syntax, whereas keeping it in results in the `LIMIT` clause, even when instructing it to generate syntactically correct mssql. It's also still correctly using `LIMIT` in my MariaDB database. I think in this case we can assume that the model will select the appropriate method based on the dialect specified. In general, it would be nice to be able to test a suite of SQL dialects for things like dialect-specific syntax and other issues we've run into in the past, but I'm not quite sure how to best approach that yet.
14 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Langchain SQLDatabase and using SQL chain is giving me issues in the recent versions. My goal has been this:
Connect to a sql server (say, Azure SQL server) using mssql+pyodbc driver (also tried mssql+pymssql driver)
connection_url = URL.create( "mssql+pyodbc", query={"odbc_connect": conn} )
sql_database = SQLDatabase.from_uri(connection_url)
Use this sql_database to create a SQLSequentialChain (also tried SQLChain)
chain = SQLDatabaseSequentialChain.from_llm( llm=self.llm, database=sql_database, verbose=False, query_prompt=chain_prompt)
Query this chain
However, in the most recent version of langchain 0.0.88, I get this issue:
And in the previous version 0.0.86, I was getting this:
A few days back, this worked - but I didn't track which version that was so I have been unable to make this work. Please help look into this.
The text was updated successfully, but these errors were encountered: