--- name: explore description: 'Use this whenever you need to know what is actually in a database, warehouse, or DuckDB file before you trust it: inventory, column profiles, PII detection, grain and data-quality problems, verified joins, ER diagrams, ad-hoc SQL probes, segmentation, and the semantic layer a repo declares (dbt, Ossie, SLayer, or Cube). Trigger it on an unmet precondition, not on phrasing: if you are about to write or fix SQL against tables whose columns, types, grain, or join keys you have not verified in this session, use this FIRST. That includes dbt work (building a model, fixing one, debugging wrong numbers) whenever the ticket names source tables without spelling out their schema. It applies mid-task too: on reaching a table you have not inspected, stop and use this rather than guess column names. Also for "what''s in my duckdb", "is this data any good", "how do these tables relate". Read-only; writes only the .dex/ cache. It does not author the model: transform does, and maintain reconciles a project that has drifted.' compatibility: 'Needs a local shell and uv. On first use, uv builds the exmergo-dex-core engine from the source bundled with the plugin, or installs it from PyPI at the version scripts/run.py pins when no source is bundled. Runs in Claude Code or another agent that loads Agent Skills and has a shell, not in claude.ai chat.' --- # Explore Make sense of a warehouse or a local DuckDB database the way an analytics engineer does: rank what matters, drill selectively, and persist a draft map in `.dex/`. This skill is read-only: it writes nothing but the `.dex/` cache. ## Procedure For project setup, run `dex init` (or `init` through an installed skill wrapper). It creates or adopts a project, installs managed README and agent instructions, and verifies the connection. It does not explore data or build models. Read its structured missing inputs and readiness before continuing; installing skills does not necessarily install a `dex` executable. Dex works in one loop: explore, transform, maintain. `dex ` below is the `dex` CLI; where it is not installed, run the same command through the skill's `scripts/run.py` wrapper. Each command prints one JSON envelope: read it and decide the next step from it. Step 1 only reads. Steps 2 to 5 change the project, so take them only when the task asks for a change; a question about the data stops after step 1 and reports what it found. Explore and maintain report findings and hand repair work to transform; only the transform workflow performs the project edits, migrations and dev builds described below. 1. **Profile what the change reads.** Before writing or fixing SQL against a table whose columns, types, grain or join keys you have not verified in this session, run `dex explore profile ` on every relation the change reads (`dex explore map` when you do not yet know which), and `dex explore relationships --verify` for the joins it will make. Answer data questions with `dex explore query`, never with a raw database client. 2. **Plan with a declaration.** Hand the SQL to `dex transform plan "" --edits-file ` with a declaration for every model you create or change, beside the edits: ```json {"edits": [{"path": "models/marts/fct_orders.sql", "kind": "model_sql", "content": "..."}], "declarations": [{"model": "fct_orders", "description": "One row per order.", "grain": ["order_id"], "population": {"rule": "Placed orders; cancelled ones are excluded.", "filters": [{"column": "status", "excludes": ["cancelled"]}]}, "columns": {"order_id": {"role": "key"}, "amount": {"role": "measure", "aggregation": "sum", "additivity": "additive", "unit": "currency:USD"}}, "assumptions": [{"decision": "Which statuses count", "chosen": "all but cancelled", "evidence": "precedent", "detail": "every sibling excludes cancelled"}]}]} ``` Use the conventional values, so tools can read them: `role` is `key`, `foreign_key`, `dimension`, `time`, `measure` or `attribute`; `additivity` is `additive`, `semi_additive` (a balance or a running total) or `non_additive` (a ratio, a share, a distinct count); `unit` is `currency:`, `fraction` (0 to 1), `percent` (0 to 100), `count` (any count of things), or a plain unit such as `days`; `aggregation` is how the column rolls up (a count rolls up with `sum`, a running total with `max`). A model that holds one row per entity of another model declares that parent too, `"population": {"parent": {"model": "stg_subscriptions", "key": {"subscription_id": "subscription_id"}}}`, so verification counts the parents missing from it. A model derived from a dbt snapshot's status history declares a `history` block (`skills/transform/references/declarations.md`): whether the first observation is a baseline or a transition, the NULL-status policy, the entities it holds, and whether its timestamp is business or capture time. A declaration is JSON in the payload, rendered into the model's YAML: it never adds, drops or renames an output column. 3. **Read the draft, supply the intent, plan again.** `data.declarations.` holds `drafted` (what Dex measured: keys, running totals, units, value domains, and `precedent`, what sibling models do with the same columns), `missing` (the intent still owed) and `contradictions`. Read them with the `warnings` and, on an existing model, `data.row_attribution`. Correct the SQL or the declaration until both say what the request asks, then plan again. When the change should keep an existing model's results (a refactor, an extraction, a cleanup), run each `data.refactor_comparison_offer.per_model` command before applying, above all where `static_attribution` is not `attributed`. `equivalent` holds for its `input_scope` at `compared_at`: relay both. `different` is a defect to fix in the SQL, unless the request asked for that difference: state an intended rename with `--map` or type change with `--accept-type`, and never loosen the comparison to get a match. `not_checked` is not equivalence: relay its `reason_code`, and where it names an input to rebuild or repair, do that and compare again. When the offer says `baseline_ready: false`, the baseline itself does not build: repair the input it names in a plan of its own, apply and build that plan (with `--cold-deps` where a package owns the node), and only then compare the refactor's plan, which stays unapplied until it is compared; if the repair changed a file that plan edits, plan the refactor again first (`plan_stale`). Never put the repair in the refactor's plan: its comparison would have nothing built to read (`mixed_with_repair`). Equivalence is about the results the request keeps, not an intermediate's layout. A change meant to alter results (a backfill, an exclusion, late arrivals) is compared too, against what it is meant to change: `dex transform compare --key --expect ''`, stating which rows may be `added` and `removed` (`"none"`, `"any"`, or `{"where": ""}`, which may test a column with `IN (SELECT FROM ref('') WHERE ...)`), the `changed_columns` a kept key may change, and `"key": "unchanged"` (or `"any"` when the key may stop being unique). The same object can come from a file with `--expect-file `; a complete one: ```json {"added": {"where": "region = 'emea'"}, "removed": "none", "changed_columns": ["amount"], "key": "unchanged"} ``` `as_expected` is the verdict to relay; `unexpected` is a defect, as `different` is: its `findings` and `unexpected_keys` name the rows the change reached beyond its statement. 4. **Apply.** `dex transform apply ` writes the plan as a reviewable diff. A `needs_confirmation` here means a file changed since planning: plan again against it. Apply refuses a plan whose `change_scope` holds an `undeclared` population change, naming each under `data.undeclared_population_changes`: record an assumption naming its `column` (a re-driven model needs `request` or `contract` tier) and plan again, or undo it. `--accept-population-change ""` applies it anyway and records the reason on the plan; use it only where the request settles the change. A commit carrying files Dex wrote ends with the `data.commit_trailer` line, after a blank line. 5. **Build and verify on dev.** `dex transform build --target dev --verify --for-plan `. Read `data.completion` first: it leads the payload and is bounded, so it survives a cut-off read, and `details` names where the rest is. A required deliverable that `failed`, was `skipped` or is `missing` is not done, whatever relation is left in dev from an earlier run; fix what `blockers` names and build again. `outcome: built_unverified` means every deliverable built and part of the change is still open: `data.completion.unverified` names each model and reason (`comparison_not_run`, `comparison_contradicted`, `undeclared_population_change`, `introduced_high_finding`, `unattributed_high_finding`, `downstream_population_changed`). It is not done. `data.verification.introduced` lists the findings this plan introduced, judged against the last `--verify` build before it was applied, and they lead `findings`; an `existing` finding predates the plan, an `unattributed` one could not be placed. Never dismiss an introduced finding as inherited. `data.completion.impact` says what the plan did to the models it rewrote and to every unedited model below them, measured against the tree before the plan, largest change first: rows, keys removed and added, and on a mart the columns that changed on kept keys. A model you did not edit whose rows or keys moved (`downstream_population_changed`, naming the edit upstream) is a defect in that edit unless the request asked for it; when it did, record the new population on that model as an assumption naming its key `column` at `request` or `contract` tier. An `unchecked` model was not measured. `build_only` means nothing checked those rows. Then read `data.verification.ran`, every finding and everything under `suppressed`. A green build says dbt ran, not that the rows are right: a column that came back all NULL, a parent that vanished, or rows that multiplied is a defect to fix, not a data issue to report. Each record in `join_coverage`, `parent_population` and `temporal_contracts` is `satisfied`, `contradicted` (a finding to fix), `not_applicable` (nothing to judge, such as an empty input, which is not full coverage) or `unchecked` (its `reason_code` says why, and it is not clean). The same holds for `data.completion.obligations`: a `comparison` entry that is not `satisfied` (a rewrite applied uncompared, or compared without an `as_expected` or `equivalent` verdict) and an `incremental_replay` entry that is not `satisfied` (no passing unit test ran the `is_incremental()` branch) are unfinished work, not a passing build. A model that declares no parent is measured against the one Dex drafts for it (`data.declarations..drafted.population_parent` on the plan): each `population_delta` record counts its orphan keys, missing parents and rows whose child columns are all NULL or zero (a sign of a parent with no child, not proof). `needs_decision` (listed under `data.completion.obligations.needs_decision`) asks which rows the model is for: declare `population.parent`, or record the population as an assumption naming the key `column` at `request`, `contract` or `precedent` tier. Output keys the parent lacks are never the population: drive the model from the parent instead. Check the rows the request is about with an aggregate over the built model, `dex explore query --target dev "" ["