Inside InsightOS: Turning Messy Spreadsheets into a Verified Local-First SQLite App, SQL Workbench & Schema-Only AI Analyst
Real-world operations run on messy multi-tab spreadsheets: stacked tables separated by blank rows, yearly tabs renamed halfway through a decade, summary “Total” rows sitting right below raw records, and ID columns whose names drift across sheets. Most “AI spreadsheet” wrappers try to shove CSV slices into a cloud prompt—leaking sensitive rows while returning unverified guesses. I built InsightOS (GitHub: Sockshare/insight-os) to invert that entire model: promote every workbook into a clean local SQLite database with zero silent drops, verify every AI-drafted query deterministically behind a 3-layer read-only SQL sandbox, and pair local-first Ollama privacy with optional schema-only Cloud AI and a direct SQL Workbench.
1. Zero-Silent-Drop Ingestion & Manual Table Relationships
InsightOS launches completely blank—zero preloaded sample records, zero bundled datasets—so it is safe to deploy anywhere as a standalone tool. Drop in .xlsx (row-streamed to keep memory low even on 200,000-row files), .xlsm, .xls, .ods, .csv, or .tsv files and insightos/ingest.py plus insightos/model.py normalize every sheet into SQLite while surfacing every judgment call on a transparent Review screen:
| Pipeline Layer | Module | What It Guarantees |
|---|---|---|
| Streaming Ingestion & Deduplication | ingest.py, reimport.py |
Splits stacked tables on a single sheet, isolates footer “Total” rows, flags unreadable cells instead of dropping them silently, and skips already-imported sheets so totals never double-count. |
| Logical Views & Manual Links | model.py, setup.js |
Merges multi-year sheets (e.g., 2024/2025/2026) into unified queryable views, deduplicates people across IDs and names, and lets analysts define custom + Add link… joins across mismatched column names—preserved across schema refreshes. |
| 3-Layer Read-Only SQL Sandbox | guard.py |
Enforces (1) a read-only SQLite connection, (2) a database-level authorizer blocking writes and internal bookkeeping tables, and (3) a single-SELECT AST parser with strict row and execution-time caps. |
| Deterministic Query Verification | sqlcheck.py, nlq.py |
Validates every filter value against real stored pick-lists, repairs capitalization automatically, detects inflated/dropping joins, flags sparse year columns and missing concepts, and cross-checks via an independent second SQL draft. |
| Schema-Only AI Gateway | llm.py, appsettings.py |
Defaults to local Ollama (qwen2.5-coder:7b) with background warm-up ETA; optionally connects to OpenAI, Gemini, Claude, or any OpenAI-compatible API via stdlib HTTP with 0600 local key storage and masked API responses—sending only table/column schemas and pick-lists. |
2. Direct SQL Workbench + Escape Hatch From Every AI Answer
Even the best NL-to-SQL pipeline hits an edge case where an analyst simply wants to tweak a WHERE clause, adjust a GROUP BY, or inspect a join manually. InsightOS treats direct SQL as a first-class citizen:
- Dedicated Read-Only SQL Workbench (
POST /api/ws/{ws}/sql+sql.js): Includes a clickable table/column schema sidebar, instant tabular results, automatic bar/line charting, 1-click pinning to the live Overview dashboard, and direct CSV/Excel/SVG/PNG downloads—running through the exact same 3-layer read-only lock as AI queries. - 1-Click “Edit SQL” Bridge: Every AI answer on the Ask page, every pinned Overview card, and every query-inspection modal includes an Edit SQL button that carries the query straight into the SQL Workbench—turning black-box answers into inspectable, reusable analyses.
- Zero-AI Full Utility: Even without Ollama or any cloud API key configured, every other workflow—importing, editing with typo-catching forms, live filtered column summaries (Sum · Avg · Min–Max), anomaly scans, SQL Workbench, Overview charts, snapshots/undo, and scheduled Excel/PDF reports—works locally out of the box.
3. Negative-Value Charting, SVG/PNG Export & Live Data Summaries
Financial variances, net changes, refunds, and deficits break naive chart libraries that clamp every axis to zero. In static/js/charts.js, both bar and line charts compute true signed baselines—rendering positive bars upward, negative bars downward from a crisp zero-axis line, accurate hover/label positioning, and 1-click SVG and 2x-DPI PNG downloads from Ask answers, Overview cards, and SQL Workbench results. On the Data table view, crud.py computes live Sum, Average, and Min–Max metrics directly over whatever search query or column filters are active, while ask.js provides searchable, paginated Ask history with per-answer deletion.
4. Measured Verification: 184 Unit Tests, 108 Chart Checks & 62 UI Steps
Every standalone upgrade was verified across backend, geometry, and browser-DOM layers before public release:
- 184 / 184 Python Unit & Live-HTTP API Tests: Covers ingestion, stacked tables,
.xls/.odsparity, 3-layer read-only lock enforcement, SQL Workbench execution, schema-only cloud provider payloads & masked credentials, manual table links surviving refresh, filtered numeric summaries, and Ask history pagination/deletion. - 38 / 38 Self-Test Integrity Checks & 108 / 108 Chart Geometry Checks: Exercises positive-only, negative-only, and mixed-sign bar/line layouts across 9 viewport widths with zero label collisions or clipping.
- 7 / 7 Node/jsdom End-to-End UI Journeys (62 / 62 Steps, 0 Page Errors): Drives the complete user experience from a clean empty start screen through workbook drag-and-drop, Review, Data editing, People deduplication, SQL Workbench, AI settings, and Overview pinning.