/bauplan:bauplan-dag-optimizationfrom bauplan
Optimizes an existing Bauplan DAG for speed and efficiency by restructuring models, narrowing inputs, adjusting materialization, and proposing partitioning. Use when a pipeline is slow or produces too many intermediates.
Ships in bauplan. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Mental model · Workflow · 1. Inventory · 2. Profile · 3. Materialization · 4. Inputs · 5. Model structure · 6. Project boundaries · 7. Partitioning · 8. Verify and measure · Proposal
References: partitioning.md for the profiling queries and partitioning heuristics, patterns.md for before/after code.
This skill uses the typed SDK (0.3.0+) syntax: inputs are Annotated[pa.Table, bauplan.Model(...)], projections are TableSchema classes passed as projection_schema=, and every model declares its output schema in its return annotation. If the project is on an older SDK, migrate it first with the bauplan-migrate-to-typed-sdk skill, or ask the user before optimizing old-style code.
Bauplan handles I/O, Arrow conversion between models, where intermediate data lives and when work is scheduled. A model that is not materialized is still handed to its children by the platform; you do not manage memory or placement, and you should not try to. Performance comes from data modeling:
The biggest wins are almost always I/O: fewer materialized intermediates, narrower inputs, and partitioned tables that consumers can read slice by slice.
filter= on bauplan.Model(...) works only on a table that already exists in the catalog when the run starts. Setting it on a model produced in the same run is rejected by the planner ("Apply the filter inside the function"). To read a slice of an intermediate, materialize it in one project and read it with filter= from a later project run.event_date >= '2025-01-01' prunes, LOWER(region) = 'emea' or other functions on the column do not. Parameters can be used inside filters with $name syntax, for example filter="event_date >= $start_date". The planner warns about unfiltered scans of tables of 20 GB or more.materialization_strategy (the default is NONE) does not write to object storage and no Iceberg commit happens. A materialized output is additionally written to object storage and committed to the catalog (REPLACE drops and rewrites the whole table).filter=, projection_schema=, the schema classes and the decorators are parsed from the source before execution, so filters must be string literals (a $name parameter inside the literal is fine), not f-strings or variables.Do steps 1 and 2 before proposing anything. Do not ask the user what to optimize; find it.
Read every bauplan_project.yml, models.py and SQL model. Build one table with a row per model:
| Column | What to record |
|---|---|
| model | function name and project |
| inputs | each bauplan.Model(...) with its projection_schema= and filter= |
| columns used | the columns the body actually touches |
| materialized | materialization_strategy and partitioned_by, if set |
| consumers | models in the same project, other projects, and anything outside the DAG |
| operations | joins, group_by keys, window partition keys, sorts, date filters inside the body |
Ask the user only one question if the code cannot answer it: which tables are read by something outside the DAG (dashboards, other teams, agents, a semantic layer).
Run read-only queries on a pinned ref to measure what the code alone cannot tell you. Use the procedures in partitioning.md:
records and size of every catalog input and every materialized output, from client.get_table(...), plus its current partitioning.Keep the numbers; the proposal cites them.
Walk backwards from consumption. A model gets a materialization_strategy only if:
filter= rule above);Everything else stays non-materialized. Each removed materialization saves one write to object storage and one Iceberg commit. Instead of rebuilding the whole table with REPLACE on every run, it is preferable to use, when applicable, an incremental approach using either OVERWRITE_PARTITIONS or APPEND.
If the original DAG materialized tables that would no longer have a materialization strategy, ask the user how to proceed: a) keep materializing them as before, b) keep the existing tables but stop materializing them, or c) drop the existing tables and stop materializing them.
projection_schema= class that lists only those columns. A missing projection reads the whole table. Take the column types from bauplan table get <namespace>.<table> and mark nullable columns | None.filter= when the rows would be discarded anyway. Do not move a filter across a join or an aggregation if that changes multiplicity or totals. For an input that is a model of the same run, filter inside the consuming function instead.$name parameters rather than editing the code per run.TableSchema in its return annotation, derived from what the transformation actually produces, including casts where Polars yields a type the schema does not allow (for example unsigned integers from pl.len() or a hash).Merge two projects when the second reads the first's output whole, without a filter, and nothing else reads that output: the intermediate becomes a non-materialized model, saving a write, a read and a job submission.
Split a project when partitioning (step 7) requires consumers to read slices of an intermediate or when it holds independent pipelines that could run as separate jobs. Independent projects can then run in parallel; dependent ones run in order.
Do not leave this to the user. From the inventory and the profile, make an explicit recommendation for every table above about 1 GB and every materialized output, using the decision procedure in partitioning.md. There are two kinds of partitioning, and a table may need more than one:
| Kind | Goal | Column choice |
|---|---|---|
| Read pruning | Consumers read fewer files | The column consumers filter on, usually a date with a year, month, day or hour transform, or a low-cardinality category |
| Incremental writes | Rewrite only the periods that changed | The time column that defines which rows change between runs |
For each recommendation, state the table, the kind, the column and transform, the expected number of partitions and rows or GB per partition, the evidence (numbers from step 2 and the code lines that filter or group on the column), what changes in the DAG (new partitioned_by, new filter=, a project split), and the risk. Also state explicitly which large tables should not be partitioned and why. The user makes the final call, but always give them a concrete default.
An optimization must not change results. For every output, compare the optimized run with the original run on the same inputs: same schema and dtypes, same rows including duplicates, same NULL positions. Restructuring can change row order and the order of float summation; if a result depends on either (keep-first deduplication, cumulative sums, float totals), make the order explicit or report the difference.
Measure on the same branch state with the same settings, and report per-job wall time with job ids for both versions. Run both with cache disabled (--no-cache in the CLI, cache=False in the SDK), because the platform skips tasks whose outputs it already holds, which makes a rerun look faster than it is.
Besides data, Bauplan stores on Iceberg, at every run, the table description (the model function's docstring, or the output TableSchema class docstring if the function has none), as well as column documentation (in the form of TableField(doc="...")). Hence, do ensure that when rewriting a DAG these metadata are kept consistent, too.
Before editing code, present:
Implement after the user approves, one project at a time, verifying each before the next: uvx ruff check and uvx ty check on the project, then bauplan run --dry-run, then a full run on an isolated data branch (<username>.<branch>, never main). The dry run executes every model, so output contract mismatches already surface there, as ModelOutputContractError.
What SKILL.md sets; muted values are Claude Code's defaults
9 skills in this plugin
/bauplan-data-assessmentAssesses whether a business question can be answered with data available in a Bauplan lakehouse. Maps business concepts to tables and columns, checks data quality on the relevant subset, validates semantic fit, and renders a verdict: answerable, partially answerable, or not answerable. Produces a structured feasibility report. Use when a user brings a business question, asks 'can we answer this', wants to know if the data supports an analysis, or before building a one-off analysis or pipeline./bauplan-data-pipelineCreates bauplan data pipeline projects with SQL and Python models. Use when starting a new pipeline, defining DAG transformations, writing models, or setting up bauplan project structure from scratch./bauplan-npx claudepluginhub bauplanlabs/bauplan-skills --plugin bauplanOther plugins' skills for the same job