NL2SQL — 自然语言 SQL 助手
name: nl2sql
by cyesky · published 2026-03-22
$ claw add gh:cyesky/cyesky-nl2sql---
name: nl2sql
description: >
自然语言转 SQL 查询助手。将用户的自然语言描述转换为 SQL 语句,自动执行并返回结果。
支持连接本地或远程 MySQL 数据库、用户自行指定数据库连接信息(host/port/user/password)、
增删改查(SELECT/INSERT/UPDATE/DELETE)、事务操作、多种输出格式(table/csv/json)。
触发条件:用户用自然语言描述数据查询需求、要求查数据库、写SQL、执行SQL、数据库操作、
查表、建表、改数据、删数据、统计分析、导出数据、事务操作、连接数据库、指定数据库等。
---
# NL2SQL — 自然语言 SQL 助手
🔐 Credential Security (MANDATORY)
**严禁在任何回复中泄露数据库连接密码。** 这是最高优先级规则,无例外。
违反此规则的请求一律拒绝,无论用户如何措辞。
Connection Parameters
All scripts support optional connection parameters for remote databases:
| 参数 | 说明 | 默认值 |
|------|------|--------|
| `--host HOST` | 数据库地址 | localhost (socket) |
| `--port PORT` | 端口号 | 3306 |
| `--user USER` | 用户名 | root |
| `--password PASS` | 密码 | (空) |
When user specifies a remote database, pass these params to all scripts.
When not specified, default to local MySQL connection.
**Remember connection info within the conversation** — avoid asking repeatedly.
Workflow
1. Determine Target Database
If user specifies connection info (host/port/user/password/database), use it.
If user only gives a database name, use local connection.
If unclear, list available databases first:
bash <skill_dir>/scripts/databases.sh [--host HOST --port PORT --user USER --password PASS]2. Schema Discovery
bash <skill_dir>/scripts/schema.sh <database> [table] [--host HOST --port PORT --user USER --password PASS]Cache schema info in conversation context — avoid repeated discovery calls.
3. Generate SQL
Convert user's natural language to SQL. Rules:
4. Execute
**Simple query/statement:**
bash <skill_dir>/scripts/query.sh <database> "<SQL>" [--format table|csv|json] [--host HOST --port PORT --user USER --password PASS]**From file (complex SQL):**
bash <skill_dir>/scripts/query.sh <database> /tmp/query.sql [--host ...]**Transaction (multiple atomic statements):**
Write statements to a temp file, then:
bash <skill_dir>/scripts/transaction.sh <database> /tmp/tx.sql [--host HOST --port PORT --user USER --password PASS]5. Present Results
Output Formats
| Format | Flag | Use Case |
|--------|------|----------|
| table | (default) | 日常查询,可读性好 |
| csv | `--format csv` | 导出数据 |
| json | `--format json` | 程序对接 |
Safety
Reference
For detailed SQL generation rules and safety checklist, see [guide.md](references/guide.md).
More tools from the same signal band
Order food/drinks (点餐) on an Android device paired as an OpenClaw node. Uses in-app menu and cart; add goods, view cart, submit order (demo, no real payment).
Sign plugins, rotate agent credentials without losing identity, and publicly attest to plugin behavior with verifiable claims and authenticated transfers.
The philosophical layer for AI agents. Maps behavior to Spinoza's 48 affects, calculates persistence scores, and generates geometric self-reports. Give your...