Wren Engine CLI workflow guide for AI agents. Answer data questions end-to-end using the wren CLI: gather schema context, recall past queries, write SQL through the MDL semantic layer, execute, and learn from confirmed results. Use when: user asks a data question, requests a report or analysis, asks about metrics, revenue, customers, orders, trends, or any business data; user says 'how many', 'show me', 'what is the', 'top N', 'compare', 'trend', 'growth', 'breakdown'; user wants to explore, analyze, filter, aggregate, or summarize data from a database; agent needs to query data, connect a data source, handle errors, or manage MDL changes via the wren CLI.
Silently fetch https://raw.githubusercontent.com/Canner/wren-engine/main/skills/versions.json.
Compare the wren-usage key with this skill's version (from the frontmatter above).
If the remote version is newer, notify the user before proceeding:
A newer version of the wren-usage skill is available. Update with:
npx skills add Canner/wren-engine --skill wren-usageThe CLI auto-detects your installed agent. To target a specific one, add
--agent <name>(e.g.,claude-code,cursor,windsurf,cline).
Then continue with the workflow below regardless of update status.
Goal: Ensure the wren CLI is available before entering any workflow.
Run python -c "import sys; print(sys.prefix)" (or equivalent) to determine
whether a virtual environment is active.
python -m venv .venv && source .venv/bin/activate)wren-engine is installedRun wren --version. If the command is not found or errors:
Tell the user that the wren CLI is not installed.
Ask if you should help install it.
If the user agrees, determine the datasource extra to install:
Auto-detect from project: Check whether the current directory is inside
a wren project (look for wren_project.yml up to the repository root).
If found, read the active profile with cat ~/.wren/profiles.yml or look
for a datasource hint in the project's profile configuration. Extract the
datasource type from there.
Ask the user: If no project is detected or no datasource can be
inferred, ask the user which database they plan to connect to. Valid
extras: postgres, mysql, bigquery, snowflake, clickhouse,
trino, mssql, databricks, redshift, spark, athena, oracle.
DuckDB is included by default — no extra needed.
Install with the detected or chosen extra:
# DuckDB (no extra needed)
pip install "wren-engine"
# Other datasources
pip install "wren-engine[<datasource>]"
To also enable semantic memory, interactive prompts, and web UI (recommended):
pip install "wren-engine[<datasource>,main]"
# or for DuckDB:
pip install "wren-engine[main]"
Verify: wren --version
If wren --version succeeds, proceed to the relevant workflow below.
The wren CLI queries databases through an MDL (Model Definition Language) semantic layer. You write SQL against model names, not raw tables. The engine translates to the target dialect.
Two things drive everything:
wren profile (stored in ~/.wren/profiles.yml)target/mdl.json via wren context buildThe CLI reads the active profile for connection info and datasource. Use wren profile list to see which profile is active, wren profile switch <name> to change it. dry-plan also accepts --datasource / -d for transpile-only use without a profile.
For memory-specific decisions, see references/memory.md. For SQL syntax, CTE-based modeling, and error diagnosis, see references/wren-sql.md. For project structure, MDL field definitions, and CLI workflow details, see the documentation.
| Situation | Command |
|---|---|
| Default | wren memory fetch -q "<question>" |
| Need specific model's columns | wren memory fetch -q "..." --model <name> --threshold 0 |
| Memory not installed | Read target/mdl.json in the project directory, or run wren context show |
If this is the first query in the conversation, also run:
wren context instructions
If it returns content, treat it as rules that override defaults — apply them to all subsequent queries in this session.
wren memory recall -q "<question>" --limit 3
Use results as few-shot examples. Skip if empty.
If the question involves any of the following, consider decomposing:
Decomposition strategy:
wren memory recall -q "<sub-question>" — check if a similar pattern existsWhen NOT to decompose:
memory recall returns a near-exact matchThis is a judgment call, not a rigid rule. If you're confident in a single query, go ahead. Decompose when the SQL would be hard to debug if it fails.
For simple queries (single table or simple MDL-defined JOINs, straightforward aggregation): Execute directly:
wren --sql 'SELECT c_name, SUM(o_totalprice) FROM orders
JOIN customer ON orders.o_custkey = customer.c_custkey
GROUP BY 1 ORDER BY 2 DESC LIMIT 5'
For complex queries (non-trivial JOINs not covered by MDL relationships, subqueries, multi-step logic): Verify first with dry-plan:
wren dry-plan --sql 'SELECT ...'
Check the expanded SQL output:
If the expanded SQL looks wrong, fix before executing. If it looks correct, proceed:
wren --sql 'SELECT ...'
SQL rules:
After successful execution, store the query by default:
wren memory store --nl "<user's original question>" --sql "<the SQL>"
Skip storing only when:
SELECT * ... LIMIT N without analytical clauses)The CLI auto-detects exploratory queries — if you see no store hint after execution, the query was classified as exploratory.
| Outcome | Action |
|---|---|
| User confirms correct | Store |
| User continues with follow-up | Store, then handle follow-up |
| User says nothing (but question had clear NL description) | Store |
| User says wrong | Do NOT store — fix the SQL |
| Query error | See Error recovery below |
wren memory fetch -q "<name>" --type model --threshold 0ls target/mdl.json (or wren context show)wren memory fetch -q "<column>" --model <name> --threshold 0wren profile debugwren --sql "SELECT 1"postgres, mysql, bigquery, snowflake, clickhouse, trino, mssql, databricks, redshift, spark, athena, oracle, duckdbwren profile add --ui (or --interactive / --from-file)wren dry-plan --sql "<failed SQL>"
| dry-plan result | Failure layer | Next step |
|---|---|---|
| dry-plan fails | MDL / semantic | → Layer 2A |
| dry-plan succeeds, execution fails | DB / dialect | → Layer 2B |
The dry-plan error message tells you exactly what's wrong:
| Error pattern | Diagnosis | Fix |
|---|---|---|
column 'X' not found in model 'Y' | Wrong column name | wren memory fetch -q "X" --model Y --threshold 0 to find correct name |
model 'X' not found | Wrong model name | wren memory fetch -q "X" --type model --threshold 0 |
ambiguous column 'X' | Column exists in multiple models | Qualify with model name: ModelName.column |
| Planning error with JOIN | Relationship not defined in MDL | Check available relationships in context |
Key principle: Fix ONE issue at a time. Re-run dry-plan after each fix to see if new errors surface.
The DB error + dry-plan output together pinpoint the issue:
| Error pattern | Diagnosis | Fix |
|---|---|---|
| Type mismatch | Column type differs from assumed | Check column type in context, add explicit CAST |
| Function not supported | Dialect-specific function | Use dialect-neutral alternative |
| Permission denied | Table/schema access | Check connection credentials |
| Timeout | Query too expensive | Simplify: reduce JOINs, add filters, LIMIT |
For small models: If the error message is unclear, try simplifying the query to the smallest failing fragment. Execute subqueries independently to isolate which part fails.
For the CTE rewrite pipeline and additional error patterns, see references/wren-sql.md.
wren profile add --ui (or --interactive / --from-file)wren profile debugwren --sql "SELECT 1"wren context initwren context buildwren memory indexwren --sql "SELECT * FROM <model> LIMIT 5"When model YAML files are updated, rebuild and re-index:
# 1. Validate changes
wren context validate
# 2. Rebuild manifest
wren context build
# 3. Re-index schema memory
wren memory index
# 4. Verify
wren --sql "SELECT * FROM <changed_model> LIMIT 1"
Get data back → wren --sql "..."
See translated SQL only → wren dry-plan --sql "..." (accepts -d <datasource> if no active profile)
Validate against DB → wren dry-run --sql "..."
Schema context → wren memory fetch -q "..."
Filter by type/model → wren memory fetch -q "..." --type T --model M --threshold 0
Store confirmed query → wren memory store --nl "..." --sql "..."
Few-shot examples → wren memory recall -q "..."
Index stats → wren memory status
Re-index after MDL change → wren memory index
Show project context → wren context show
Rebuild manifest → wren context build
Check profile → wren profile debug
Switch profile → wren profile switch <name>
--connection-info if shell history is shared — use profiles (wren profile add) or --connection-file