Middleware Query Skill
Implement natural-language query workflows with strict safety controls.
1) Collect required inputs
Require all connection parameters explicitly for each datasource:
hostportusernamepassword- optional:
database(MySQL/Mongo),db(Redis logical DB)
Store connection profiles in scripts/connections.json (or provide env vars) before execution.
Use scripts/connections.example.json as a template and keep real connections.json local-only (gitignored).
Prefer middleware-list config with env/alias entries, e.g. {"redis":[{"env":"local","alias":"main",...}]} and use profiles like redis.local or redis.main.
2) Enforce read-only safety
Always keep operations read-only:
- SQL:
SELECT,WITH,EXPLAIN SELECTonly - Redis:
GET,MGET,HGET,HGETALL,SMEMBERS,ZRANGE,SCAN,TTL,TYPE - Mongo:
find,count_documents,aggregatewith read-only stages
Reject write/dangerous operations.
3) Prefer deterministic executors
Use scripts under scripts/:
nl_query.py(single command entry: NL -> plan -> guard -> execute)planner_llm.py(LLM NL -> plan JSON with retry repair)plan_schema.py+references/plan-schema.json(JSON Schema validation)router_nl.py(rule-based fallback)planner_guard.py(semantic guard)execute_plan.py(validated plan execution)query_sql.pyquery_redis.pyquery_mongo.py
Pass validated parameters; never execute free-form shell commands for database access.
4) Output format
Return:
- Datasource + profile used
- Executed query/operation (sanitized)
- Row/document/key count
- Tabular/JSON preview (truncated)
- Short interpretation in Chinese
5) Configuration sources
Priority order:
- Explicit CLI args
- Env vars (see
references/config.md) scripts/connections.json
Fail with clear error if any required field is missing.
6) Reference docs
Read when needed:
references/config.md: connection and env conventionsreferences/safety-policy.md: guardrails and denylistreferences/examples.md: common command examples