Skip to content
FlowHubFluxonLab
A
AI Automationfree

Email Assistant: Convert Natural Language to SQL Queries with Phi4-mini and PostgreSQL

by Alfonso Correttiadapted from n8n official workflow galleryUpdated Aug 2026
RequiresAAI AgentOllama Chat ModelOllama Chat ModelPostgresPostgres
Share Post Share
SeAdd table name to outputAdd table name …CTConvert data to binaryConvert data to…RWSave file locallySave file local…EFExtract data from fileExtract data fr…ChChat TriggerMaWhen clicking "Test workflow"When clicking "…SeCombine schema data and chat inputCombine schema …RWLoad the schema from the local fileLoad the schema…SeExtract SQL queryExtract SQL que…IfCheck if query existsCheck if query …SeFormat query resultsFormat query re…MeCombine query result and chat answerCombine query r…List all columns in a tableList all column…List all tables in a databaseList all tables…Ollama Chat ModelOllama Chat Mod…PostgresSeAdd trailing semicolonAdd trailing se…IfCheck for trailing semicolonCheck for trail…EWWorkflowTriggerIfIf ran manuallyIfIf file exists or already retried generating itIf file exists …AgAI AgentSeFormat empty outputFormat empty ou…12345678910111213141516171819202122232425
1/5
STEPS · 25
Starts from a chat message

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, and a sqloutput parameter will contain the results of executing such query. What's the use case? This template is most useful paired with other workflows that extract e-mail information and store it in a structured Postgres table, and use LLMs to understand inquiries about information contained in an e-mail inbox and formulate questions that needs answering. Plus, the prompt can be easily adapted to formulate SQL queries over any kind of structured database. Privacy and Economics As LLM provider I'm using Ollama locally, as I consider my e-mail extremely sensitive information. As model, phi4-mini does an excellent job balancing quality and efficiency. Setup Upon running for the first time, this workflow will automatically trigger a sub-section to read all tables and extract their schema into a local file.

Tags

n8nreference-onlyagentlm-chat-ollamapostgres
Connects
AAI AgentollamachatmodelOllama Chat ModelpostgresPostgres
CategoryAI Automation
Triggermanual
Complexityadvanced
Nodes23
AddedApr 27, 2025

Related workflows

See all AI Automation
ABCD
free

Run AI employee onboarding with Groq, Google Workspace, and Gemini

Quick overview This workflow ingests onboarding documents from Google Drive into an in-memory vector store with Google Gemini embeddings, then runs a multi-channel onboarding chatbot powered by Groq, sends role-based welcome emails via Gmail when a new hire appears in Google Sheets, and schedules day 1/7/30 check-in emails. How it works Manually runs an ingestion flow that lists files in a specified Google Drive folder, downloads them, extracts text, and indexes them into an in-memory vector store using Google Gemini embeddings. Receives employee questions via n8n Chat (and optionally Slack or Telegram), normalizes the message into a single format, and rejects empty or overly long inputs. Uses a Groq LLM agent with per-user session memory to retrieve relevant excerpts from the in-memory company_docs knowledge base and generate a grounded answer, or directs the user to HR when no relevant content is found. Routes the assistant’s response back to the originating channel (n8n Chat, and optionally Slack or Telegram). Triggers every minute on updates to a Google Sheets “Hires” sheet, validates rows marked as Hired, and skips hires already present in the “Tracking” sheet. Builds a depart

by Yash Kabra
Agmailopenaichatmodeltextclassifier
free

Suggest meeting slots using AI

The purpose of this n8n workflow is to automate the process of identifying incoming Gmail emails that are requesting an appointment, evaluating their content, checking calendar availability, and then composing and sending a response email. Note that to use this template, you need to be on n8n version 1.19.4 or later.

by n8n Team
AopenaichatmodelserpapigooglesearchS
free

AI agent chat

This workflow employs OpenAI's language models and SerpAPI to create a responsive, intelligent conversational agent. It comes equipped with manual chat triggers and memory buffer capabilities to ensure seamless interactions. To use this template, you need to be on n8n version 1.50.0 or later.

by n8n Team