← 返回
未分类

bi-query

智能问数 / Text-to-SQL。连接 MySQL 数据库,将自然语言问题转换为 SQL 查询并返回智能解读。当用户问及数据库中的数据、报表、统计、业务指标、记录查询等问题时触发。Keywords: 查数据, 问数据, 数据库, 查询, SQL, 报表, 统计, 指标, 多少, 哪个, 排名, 趋势, 问数, 查表.
谷新城
未分类 community v1.0.0 1 版本 99218.8 Key: 无需
★ 0
Stars
📥 127
下载
💾 5
安装
1
版本
#latest

概述

BI Query - 智能问数

Connect to MySQL, generate SQL from natural language, execute safely, and interpret results.

Config

Database connection is configured in config.json (same directory as SKILL.md).

{
  "host": "127.0.0.1",
  "port": 3306,
  "user": "root",
  "password": "",
  "database": "",
  "default_limit": 1000,
  "query_timeout": 30
}

First run: Edit config.json with real connection info, then generate schema cache.

Workflow

Step 0: Ensure pymysql is installed

pip install pymysql

Step 1: Generate schema cache (first time or after schema changes)

python scripts/get_schema.py --mode index --output references/schema.md

This creates a lightweight table index in references/schema.md. Only re-run when database structure changes.

Step 2: Answer user questions

When a user asks a data question:

  1. Read schema index: read references/schema.md — identify which tables are relevant
  2. Get table details (on demand): python scripts/get_schema.py --mode detail --tables t1,t2 — fetch column details for relevant tables only
  3. Generate SQL: Based on table structures, write the appropriate SQL query
  4. Execute: python scripts/query_mysql.py --sql "SELECT ..."
  5. Interpret: Analyze the returned JSON and present a clear, natural-language answer

SQL Generation Guidelines

  • Always use proper table aliases for readability
  • Prefer WHERE filters to reduce data volume
  • Use appropriate aggregation (COUNT, SUM, AVG, GROUP BY) for statistical questions
  • Add ORDER BY when ranking or trending
  • Use LIMIT — the script auto-injects it, but explicit limits are better for performance
  • Handle NULL values appropriately (IFNULL, COALESCE)
  • For time-range questions, use proper date functions: DATE(created_at), YEAR(), MONTH(), etc.
  • For large tables (>1M rows), always include a WHERE clause with index-friendly conditions

Response Format

After getting query results, present:

  1. Answer: Clear natural language summary of findings
  2. Key numbers: Highlight important metrics
  3. Data table: Show results in a readable format (first 20 rows max)

重要限制:不要向用户展示生成的 SQL 语句。用户只需要自然语言的答案,不需要看到技术细节。

Error Handling

  • Connection failed: Check config.json connection info
  • Query timeout: Suggest adding more WHERE filters, or narrow the date range
  • No results: Confirm with user whether filters are correct
  • SQL error: Read the error message, fix the SQL, retry once

Security

All queries are validated server-side:

  • Only SELECT, SHOW, DESCRIBE, EXPLAIN allowed
  • INSERT, UPDATE, DELETE, DROP, etc. are blocked
  • Multiple statements (semicolons) are blocked
  • Default LIMIT 1000 applies when no explicit LIMIT is set
  • Query timeout defaults to 30 seconds

版本历史

共 1 个版本

  • v1.0.0 Initial release 当前
    2026-04-11 11:09 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 672 📥 324,427
ai-intelligence

self-improving agent

pskoett
捕获经验教训、错误和纠正,以实现持续改进。使用时机:(1)命令或操作意外失败;(2)用户纠正……
★ 4,060 📥 798,990
security-compliance

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,219 📥 266,753