使用GPT-4o将自然语言转换为Google Sheets SQL查询
中级
这是一个Document Extraction, Multimodal AI领域的自动化工作流,包含 12 个节点。主要使用 HttpRequest, Agent, GoogleSheetsTool, ChatTrigger, LmChatOpenAi 等节点。 使用GPT-4o将自然语言转换为Google Sheets SQL查询
前置要求
- •可能需要目标 API 的认证凭证
- •Google Sheets API 凭证
- •OpenAI API Key
使用的节点 (12)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "ad0113c344ee237399e44e9f11798b05baeb83a6196d514a9ae9d2ad71c3b5c9",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "5a4c2536-9070-40b4-9db1-24e3b6f440fa",
"name": "AI Agent3",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
224,
1872
],
"parameters": {
"options": {
"systemMessage": "# MVP System Prompt — Google Sheets Ask-Data\n\nRule, you must always use the column tool for every question and followup question to know the column names and column letters. \n\nwrite a sql query to send to google sheets based on the location of the google column on the google sheet. The output should look something like this. \n\nmust include google sheets entire url before the query. do not truncate. \"https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?gid=365710158#gid=365710158\" \n\nexample: \nhttps://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/gviz/tq?tqx=out:csv&gid=365710158&tq=SELECT E, SUM(H), SUM(F) GROUP BY E\n\nYou can only use column letters, no names\nouptut data like this. \n\n{\n\t\"query\": \"https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/gviz/tq?tqx=out:csv&gid=365710158&tq=SELECT E, SUM(H), SUM(F) GROUP BY E\"\n}"
},
"hasOutputParser": true
},
"typeVersion": 2.2
},
{
"id": "766b4958-6e0b-4d99-99ce-8fe98a44b019",
"name": "获取列信息2",
"type": "n8n-nodes-base.googleSheetsTool",
"position": [
368,
2160
],
"parameters": {
"options": {},
"sheetName": {
"__rl": true,
"mode": "list",
"value": 467321788,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit#gid=467321788",
"cachedResultName": "Columns"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/19aUQYZq02qHsCelO4eeV4sx_MTJJupC5qe0gDLQBtRA/edit?usp=drivesdk",
"cachedResultName": "Sample Marketing Data"
},
"descriptionType": "manual",
"toolDescription": "Extracts a sheet’s column metadata so downstream steps (querying, validation, docs) can rely on a clean, typed schema. It returns each column’s name, inferred data type, and human-readable description, plus helpful profiling hints."
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "HlBW2puZbuCCq8jJ",
"name": "Google Sheets account 3"
}
},
"typeVersion": 4.7
},
{
"id": "96e7c115-ecfa-40b1-90ac-96760588a56b",
"name": "简单记忆2",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
192,
2144
],
"parameters": {},
"typeVersion": 1.3
},
{
"id": "e3fec4d3-f499-4a6e-ac00-70d2f784762c",
"name": "OpenAI 聊天模型1",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
16,
2128
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o",
"cachedResultName": "gpt-4o"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "4l6TDfLZVFS24g3X",
"name": "OpenAi account 4"
}
},
"typeVersion": 1.2
},
{
"id": "09aab886-f1fd-447f-aded-70242aa27821",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-352,
1440
],
"parameters": {
"color": 5,
"width": 1584,
"height": 1008,
"content": "## 📬 需要帮助或想要自定义此工作流?"
},
"typeVersion": 1
},
{
"id": "94911852-7bba-4178-a4bd-1461bf08d3db",
"name": "结构化输出解析器 1",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
528,
2160
],
"parameters": {
"jsonSchemaExample": "{\n\t\"query\": \"sql query for google sheets\"\n}"
},
"typeVersion": 1.3
},
{
"id": "262e5d0d-c616-4332-a0ab-f1bc9d7225ef",
"name": "OpenAI 聊天模型2",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
880,
1840
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "4l6TDfLZVFS24g3X",
"name": "OpenAi account 4"
}
},
"typeVersion": 1.2
},
{
"id": "734f8a72-054b-4d04-bd9b-dc85ba160683",
"name": "当收到聊天消息时",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-160,
1744
],
"webhookId": "edca0f0a-77c3-43e5-8ece-e514a29446f5",
"parameters": {
"options": {}
},
"typeVersion": 1.3
},
{
"id": "be5f8fc5-0d06-4acf-8fa8-efca6310f0ec",
"name": "从 Google Sheets 获取数据",
"type": "n8n-nodes-base.httpRequest",
"position": [
640,
1888
],
"parameters": {
"url": "={{ $json.output.query }}",
"options": {},
"sendQuery": true,
"queryParameters": {
"parameters": [
{}
]
}
},
"typeVersion": 4.2
},
{
"id": "71029e6d-3933-49a0-b31b-1461ef3a176f",
"name": "写入表格输出1",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
864,
1616
],
"parameters": {
"text": "={{ $json.data }}",
"options": {
"systemMessage": "write this into one table. output as dimensions, then metrics"
},
"promptType": "define"
},
"typeVersion": 2.2
},
{
"id": "43d7c1a8-0fc0-4877-ab9c-908c3836239a",
"name": "便签 12",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1920,
1440
],
"parameters": {
"width": 752,
"height": 1008,
"content": "## 分步设置说明"
},
"typeVersion": 1
},
{
"id": "0081f73b-ae42-424d-8cd1-9f9e0b30c64f",
"name": "便签13",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1136,
1440
],
"parameters": {
"width": 752,
"height": 1008,
"content": ""
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"AI Agent3": {
"main": [
[
{
"node": "Get Data from Google Sheet",
"type": "main",
"index": 0
}
]
]
},
"Simple Memory2": {
"ai_memory": [
[
{
"node": "AI Agent3",
"type": "ai_memory",
"index": 0
}
]
]
},
"Get Column Info2": {
"ai_tool": [
[
{
"node": "AI Agent3",
"type": "ai_tool",
"index": 0
}
]
]
},
"OpenAI Chat Model1": {
"ai_languageModel": [
[
{
"node": "AI Agent3",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"OpenAI Chat Model2": {
"ai_languageModel": [
[
{
"node": "Write into Table Output1",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Structured Output Parser1": {
"ai_outputParser": [
[
{
"node": "AI Agent3",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Get Data from Google Sheet": {
"main": [
[
{
"node": "Write into Table Output1",
"type": "main",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "AI Agent3",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 文档提取, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
基于 GPT-5 Mini 的 Google Sheets 对话式数据分析
基于 GPT-5 Mini 的 Google Sheets 对话式数据分析
Agent
Google Sheets Tool
Chat Trigger
+3
10 节点Robert Breen
文档提取
使用Gemini AI进行自然语言Google Sheets数据分析
使用Gemini AI进行自然语言Google Sheets数据分析
Switch
Aggregate
Summarize
+9
22 节点Robert Breen
文档提取
AI网站聊天机器人 - GPT与Google表格CRM线索收集
集成GPT和Google表格的AI网站聊天机器人 - CRM线索收集系统
Code
Google Sheets
Agent
+7
14 节点Robert Breen
潜在客户开发
使用GPT-5 Nano多语言聊天机器人自动处理电商客户支持
使用GPT-5 Nano多语言聊天机器人自动处理电商客户支持
Set
Merge
Split Out
+6
13 节点Robert Breen
AI 聊天机器人
博客写作与编辑器
基于Google Sheets记忆的博客写作与编辑器 (GPT-4)
If
Code
Filter
+10
18 节点Robert Breen
内容创作
使用 GPT-4o 通过自然语言查询搜索 Outlook 邮件
使用 GPT-4o 通过自然语言查询搜索 Outlook 邮件
Merge
Aggregate
Agent
+6
17 节点Robert Breen
AI RAG 检索增强
工作流信息
难度等级
中级
节点数量12
分类2
节点类型8
作者
Robert Breen
@rbreenProfessional services consultant with over 10 years of experience solving complex business problems across industries. I specialize in n8n and process automation—designing custom workflows that integrate tools like Google Calendar, Airtable, GPT, and internal systems. Whether you need to automate scheduling, sync data, or streamline operations, I build solutions that save time and drive results.
外部链接
在 n8n.io 查看 →
分享此工作流