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

Fix problem with sql_chain and quotation marks: normalize_sql_cmd #3385

Closed
wants to merge 10 commits into from

Conversation

PhilipMay
Copy link

@PhilipMay PhilipMay commented Apr 23, 2023

fixes #3305

@PhilipMay
Copy link
Author

PhilipMay commented Apr 23, 2023

I am not 100% sure if this locale solution (@staticmethod in SQLDatabaseChain) is the right solution.

Are there more places where this kind of normalization is needed or even implemented? Should that normalization
be on a more generic place in the code?

I do not know. Need help from maintainers here...

@PhilipMay PhilipMay changed the title [WIP] Fix problem with sql_chain and quotation marks: normalize_sql_cmd Fix problem with sql_chain and quotation marks: normalize_sql_cmd Apr 23, 2023
@PhilipMay
Copy link
Author

This is ready for review please.

@bllchmbrs
Copy link
Contributor

@PhilipMay , I hit this issue too.

One problem that might come up I believe with this implementation is the following query.

"SELECT * FROM blah_table where x='F'

I'm not sure if it's more likely that quotations aren't mirrored (e.g., starts with " ends with ') or whether it's more likely that a quotation would be omitted (like in my above example). If I read your implementation right, it remove the final ' from the query, even though it should keep it.

Not sure of the right answer here, but wanted to bring it up to make sure we're covering all the edge cases effectively.

@PhilipMay
Copy link
Author

Hi @anabranch

If I read your implementation right, it remove the final ' from the query, even though it should keep it.

That is not right. The code below sais:

"(if it starts and ends with double quotation mark) or (if it starts and ends with single quotation mark)"

If it starts with double and ends with single -> nothing will be changed. IMO that also would be incorrect SQL.

            if (
                (sql_cmd.startswith('"') and sql_cmd.endswith('"'))
                or (sql_cmd.startswith("'") and sql_cmd.endswith("'"))
            ) and (len(sql_cmd) >= 2):

Does that resolve your reservations? @anabranch

@PhilipMay
Copy link
Author

@PhilipMay
Copy link
Author

@hwchase17 can you please approve the workflows?

@PhilipMay
Copy link
Author

PhilipMay commented Apr 27, 2023

@hwchase17 can you please approve the workflows?

Thanks.

Ok. So checks are green. IMO this can be merged. :-)

@hansvdam
Copy link
Contributor

hansvdam commented May 4, 2023

I'm not sure, but to me the problem is that the prompt template is wrong in asking for an SQL-statement with quotes. I think it is better to just not do that:
#4101

@PhilipMay
Copy link
Author

I'm not sure, but to me the problem is that the prompt template is wrong in asking for an SQL-statement with quotes. I think it is better to just not do that: #4101

I agree. #4101 would be useful. But removing the quotes - just in case - would also be useful IMO.

hwchase17 pushed a commit that referenced this pull request May 13, 2023
fixes a syntax error mentioned in
#2027 and #3305
another PR to remedy is in #3385, but I believe that is not tacking the
core problem.
Also #2027 mentions a solution that works:
add to the prompt:
'The SQL query should be outputted plainly, do not surround it in quotes
or anything else.'

To me it seems strange to first ask for:

SQLQuery: "SQL Query to run"

and then to tell the LLM not to put the quotes around it. Other
templates (than the sql one) do not use quotes in their steps.
This PR changes that to:

SQLQuery: SQL Query to run
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jul 14, 2023
@leo-gan
Copy link
Collaborator

leo-gan commented Sep 13, 2023

@PhilipMay Hi , could you, please, resolve the merging issues and address the last comments (if needed)? After that, ping me and I push this PR for the review. Thanks!

If this PR is not needed anymore, could you, please, let me know?

@efriis
Copy link
Member

efriis commented Nov 7, 2023

Closing because the PR wouldn't line up with the current directory structure of the library (would need to be in /libs/langchain/langchain instead of /langchain). Feel free to reopen against the current head if it's still relevant!

@efriis efriis closed this Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with sql_chain and quotation marks
5 participants