Skip to content

SQL query execution is not working with QuerySQLDataBaseTool #23625

Answered by dosubot bot
kj4483 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, @kj4483! I'm here to assist you with any bugs, questions, or contributions. Let's tackle this issue together!

The error you're encountering is due to the SQL query being wrapped in triple backticks, which is not valid SQL syntax. To resolve this issue, you need to ensure that the query generated by the LLM does not include these backticks. Here’s how you can modify your code to handle this:

  1. Modify the QuerySQLDataBaseTool class to clean up the query:
    You can create a custom tool that extends QuerySQLDataBaseTool and overrides the _run method to clean up the query before execution.
from langchain_community.tools.sql_database.tool import QuerySQLDataBaseTool

class CustomQuerySQLD…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@dosubot
Comment options

@Pipasgonzalez
Comment options

@kj4483
Comment options

@dosubot
Comment options

@mdbellini
Comment options

Answer selected by kj4483
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Pipasgonzalez
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants