Email assistant: convert natural language to SQL queries with Phi4-mini and PostgreSQL
Needs changesWhat this workflow does
This AI workflow has 23 nodes and runs manually, when you click “Execute workflow” (plus 2 other triggers). Along the way it connects Postgres and Ollama Chat Model.
How it runs
Trigger: Manually, when you click “Execute workflow” (plus 2 other triggers).
- List all tables in a database (Postgres): run a query
- Load the schema from the local file (Read/Write Files from Disk): reads a file from disk
- List all columns in a table (Postgres): run a query
- If: checks a condition and branches into true / false
- Add table name to output (Edit Fields (Set)): sets 1 field: table
- Extract data from file (Extract from File): extracts data from a file (from json)
- Convert data to binary (Convert to File): converts data to a file (to json)
- Combine schema data and chat input (Edit Fields (Set)): sets 4 fields: sessionId, action, chatinput…
- Save file locally (Read/Write Files from Disk): writes a file to disk
- AI Agent: runs an AI agent, with model: Ollama Chat Model
…plus 9 more steps. See the full node list below.
Services it uses
Before you upgrade to n8n 3.0
1 thing in this workflow is removed in n8n 3.0. Fix it before you upgrade:
- AI Agent v1 (old agent modes) in AI Agent (v1.8): replace with Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent.
Rather not rewrite it? Many of these flows can be rebuilt in Make (free plan).
| Removed in 3.0 | Replace with |
|---|---|
| AI Agent v1 (old agent modes) AI Agent (v1.8) | Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent. |
Nodes used (12)
- Edit Fields (Set)
n8n-nodes-base.set - Convert to File
n8n-nodes-base.convertToFile - Read/Write Files from Disk
n8n-nodes-base.readWriteFile - Extract from File
n8n-nodes-base.extractFromFile - Chat Trigger
@n8n/n8n-nodes-langchain.chatTrigger - Manual Trigger
n8n-nodes-base.manualTrigger - If
n8n-nodes-base.if - Merge
n8n-nodes-base.merge - Postgres
n8n-nodes-base.postgres - Ollama Chat Model
@n8n/n8n-nodes-langchain.lmChatOllama - Execute Workflow Trigger
n8n-nodes-base.executeWorkflowTrigger - AI Agent
@n8n/n8n-nodes-langchain.agent
From the author
Who is this for? 🧑🏻🫱🏻🫲🏻🤖 Humans and Robots alike. This workflow can be used as a Chat Trigger, as well as a Workflow Trigger. It will take a natural language request, and then generate a SQL query. The resulting query parameter will contain the query,…