How to Query CSV Files with Natural Language Locally (No Cloud Uploads)
If you are a data analyst or software engineer, querying multi-gigabyte CSV files usually requires one of two annoying paths:
- Slow Excel / Sheet UIs: Crashing when loading more than 1,000,000 rows.
- Cloud AI SaaS Tools: Uploading raw customer files to cloud servers with privacy & GDPR risks.
In this guide, we will show you how to query CSV files in natural language 100% locally using an in-process DuckDB C++ engine and AST security validation.
🛠️ Step 1: In-Process CSV Ingestion with DuckDB
Unlike traditional SQL databases that require running heavy database servers (like PostgreSQL or MySQL), DuckDB operates as an in-process columnar database inside Node.js or Python.
import duckdb from 'duckdb';
const db = new duckdb.Database(':memory:');
const con = db.connect();
// Query 100MB+ CSV directly in-memory without database import
con.all("SELECT * FROM read_csv_auto('sales_data.csv') LIMIT 10;", (err, res) => {
if (err) throw err;
console.log('Query Results:', res);
});
🔒 Step 2: Natural Language Text-to-SQL with Local Schema Injection
To allow users to ask questions like "What were our top 5 revenue states last month?", we convert natural language into SQL using Schema-Only Context:
{
"tableName": "sales_data",
"columns": [
{"name": "state", "type": "VARCHAR"},
{"name": "revenue", "type": "DOUBLE"},
{"name": "created_at", "type": "TIMESTAMP"}
]
}
Only the column names above are passed to the LLM (Ollama or BYOK endpoint). Raw data rows never leave your environment!
📊 Step 3: Local Visualization & Offline Dashboard Export
Once DuckDB executes the SQL query locally, the resulting rows are rendered directly on the client using interactive Chart.js visualizations.
Key Benefits:
- ⚡ Instant Execution: Query millions of rows in milliseconds.
- 🛡️ 100% Data Residency: Zero raw-data transmission over the web.
- 📁 1-Click HTML Exporter: Export standalone HTML charts that open offline in any browser.
🚀 Experience It Live
Try this exact architecture live on our web demo:
- 🔗 Live Demo: veil-analytics.onrender.com
- 🌐 Official Website: veilanalytics.netlify.app
Top comments (0)