Capability · Reshape

Not just renaming columns — reshaping the grid.

Transpose, unpivot, pivot, join across sheets and split one messy input into a clean multi-sheet workbook. A deterministic detection pass untangles the grid; a PHI-free router picks how to transform it.

POST /v1/reshape
reshape.pyworkbook.xlsxImportGenerate codeClean output

What you get

Built for regulated workloads

Real spreadsheets are not tidy tables. Headers sit three rows down, units live on their own row, grouped headers span columns, and the whole thing is transposed. Reshape handles the structure the cascade assumes away. First a deterministic structural-detection pass turns the mess into clean logical tables. Then a PHI-free router classifies the job into one of three strategies — and in every generated path, the model sees only table SHAPE plus up to three clamped sample rows, never your full data.

Detect

Untangle the grid first

A deterministic pass finds headers that aren’t on row 0, flattens multi-row and grouped headers (into “Instrument › Variable”), strips unit rows and auto-unpivots transposed layouts — turning a messy sheet into clean logical tables before any AI is asked to reason about it.
Route

Three strategies, one router

A PHI-free classifier picks the cheapest strategy that fits: direct (a plain cascade rename), plan (a declarative JSON transform), or code (generated Python, R or SQL). The router reasons over shape only — never the data.
Plan

Declarative plans, executed in-process

The default, PHI-safe path: the model writes a declarative JSON reshape plan — rename, derive, filter, unpivot, pivot, join — that AdaptivMapr executes deterministically in-process. No eval, byte-reproducible, and you can inspect every step before it runs.
Code

Generated code, sandboxed

When a job is too gnarly for a plan, the model writes Python/pandas, R or SQL/DuckDB, executed in a network-isolated sandbox in your region. The code operates on the shape it was shown; the sandbox is torn down when the answer returns.
Privacy

Shape in, never the rows

In both generated paths — plan and code — the model is handed only the table structure and up to three clamped sample rows (≤80 chars each). The full dataset is transformed locally by the plan or in the pinned sandbox; it never becomes prompt text.
Output

One mess in, clean workbook out

Split a single tangled input into a tidy multi-sheet output workbook — one logical table per sheet — mapped to your target schema and ready to commit. The signature move that a rename-only mapper simply can’t do.

Try it

A real call, end to end

Post a messy workbook and your target schema. The response tells you which strategy the router chose, the transform it generated, and the clean sheets it produced.

Good to know
  • plan is the default and PHI-safe — a declarative transform executed in-process, no eval, byte-reproducible.
  • code runs in a region-pinned, network-isolated sandbox and is full-data by nature (PHI entitlement required).
  • The structural-detection pass is deterministic and source-agnostic — it runs before any model is called.
curl
curl https://api.adaptivmapr.com/v1/reshape \
  -H "Authorization: Bearer $MAPR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "upload_id": "up_7fce…",
    "target": "lab_results"
  }'
response
{
  "strategy": "plan",
  "plan": [
    { "op": "unpivot", "id_cols": ["patient_id", "drawn_at"],
      "value_cols": ["Na", "K", "Cl"], "into": ["analyte", "value"] },
    { "op": "derive", "field": "unit", "from": "analyte_unit_row" }
  ],
  "sheets": [
    { "name": "results", "rows": 1840, "target": "lab_results" }
  ]
}

FAQ

Common questions

The cascade maps columns to fields on an already-tidy table. Reshape changes the table’s structure first — transposing, unpivoting, pivoting, joining and splitting — so a spreadsheet that isn’t a clean grid can still land on your schema. Reshape often finishes by handing its clean output to the cascade.
No. The detection pass is deterministic and local. When the router chooses a generated path, the model sees only the table’s shape and up to three clamped sample rows — never the full dataset. A plan is executed in-process; generated code runs in a region-pinned, isolated sandbox.
A declarative plan is inspectable, deterministic and byte-reproducible — no arbitrary code executes, so it is the safe default and works without the full-data tier. Code generation is the escape hatch for transforms a plan can’t express, and it runs sandboxed.
Yes — that’s the flagship move. A single input holding several logical tables (say, patients and their encounters interleaved) is detected, separated and emitted as a clean multi-sheet workbook, each sheet mapped to its own target.
The detection pass handles exactly that: non-row-0 headers, multi-row and grouped headers (flattened like “Instrument › Variable”), and unit rows are all found and normalized deterministically before mapping begins.

Ready when you are

Put structural reshape in production — without shipping raw records.

Spin up a key in minutes. Top up a $10 prepaid wallet — every map is a few tokens.

$10 minimum to start · pay only for what you map · PHI under BAA coverage