01 / 06 資料提問Data questions

QueryLion

可自架的 PostgreSQL 自然語言資料分析 Agent

A self-hostable natural-language data analysis agent for PostgreSQL

用中文或英文提問,拿回圖表,而不是一張只能匯出的表格。

Ask in Chinese or English. Get a chart back, not just a table to export.

QueryLion icon
執行環境Runtime
Node.js ≥ 22.13 · DockerNode.js ≥ 22.13 · Docker
資料庫Database
PostgreSQL(示範用 PGlite)PostgreSQL (PGlite for the demo)
模型Models
OpenAI · Anthropic · Gemini · 相容端點OpenAI · Anthropic · Gemini · compatible
技術Built with
  • Vue 3
  • Hono
  • TypeScript
  • ECharts
  • PGlite / PostgreSQL
  • Zod

(01) 為什麼Why

資料散落在 PostgreSQL,非工程人員想查數字只能排隊等人寫 SQL;而讓 AI 直接連正式資料庫,可能誤刪資料、拖垮效能或洩漏敏感欄位。QueryLion 讓 Agent 自己探索 Schema、寫唯讀 SQL,寫入一律先給你看差異。

Data lives in PostgreSQL, and non-engineers queue for someone to write SQL — yet letting an AI loose on a production database risks deleted rows, overloaded servers and leaked columns. QueryLion lets the agent explore the schema and write read-only SQL, and every write shows you a diff first.

(02) 06 項items

它做什麼What it does

  1. 01

    唯讀 SQL,自動修正Read-only SQL that repairs itself

    Agent 探索 Schema、產生並執行唯讀 SQL,出錯時自動修正,最多 3 次。

    The agent explores the schema, generates and runs read-only SQL, and fixes its own errors up to 3 times.

  2. 02

    8 種受控圖表元件8 controlled chart components

    KPI、折線、長條、樞紐、表格、散佈、熱圖、漏斗,以 Zod 驗證;可切換圖表並匯出 CSV / PNG。

    KPI, line, bar, pivot, table, scatter, heatmap and funnel, validated with Zod — switch charts and export CSV / PNG.

  3. 03

    雙層查詢防護Two-layer query guard

    資料庫層 READ ONLY 交易與 statement_timeout;應用層以 AST 驗證只允許 SELECT / WITH、白名單資料表與函式,並遮罩敏感欄位。

    Database-level READ ONLY transactions and statement_timeout; app-level AST validation allows only SELECT / WITH, whitelisted tables and functions, and masks sensitive columns.

  4. 04

    寫入前人工核准Human approval before any write

    INSERT / UPDATE / DELETE 先 Dry-run 產生逐列差異後 ROLLBACK,以 HMAC 防篡改;超過門檻(預設 50 筆)需二次確認,全部寫入稽核日誌。

    INSERT / UPDATE / DELETE dry-run into a row-level diff, then ROLLBACK, HMAC-protected; above a threshold (50 rows by default) a second confirmation is required, and everything lands in an audit log.

  5. 05

    Schema 語意註解Schema annotations

    在介面直接編輯欄位說明,存於 querylion.config.json。

    Edit column descriptions right in the UI; they are saved to querylion.config.json.

  6. 06

    BYOK,自備模型Bring your own model

    OpenAI、Anthropic、Google Gemini 或 OpenAI 相容端點(含 Ollama)。金鑰加密存在伺服器本機,畫面只顯示遮罩。

    OpenAI, Anthropic, Google Gemini or any OpenAI-compatible endpoint (including Ollama). Keys are encrypted on your server and only ever shown masked.

(03) 怎麼運作How it works

一個問題的旅程The life of a question

  1. 01

    提問Ask

    用中文或英文輸入問題。

    Type a question in Chinese or English.

  2. 02

    探索 SchemaExplore

    Agent 讀取資料表結構與你寫的欄位註解。

    The agent reads the schema and your column notes.

  3. 03

    唯讀執行Run read-only

    AST 檢查後在唯讀交易中執行,錯誤時最多自動修正 3 次。

    AST-checked, run in a read-only transaction, auto-repaired up to 3 times.

  4. 04

    呈現Render

    從 8 種元件挑出圖表或表格。

    Picks a chart or table from 8 components.

  5. 05

    核准寫入Approve writes

    若要寫入,先看 Dry-run 差異,由人核准。

    Writes wait for you behind a dry-run diff.

(04) README

快速開始Quick start

首次啟動會以 PGlite 建立電商示範資料(50,000 筆訂單)。預設 Demo 模式只回應示範題;在「設定 → 模型與連線」貼上金鑰即可切到即時模式。

First start seeds a PGlite e-commerce demo (50,000 orders). Demo mode only answers the scripted demo questions; paste a key in Settings → Model & connection to go live.

本機(Node.js ≥ 22.13)Local (Node.js ≥ 22.13)
npm ci
npm run dev
# open http://127.0.0.1:5173
Docker ComposeDocker Compose
docker compose up --build
# open http://127.0.0.1:3001

(05) 實測Measured

真實模型實測Real-model evaluation

2026-11-02 · demo 資料集 · 自有 30 題標準題庫 · claude-haiku-5-52026-11-02 · demo dataset · own 30-question set · claude-haiku-5-5

正確率Accuracy修復後 SQL 成功SQL success after repair圖表命中Chart hit成本/題Cost / questionP50 首個 SSEP50 first SSE
96.7%100%56.7%US$0.001561.6 s

(06) 安全與權限Safety & permissions

安全與權限Safety & permissions

  • 只靠 prompt 不夠:唯讀資料庫角色 + SQL AST 檢查雙層防護。Not prompt-only: a read-only database role plus SQL AST checks.
  • 寫入預設關閉;啟用後一律 Dry-run、人工核准、寫入稽核日誌。Writes are off by default; when enabled they always dry-run, need approval and are audit-logged.
  • 可選 OIDC 登入,角色 viewer / analyst / approver,不可核准自己提出的變更。Optional OIDC with viewer / analyst / approver roles — nobody approves their own change.
  • 自架:API 金鑰與資料都留在你的環境。Self-hosted: API keys and data stay in your environment.

目前狀態Status

  • Repo 目前為私有,準備開源中。Repo currently private — coming to open source.
  • README 宣告 MIT 授權。README declares the MIT licence.

想先試用 QueryLion?Want to try QueryLion early?

所有 repo 目前都是私有的,準備開源中。想搶先試用,請透過 GitHub 個人頁聯絡。All repos are private for now and on their way to open source. To try one early, get in touch via the GitHub profile.