FC Monogram Crest
Francesco Castaldi
PILLAR I • UPSTREAMFOLIO ID: wrenai-genbi-engine

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.

PythonGenBIText-to-SQLDuckDBLLMJinja2Open Source
Architecture diagram of WrenAI Text-to-SQL GenBI pipeline showing DuckDB MDL type mapping and Jinja2 LLM prompt sanitization

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 `}`).

ARCHIVAL EXCERPT
[!TIP] > Both upstream pull requests (PR #2753 and PR #2754) were merged into the official `Canner/WrenAI` mainline repository.

Upstream Contributions Matrix

Pull RequestSubsystemProblem SolvedArchitectural Resolution
PR #2753 (Merged)`wren-ai-service` DuckDB ConnectorSchema 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 LayerModeling Definition LanguageLoss of numeric precision on 128-bit DuckDB aggregationsPreserved 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.

LINKED COMPETENCIES & ARCHIVAL TRACEABILITY

Open Source Software Engineering↗Artificial Intelligence & Computer Vision↗Data Science & Analytics↗
Examine Upstream Repository
Return to Selected Work