How to use SQL Query component #5500
Replies: 1 comment 3 replies
-
Hey there, @angelcruijff! I'm here to help you with any bugs, questions, or contributions you have. Let me know how I can assist you while you're waiting for a human maintainer. To use the SQL Query component in Langflow for your use case, you can follow these steps:
Here's a code snippet to illustrate the process: # Assuming you have already set up the necessary components and configurations
sql_generator = SQLGeneratorComponent()
sql_executor = SQLExecutorComponent()
# Input request
input_request = "Find the top 5 sales records for the last month."
# Generate SQL query
sql_query = sql_generator.build(
input_value=input_request,
db=my_database, # Your SQLDatabase instance
llm=my_language_model, # Your LanguageModel instance
top_k=5
)
# Execute the SQL query
database_url = "your_database_url_here"
query_result = sql_executor.build(
query=sql_query,
database_url=database_url,
include_columns=True, # Optional
passthrough=True, # Optional
add_error=True # Optional
)
# Pass the SQL query result to another agent for data analysis
data_analysis_agent.process(query_result) This setup allows you to generate an SQL query from a natural language request, execute it, and pass the result to another agent for further processing [1][2]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Currently, the SQL Query component under Data is in beta but I can't find examples to use it.
Is there a way to tell the agent to run a query using this component? The use case is: The agent creates a query based on the input request, I expect that the response from the agent (the query) can be use and pass it to the SQL Query component, then, the response from this component can be pass to another agent so it can analyse the data from que database response.
But the SQL Query input is expecting Text, not Message, also, the response from SQL Query is Text, and can't be use directly as input for the new agent.
Any examples or hints I can use? I'm new with langflow.
Beta Was this translation helpful? Give feedback.
All reactions