-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
Conversation
I am not 100% sure if this locale solution ( Are there more places where this kind of normalization is needed or even implemented? Should that normalization I do not know. Need help from maintainers here... |
This is ready for review please. |
@PhilipMay , I hit this issue too. One problem that might come up I believe with this implementation is the following query.
I'm not sure if it's more likely that quotations aren't mirrored (e.g., starts with Not sure of the right answer here, but wanted to bring it up to make sure we're covering all the edge cases effectively. |
Hi @anabranch
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 |
@anabranch I added a test for this case: |
@hwchase17 can you please approve the workflows? |
Thanks. Ok. So checks are green. IMO this can be merged. :-) |
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: |
5a450f2
to
3381522
Compare
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
@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? |
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! |
fixes #3305