talk to your sqlite database with a langchain ai agent
Configured with Agent, Chat Trigger, Execute Workflow, Execute Workflow Trigger, and additional nodes. Review the connections and setup before adapting this template.
Node categories in this workflow
- AI & models
- Subworkflow
- Trigger
- Web / API
- Transform
- Data store
Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.
Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.
How it works
The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.
| Node | Category | Type | Operation |
|---|---|---|---|
| OpenAI Chat Model | AI & models | OpenAI Chat Model | See node parameters |
| Execute Workflow | Subworkflow | Execute Workflow | See node parameters |
| Execute "Generate a chart" tool | Trigger | Execute Workflow Trigger | See node parameters |
| OpenAI - Generate Chart definition with Structured Output | Web / API | HTTP Request | POST |
| Set response | Transform | Edit Fields | See node parameters |
| When chat message received | Trigger | Chat Trigger | See node parameters |
| Set Text output | Transform | Edit Fields | See node parameters |
| Set Text + Chart output | Transform | Edit Fields | See node parameters |
| AI Agent | AI & models | Agent | See node parameters |
| Window Buffer Memory | Data store | Memory Buffer Window | See node parameters |
| OpenAI Chat Model Classifier | AI & models | OpenAI Chat Model | See node parameters |
| Text Classifier - Chart required? | AI & models | Text Classifier | See node parameters |
| User question + Agent initial response | Transform | Edit Fields | See node parameters |
| Information Extractor - User question | AI & models | Information Extractor | See node parameters |
Setup
- Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
- Connect your own credentials through n8n’s credential store. Replace
REPLACE_WITH_*values with your resource identifiers. - Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
- Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.
Requirements
An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.
Credential types declared in the source
openAiApipostgres
Workflow notes
Overview
Overview
- This workflow aims to provide data visualization capabilities to a native SQL Agent.
- Together, they can help foster data analysis and data visualization within a team.
- It uses the native SQL Agent that works well and adds visualization capabilities thanks to OpenAI’s Structured Output and Quickchart.io.
How it works
- Information Extraction:
- The Information Extractor identifies and extracts the user's question.
- If the question includes a visualization aspect, the SQL Agent alone may not respond accurately.
- SQL Querying:
- It leverages a regular SQL Agent: it connects to a database, queries it, and translates the response into a human-readable format.
- Chart Decision:
- The Text Classifier determines whether the user would benefit from a chart to support the SQL Agent's response.
- Chart Generation:
- If a chart is needed, the sub-workflow dynamically generates a chart and appends it to the SQL Agent’s response.
- If not, the SQL Agent’s response is output as is.
- Calling OpenAI for Chart Definition:
- The sub-workflow calls OpenAI via the HTTP Request node to retrieve a chart definition.
- Building and Returning the Chart:
- In the "Set Response" node, the chart definition is appended to a Quickchart.io URL, generating the final chart image.
- The AI Agent returns the response along with the chart.
How to use it
- Use an existing database or create a new one.
- For example, I've used this Kaggle dataset and uploaded it to a Supabase DB.
- Add the PostgreSQL or MySQL credentials.
- Alternatively, you can use SQLite binary files (check this template).
- Activate the workflow.
- Start chatting with the AI SQL Agent.
- If the Text Classifier determines a chart would be useful, it will generate one in addition to the SQL Agent's response.
Notes
- The full Quickchart.io specifications have not been fully integrated, so there may be some glitches (e.g., radar graphs may not display properly due to size limitations).
Generate a Quickchart definition
Generate a Quickchart definition
HTTP Request node
- Send the chart query to OpenAI, with a defined JSON response format - using HTTP Request node as it has not yet been implemented in the OpenAI nodes
- The JSON structure is based on ChartJS and Quickchart.io definitions, that let us create nice looking graphs.
- The output is a JSON containing the chart definition that is passed to the next node.
Set Response node
- Adds the chart definition at the end of a Quickchart.io URL (see documentation)
- Note that in the parameters, we specify the width to 250 in order to be properly displayed in the chart interface.
Information Extractor
Information Extractor
- This Information Extractor is added to extract the user's question
- In some cases, if the question contains a visualization aspect, the SQL Agent may not responding accurately.
SQL Agent
- This SQL Agent is connected to a Database.
- It queries the Database for each user message.
- In this example, the prompt has been slightly changed to address an issue with querying a Supabase DB. Feel free to change the
Prefix Promptto suit your needs. - This example uses the data from this Kaggle dataset
Respond with a text only or also include a chart
Respond with a text only or also include a chart
- The text classifier determines if the response from the SQL Agent would benefit from a chart
- If it does, then it executes the subworkflow to dynamically generate a chart, and append the chart to the response from the SQL Agent
- If it doesn't, then the SQL Agent response is directly outputted.
Demo
Demo
talk to your sqlite database with a langchain ai agent
talk to your sqlite database with a langchain ai agent
Purpose and structure
This folder contains the talk to your sqlite database with a langchain ai agent workflow. Its executable nodes use agent, chatTrigger, executeWorkflow, executeWorkflowTrigger, httpRequest, informationExtractor, lmChatOpenAi, memoryBufferWindow, set, textClassifier. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.
Setup
Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.
Entry points
Execute "Generate a chart" tool, When chat message received
Verification
Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.
Attribution
https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Http/0636_HTTP_Stickynote_Create_Webhook.json MIT; preserve source notices.