$cd ../use-cases/
πΎ Developerv1.4+8 min setup
$ cat sql-natural-language.md
SQL Natural Language Interface
/** Bridge the gap between human curiosity and structured data. OpenClaw converts natural language into production-grade SQL with native schema awareness and safety guardrails. */
schema_sentinel.log
Schema Awareness & Safety First
OpenClaw doesn't just 'guess' SQL. It performs a deep scan of your database metadata (DDL), understanding foreign keys, constraints, and column types. Most importantly, it operates under a 'Security-First' model: read-only by default, PII masking for sensitive fields, and built-in SQL injection prevention using prepared statements and LLM-based verification.
query_pipeline.md
βοΈ Query Pipeline
1
Metadata Discovery
OpenClaw introspects schemas for PostgreSQL, MySQL, and BigQuery without reading row data.
2
Semantic Mapping
Maps user intent to specific table columns using RAG-enhanced schema context.
3
SQL Synthesis & Verification
Generates ANSI-standard SQL and validates it against a local linter before execution.
4
Multimodal Visualization
Automatically renders result sets as interactive tables, bar charts, or CSV exports.
database_pool.json
βοΈ Database Connection Config
{
"provider": "postgresql",
"connection": "postgres://readonly:***@prod-db:5432/analytics",
"security": {
"enforce_read_only": true,
"pii_masking": ["email", "phone"]
}
}
π‘# π‘ Pro Tip: Use 'postgres-read-only' role to ensure AI can never modify your production data.
example_queries.sql
π¬ Production-Grade Examples
QUERY:
"Calculate churn rate for Pro users in Q3"
OUTPUT:
WITH churn AS (SELECT user_id FROM subs WHERE status='expired'...) SELECT count(*) / (SELECT count(*) FROM users)...
QUERY:
"Find overlapping appointments for Room 202"
OUTPUT:
SELECT t1.id, t2.id FROM appts t1 JOIN appts t2 ON t1.room=t2.room AND t1.start < t2.end...
π Extended Workflows
β FAQ
Q1. Can it accidentally modify my production database?
No. OpenClaw operates in read-only mode by default. Even if the LLM generates a destructive query, the execution layer rejects it. Use a 'postgres-read-only' role for extra safety.
Q2. Which databases are supported?
PostgreSQL, MySQL, and Google BigQuery out of the box. Additional connectors (MSSQL, SQLite, Oracle) can be added via config. The schema introspection engine adapts to each dialect.
Q3. Does it handle complex queries like JOINs and CTEs?
Yes. The LLM understands foreign keys and table relationships from DDL metadata. It generates JOINs, CTEs, window functions, and subqueries when needed.
Q4. Is my data sent to the cloud?
Only the schema metadata AND the generated SQL are processed. Row-level data stays local. With local LLMs via Ollama, nothing leaves your network.
Q5. How does PII masking work?
You define sensitive columns (email, phone, SSN) in config. The output automatically replaces these with masked values like '***@***.com'. The masking happens before any data leaves the system.