Skip to content
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

Use SQL dialect-specific prompts for SQLDatabaseChain #2748

Merged
merged 5 commits into from
Apr 14, 2023

Conversation

jzluo
Copy link
Contributor

@jzluo jzluo commented Apr 12, 2023

Mentioned the idea here initially: #2106 (comment)

Since there have been dialect-specific issues, we should use dialect-specific prompts. This way, each prompt can be separately modified to best suit each dialect as needed. This adds a prompt for each dialect supported in sqlalchemy (mssql, mysql, mariadb, postgres, oracle, sqlite). For this initial implementation, the only differencse between the prompts is the instruction for the clause to use to limit the number of rows queried for, and the instruction for wrapping column names using each dialect's identifier quote character.

@jzluo jzluo marked this pull request as ready for review April 13, 2023 01:40
input_text = f"{inputs[self.input_key]} \nSQLQuery:"
try:
prompt = self.prompt or SQL_PROMPTS[self.database.dialect]
except KeyError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer to check explicitly - but i can make this change!

@hwchase17 hwchase17 merged commit 5565f56 into langchain-ai:master Apr 14, 2023
9 checks passed
@BenSchZA BenSchZA mentioned this pull request Apr 16, 2023
hwchase17 pushed a commit that referenced this pull request Apr 18, 2023
This PR extends upon @jzluo 's PR #2748 which addressed dialect-specific
issues with SQL prompts, and adds a prompt that uses backticks for
column names when querying BigQuery. See [GoogleSQL quoted
identifiers](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_identifiers).

Additionally, the SQL agent currently uses a generic prompt. Not sure
how best to adopt the same optional dialect-specific prompts as above,
but will consider making an issue and PR for that too. See
[langchain/agents/agent_toolkits/sql/prompt.py](langchain/agents/agent_toolkits/sql/prompt.py).
@jzluo jzluo deleted the sql-dialect-prompts branch April 18, 2023 16:18
samching pushed a commit to samching/langchain that referenced this pull request May 1, 2023
)

Mentioned the idea here initially:
langchain-ai#2106 (comment)

Since there have been dialect-specific issues, we should use
dialect-specific prompts. This way, each prompt can be separately
modified to best suit each dialect as needed. This adds a prompt for
each dialect supported in sqlalchemy (mssql, mysql, mariadb, postgres,
oracle, sqlite). For this initial implementation, the only differencse
between the prompts is the instruction for the clause to use to limit
the number of rows queried for, and the instruction for wrapping column
names using each dialect's identifier quote character.
samching pushed a commit to samching/langchain that referenced this pull request May 1, 2023
This PR extends upon @jzluo 's PR langchain-ai#2748 which addressed dialect-specific
issues with SQL prompts, and adds a prompt that uses backticks for
column names when querying BigQuery. See [GoogleSQL quoted
identifiers](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_identifiers).

Additionally, the SQL agent currently uses a generic prompt. Not sure
how best to adopt the same optional dialect-specific prompts as above,
but will consider making an issue and PR for that too. See
[langchain/agents/agent_toolkits/sql/prompt.py](langchain/agents/agent_toolkits/sql/prompt.py).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants