Plan mode — pipeline.plan()¶
Pipeline.run() is all-or-nothing: it either runs the whole dataset or it
doesn't. For a new pipeline that's a real risk — a mis-built prompt or a 10k-row
CSV can turn into an accidental \$50 run. pipeline.plan() is the dry run:
it previews what each step will do and estimates the full cost before you
commit, modelled on terraform plan and Claude Code's plan mode.
What a plan does¶
plan() runs the pipeline over the first sample_size rows — real calls, but
capped — and reports:
- Resolved prompts — the system prompt each LLM step will send. This is the
static half of the prompt (instructions plus field specifications); row data
travels in the user message and is shown separately under
sample_rows. - JSON schemas — the structured-output schema each step generates from its field specs.
- Sample outputs — the actual enriched rows from the capped run.
- Estimated full-run cost — the sample's measured token usage extrapolated to the full row count.
plan.summary() returns a human-readable preview as a string (print it, log it,
or assert on it in a test). The structured fields are also available directly on
the PipelinePlan: steps, sample_rows, sample_outputs, sample_errors,
total_rows, sample_size, sample_cost, estimated_cost and
unestimated_steps.
Inspecting individual steps¶
plan.steps is a list of StepPlan objects — one per step, in execution order —
so you can assert on a single step instead of string-matching summary():
from accrue import StepPlan # exported at the top level
plan = pipeline.plan(df)
for step in plan.steps:
print(step.name, step.kind, step.depends_on)
# Catch a prompt regression before paying for a full run
enrich = next(s for s in plan.steps if s.name == "enrich")
assert "investment thesis" in enrich.system_prompt
| Attribute | Meaning |
|---|---|
name |
Step name |
kind |
"llm", "function", or "other" (a custom Step) |
depends_on |
Names of upstream steps this one consumes |
model |
Model identifier (LLM steps only) |
system_prompt |
The resolved system prompt — the static, cacheable half (LLM steps only) |
response_format |
The response_format the step will send: a JSON schema dict, or {"type": "json_object"} for freeform (LLM steps only) |
The non-LLM attributes are None on function and custom steps.
Cost estimation¶
The estimate extrapolates the sample's measured tokens to the full dataset. Crucially, it divides by the rows that actually called the API — cache misses (or every processed row when caching is off) — so cached sample rows don't deflate the estimate, and re-planning an already-cached dataset doesn't invent phantom cost.
Cost is reported in tokens (prompt / completion / total), matching how
result.summary() and result.report() express cost throughout Accrue. On a
fresh dataset the estimate lands within roughly ±20% of the actual full run;
treat it as a guardrail against surprises, not an invoice.
When sample rows fail¶
A failed row counts in the estimate if the provider billed it. One with no
reported tokens, such as a rejected request, is left out. If some sample rows
fail for a step, summary() says how many.
If every sample row fails for an LLM step, there is nothing to extrapolate
from. A missing API key does this. The step is listed in
plan.unestimated_steps, and summary() opens with a warning that names the
step and its first error. The full-run line reads "no estimate" instead of
0 tokens. Fix the error and plan again. A step whose rows were all skipped
because an upstream step failed is listed too.
Rows served from the cache count as successes. A second plan() over cached
rows still reports zero tokens, with no warning: those rows really are free.
Plan with EnrichmentConfig(enable_caching=False) to re-estimate them.
Confirm before a big run¶
For interactive scripts, run(..., confirm=True) wires the preview straight into
a gate: it prints the plan and asks y/n before running the rest of the dataset.
# Prints the plan, then prompts. Answering "n" raises RuntimeError without
# running the full dataset.
result = pipeline.run(df, confirm=True)
The capped sample inside the plan still makes real (small) calls, so you see true sample outputs before deciding whether to spend on the whole set.
If the plan has no estimate because every sample row failed, the prompt says so and asks "Proceed anyway?". The default is still no.
Out of scope¶
- Per-row cost preview — use
run()and inspectresult.costfor that. - Interactive UI —
plan()is plain stdout; wrap it yourself if you want more.