npx skills add https://github.com/oimiragieo/agent-studio --skill text-to-sql模式:认知/提示驱动 — 无独立实用脚本;需通过智能体上下文使用。
文本转 SQL - 利用数据库模式上下文和查询模式,将自然语言查询转换为 SQL。
使用时机 :
如何调用 :
"生成 SQL 以查找过去一个月内注册的所有用户"
"创建一个查询来计算各产品的总收入"
"编写 SQL 以查找重复记录"
功能说明 :
模式集成 :
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
查询优化 :
安全性 :
文本转 SQL 使用来自 database-architect 的模式:
文本转 SQL 为开发者生成查询:
用户:"查找过去一个月内注册的所有用户"
文本转 SQL:
1. 分析查询
2. 参考 users 表模式
3. 生成 SQL:
SELECT * FROM users
WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
4. 返回参数化查询
用户:"计算第四季度各产品的总收入"
文本转 SQL:
1. 分析查询
2. 参考 orders 和 products 表
3. 生成 SQL:
SELECT p.name, SUM(o.total) as revenue
FROM orders o
JOIN products p ON o.product_id = p.id
WHERE o.created_at >= '2024-10-01'
AND o.created_at < '2025-01-01'
GROUP BY p.id, p.name
4. 返回优化后的查询
基于 Claude Cookbooks 模式,文本转 SQL 评估包括:
语法验证 :
功能测试 :
Promptfoo 集成 :
评估配置 : 为您的评估设置创建一个 promptfoo 配置文件(例如,text_to_sql_config.yaml)。
# 运行文本转 SQL 评估(需先创建配置)
npx promptfoo@latest eval -c text_to_sql_config.yaml
始终包含完整的数据库模式:
提供类似查询的示例:
对于复杂查询,使用思维链推理:
使用 RAG 检索相关的模式信息:
LIMIT 子句(默认 100),除非用户明确覆盖| 反模式 | 失败原因 | 正确方法 |
|---|---|---|
| 对值使用字符串插值 | SQL 注入漏洞 | 使用带有 ? 或 $N 占位符的参数化查询 |
| SELECT 查询没有 LIMIT 子句 | 返回所有行,存在内存溢出和超时风险 | 默认 LIMIT 100,需要用户明确覆盖 |
| 未经确认执行破坏性 SQL | 不可逆的数据丢失 | 将 DROP/DELETE/TRUNCATE 置于用户确认之后 |
| 没有模式验证 | 引用不存在的表或列 | 根据提供的模式验证所有标识符 |
| 使用 SELECT * 而不指定列列表 | 结果不可预测且浪费性能 | 始终指定明确的列列表 |
开始前: 阅读 .claude/context/memory/learnings.md
完成后:
.claude/context/memory/learnings.md.claude/context/memory/issues.md.claude/context/memory/decisions.md每周安装数
89
代码仓库
GitHub 星标数
19
首次出现
2026年1月27日
安全审计
安装于
github-copilot85
opencode85
codex84
gemini-cli84
cursor84
kimi-cli81
Mode: Cognitive/Prompt-Driven — No standalone utility script; use via agent context.
Text-to-SQL - Converts natural language queries to SQL using database schema context and query patterns.
When to Use :
How to Invoke :
"Generate SQL to find all users who signed up in the last month"
"Create a query to calculate total revenue by product"
"Write SQL to find duplicate records"
What It Does :
Schema Integration :
Query Optimization :
Safety :
Text-to-SQL uses schema from database-architect:
Text-to-SQL generates queries for developers:
User: "Find all users who signed up in the last month"
Text-to-SQL:
1. Analyzes query
2. References users table schema
3. Generates SQL:
SELECT * FROM users
WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
4. Returns parameterized query
User: "Calculate total revenue by product for Q4"
Text-to-SQL:
1. Analyzes query
2. References orders and products tables
3. Generates SQL:
SELECT p.name, SUM(o.total) as revenue
FROM orders o
JOIN products p ON o.product_id = p.id
WHERE o.created_at >= '2024-10-01'
AND o.created_at < '2025-01-01'
GROUP BY p.id, p.name
4. Returns optimized query
Based on Claude Cookbooks patterns, text-to-SQL evaluation includes:
Syntax Validation :
Functional Testing :
Promptfoo Integration :
Evaluation Configuration : Create a promptfoo config file for your evaluation setup (e.g., text_to_sql_config.yaml).
# Run text-to-SQL evaluation (create config first)
npx promptfoo@latest eval -c text_to_sql_config.yaml
Always include complete database schema:
Provide examples of similar queries:
For complex queries, use chain-of-thought reasoning:
Use RAG to retrieve relevant schema information:
LIMIT clause (default 100) to SELECT queries unless the user explicitly overrides it| Anti-Pattern | Why It Fails | Correct Approach |
|---|---|---|
| String interpolation for values | SQL injection vulnerability | Use parameterized queries with ? or $N placeholders |
| No LIMIT clause on SELECT | Returns all rows, risk of OOM and timeout | Default LIMIT 100, require explicit user override |
| Destructive SQL without confirmation | Irreversible data loss | Gate DROP/DELETE/TRUNCATE behind user confirmation |
| No schema validation | References non-existent tables or columns | Validate all identifiers against the provided schema |
| SELECT * without column list | Unpredictable results and performance waste | Always specify an explicit column list |
Before starting: Read .claude/context/memory/learnings.md
After completing:
.claude/context/memory/learnings.md.claude/context/memory/issues.md.claude/context/memory/decisions.mdWeekly Installs
89
Repository
GitHub Stars
19
First Seen
Jan 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
github-copilot85
opencode85
codex84
gemini-cli84
cursor84
kimi-cli81
AI 代码实施计划编写技能 | 自动化开发任务分解与 TDD 流程规划工具
50,900 周安装