WrenAI GenBI Engine · DuckDB Type System & Prompt Sanitization
Upstream contributions to WrenAI, an open-source GenBI (Generative Business Intelligence) Text-to-SQL platform. Extended the DuckDB connector type system to support unsigned integers, hugeint, bitstrings, and temporal intervals, and sanitized user-supplied metadata in Jinja2 LLM prompt pipelines.
Generative BI & Text-to-SQL Reliability
[WrenAI](https://github.com/Canner/WrenAI) is an open-source GenBI agent that translates natural language business questions into executable SQL queries across modern data warehouses. In production Text-to-SQL pipelines, two failure modes frequently arise: unmapped database-specific column types during schema introspection, and template syntax exceptions when table comments or sample values contain raw curly braces (`{` or `}`).
Upstream Contributions Matrix
| Pull Request | Subsystem | Problem Solved | Architectural Resolution |
|---|---|---|---|
| PR #2753 (Merged) | `wren-ai-service` DuckDB Connector | Schema introspection failed on `UHUGEINT`, `UTINYINT`, `BIT`, `TIME_TZ` | Complete bi-directional MDL type mapping table |
| PR #2754 (Merged) | LLM Prompt Jinja2 Pipeline | `TemplateSyntaxError` when schema descriptions contain `{{ ... }}` | Deterministic AST-safe Jinja2 delimiter escaping |
| Semantic MDL Layer | Modeling Definition Language | Loss of numeric precision on 128-bit DuckDB aggregations | Preserved exact analytical type semantics for LLM context |
*Table 1: WrenAI GenBI Upstream Enhancements*
# Upstream DuckDB type mapping and Jinja2 prompt sanitization in WrenAI
DUCKDB_EXTENDED_TYPE_MAP = {
"UTINYINT": "INTEGER",
"USMALLINT": "INTEGER",
"UINTEGER": "BIGINT",
"UBIGINT": "NUMERIC",
"HUGEINT": "NUMERIC",
"UHUGEINT": "NUMERIC",
"BIT": "VARCHAR",
"TIME WITH TIME ZONE": "TIMETZ",
}def sanitize_jinja_prompt_input(raw_text: str) -> str: return raw_text.replace("{{", "{ {").replace("}}", "} }").replace("{%", "{ %").replace("%}", "% }") ```
Impact on Enterprise GenBI Workflows
- Zero schema introspection crashes when connecting WrenAI to local or MotherDuck DuckDB analytical files. - Eliminated prompt rendering failures on complex enterprise database schemas containing JSON snippets in column documentation.
