bricksentry 0.1.9__tar.gz → 0.1.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bricksentry-0.1.9 → bricksentry-0.1.12}/CHANGELOG.md +32 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/PKG-INFO +40 -10
- {bricksentry-0.1.9 → bricksentry-0.1.12}/README.md +39 -9
- bricksentry-0.1.12/deploy/databricks-app/README.md +88 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/pyproject.toml +1 -1
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/__init__.py +1 -1
- bricksentry-0.1.12/src/bricksentry/__main__.py +6 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/agent_tools.py +20 -4
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/assess.py +43 -4
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/backends/databricks_backend.py +19 -1
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/cli.py +13 -3
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/config.py +5 -1
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/explain.py +16 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/lineage.py +117 -3
- bricksentry-0.1.12/src/bricksentry/mcp_server.py +110 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/models.py +23 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/policy.py +55 -2
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/policy_templates.py +8 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/report.py +15 -0
- bricksentry-0.1.12/tests/test_0110.py +211 -0
- bricksentry-0.1.12/tests/test_0112.py +244 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_018.py +2 -1
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_check_notebook.py +1 -1
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_notify_templates.py +1 -1
- bricksentry-0.1.9/src/bricksentry/mcp_server.py +0 -55
- {bricksentry-0.1.9 → bricksentry-0.1.12}/.gitignore +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/LICENSE +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/SECURITY.md +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/action.yml +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/examples/databricks/bricksentry_check_my_table.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/examples/databricks/bricksentry_quickstart.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/packages/bricksentry-mcp/LICENSE +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/packages/bricksentry-mcp/README.md +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/packages/bricksentry-mcp/src/bricksentry_mcp/__init__.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/scripts/build_notebook.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/backends/base.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/backends/duckdb_backend.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/demo.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/diff.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/github.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/notify.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/conftest.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_019.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_demo.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_diff.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.9 → bricksentry-0.1.12}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.12 (2026-11-11)
|
|
4
|
+
|
|
5
|
+
- **Column-level signals.** After the diff, bricksentry knows which columns a change touched (changed values, new NULLs, dropped or retyped). It reads their Unity Catalog tags from `information_schema.column_tags`, and follows `system.access.column_lineage` from those columns only, up to `lineage.column_depth` hops (default 2), to the downstream columns they feed. Assessments, summaries and the pull-request report show the changed columns, their tags and the column impact.
|
|
6
|
+
- New policy conditions: `changed_column_tag` (e.g. `pii`), `downstream_column_tag` (e.g. `certified`) and `changed_column` (glob). The default policy now asks a human when a column tagged `pii` changes (`pii-column-changed`); `strict`, `agent-safe` and `certified` also flag changes that feed a certified column (`certified-column-feed`), and `pii` flags changes that feed pii columns.
|
|
7
|
+
- `whats_downstream` takes an optional `columns` list, so an agent can see before editing which downstream columns a column feeds and how they are tagged.
|
|
8
|
+
- Static lineage (`type: static`) supports `column_edges` and `column_tags`; the README now shows a full static lineage example.
|
|
9
|
+
- `python -m bricksentry` runs the CLI, for environments where the console command isn't on the PATH.
|
|
10
|
+
- If column tags or column lineage can't be read, the check still runs and the summary says what was unavailable.
|
|
11
|
+
|
|
12
|
+
## 0.1.11 (2026-11-11)
|
|
13
|
+
|
|
14
|
+
> **Published by hand, without provenance.** GitHub Actions stopped starting jobs in this repository on 2026-11-11 (from about 20:20 UTC), so the release workflow could not run. `bricksentry` 0.1.11 was built from commit `b3d9c32` and uploaded manually with `twine`. That is why PyPI shows "loss of provenance" for this release: attestations are only created by the automated workflow. The 29 files inside the published wheel were compared with an independent build of the same commit and are identical. `bricksentry-mcp` was not published for 0.1.11. The next release goes through the normal workflow again, with provenance.
|
|
15
|
+
>
|
|
16
|
+
> SHA-256 of the published files:
|
|
17
|
+
> - `bricksentry-0.1.11-py3-none-any.whl`: `67f914626c71784d473693c8bbe72665b4de9a48c1265dbb1d1d0afe65cb76f1`
|
|
18
|
+
> - `bricksentry-0.1.11.tar.gz`: `6a894e20157734061850be33c1ca6af9dea160ba9f859babcc207939bc1c6913`
|
|
19
|
+
>
|
|
20
|
+
> Check a download with `shasum -a 256 <file>` (macOS) or `sha256sum <file>` (Linux).
|
|
21
|
+
|
|
22
|
+
From a full live test of 0.1.9 on Databricks serverless:
|
|
23
|
+
|
|
24
|
+
- Fix: when the Databricks SDK could not find credentials, the CLI showed the SDK's raw error. Run as a subprocess of a notebook it failed with a cryptic `parent_header` error. It now says it could not sign in to Databricks, lists the ways to provide credentials, and suggests the Python API inside notebooks.
|
|
25
|
+
- The `lineage.type` false warning that test also found was already fixed in 0.1.10.
|
|
26
|
+
|
|
27
|
+
## 0.1.10 (2026-11-11)
|
|
28
|
+
|
|
29
|
+
- **Run the MCP server as a Databricks App.** New kit in `deploy/databricks-app`: `app.yaml`, an Asset Bundle with the SQL warehouse resource, a pinned `requirements.txt`, a starter `bricksentry.yml` and the Unity Catalog grants for the app's service principal. Deploy with `databricks bundle deploy` and `databricks bundle run`; agents connect to `https://<app-url>/mcp`.
|
|
30
|
+
- `bricksentry mcp --transport streamable-http` now listens on `0.0.0.0:$DATABRICKS_APP_PORT` on Databricks Apps, and takes `--host` / `--port` (or `BRICKSENTRY_HOST` / `BRICKSENTRY_PORT`) elsewhere. It runs stateless, so it works behind a load balancer.
|
|
31
|
+
- New `--read-only` (or `BRICKSENTRY_READ_ONLY=1`) leaves out `preview_write`, so a shared server never writes, not even to a sandbox clone.
|
|
32
|
+
- Fix: with mcp 1.x, the HTTP server rejected requests that came through a proxy (HTTP 421) because localhost-only host checking stayed on. It now applies only when listening on localhost, as in mcp 2.
|
|
33
|
+
- Fix: the config typo warnings added in 0.1.8 flagged valid lineage settings such as `lineage.type`, `exclude` and `exclude_dropped`. All lineage keys bricksentry reads are now recognised, and a test keeps the list in sync with the code.
|
|
34
|
+
|
|
3
35
|
## 0.1.9 (2026-11-11)
|
|
4
36
|
|
|
5
37
|
- New notebook: **what did my last pipeline run do?** Point it at a Delta table; it finds the latest data change in the table's history, compares it with the version before using two shallow clones, and shows the verdict, rules, blast radius and the `RESTORE` command. Read-only on your table. Import from `examples/databricks/bricksentry_check_my_table.py`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.12
|
|
4
4
|
Summary: Change-safety for Databricks pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans.
|
|
5
5
|
Project-URL: Homepage, https://bricksentry.org
|
|
6
6
|
Project-URL: Documentation, https://bricksentry.org/docs
|
|
@@ -98,7 +98,7 @@ Before a change reaches production, bricksentry answers three questions, in a
|
|
|
98
98
|
pull-request comment for humans and in structured JSON for agents:
|
|
99
99
|
|
|
100
100
|
1. **What does it do to the data?** A key-based data diff: added, removed and changed rows, schema changes, per-column changes, numeric totals, duplicate keys, and *where* the change is concentrated ("100% of affected rows are region = APAC").
|
|
101
|
-
2. **Who gets hurt?** The downstream blast radius from Unity Catalog lineage: tables, jobs, notebooks, Lakeflow pipelines, dashboards and queries, with owners and tags.
|
|
101
|
+
2. **Who gets hurt?** The downstream blast radius from Unity Catalog lineage: tables, jobs, notebooks, Lakeflow pipelines, dashboards and queries, with owners and tags. Down to the column: which columns the change touched, whether they are tagged (for example `pii`), and which downstream columns they feed.
|
|
102
102
|
3. **Is it safe, and how do I undo it?** A deterministic policy verdict (`pass` · `warn` · `needs_human` · `block`) and the exact `RESTORE TABLE … VERSION AS OF n` rollback.
|
|
103
103
|
|
|
104
104
|
For your Databricks workspace:
|
|
@@ -144,7 +144,7 @@ bricksentry is listed in the [official MCP Registry](https://registry.modelconte
|
|
|
144
144
|
|
|
145
145
|
| Tool | What the agent gets |
|
|
146
146
|
|---|---|
|
|
147
|
-
| `whats_downstream(table, depth)` | Downstream assets with owners and tags. Call it *before* editing. |
|
|
147
|
+
| `whats_downstream(table, depth, columns?)` | Downstream assets with owners and tags. Call it *before* editing. Pass the columns you'll change to see the downstream columns they feed and their tags. |
|
|
148
148
|
| `rollback_plan(table)` | The restore SQL. Capture it *before* changing anything. |
|
|
149
149
|
| `preview_write(sql, target, keys?)` | Runs one write against a **disposable shallow clone**, never production, and returns the diff plus verdict. |
|
|
150
150
|
| `assess_change(tables, candidates?, pr?)` | Diffs prod vs. the candidate built by your change, plus lineage and policy. Returns a verdict and an `id`. |
|
|
@@ -163,6 +163,17 @@ The same tools are plain Python functions in `bricksentry.agent_tools`, so you c
|
|
|
163
163
|
|
|
164
164
|
To watch the whole loop, run `bricksentry demo` (see the top of this page). `bricksentry demo --report report.md` also writes the pull-request comment a reviewer would see.
|
|
165
165
|
|
|
166
|
+
### Host it in your workspace (Databricks Apps)
|
|
167
|
+
|
|
168
|
+
Run the MCP server as a Databricks App so every agent in your workspace can reach it over HTTPS, with no tokens to manage: it runs as the app's service principal, and Unity Catalog grants decide what it can read. [`deploy/databricks-app`](deploy/databricks-app) is a ready app (`app.yaml`, an Asset Bundle, the grants) that deploys with two commands:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
databricks bundle deploy --var warehouse_id=<your-sql-warehouse-id>
|
|
172
|
+
databricks bundle run bricksentry_mcp
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Agents connect to `https://<app-url>/mcp`. The kit starts the server with `--read-only`, which leaves out `preview_write`, so the app never writes. On any other host, `bricksentry mcp --transport streamable-http --host 0.0.0.0 --port 8000` serves the same endpoint. Unity Catalog *MCP Services* are for servers hosted outside Databricks, so a Databricks App is the recommended way to run bricksentry inside it; see the [kit's README](deploy/databricks-app/README.md).
|
|
176
|
+
|
|
166
177
|
## For data engineers: CLI and CI
|
|
167
178
|
|
|
168
179
|
```bash
|
|
@@ -205,7 +216,7 @@ Check out with `fetch-depth: 0` and give the job `pull-requests: write` permissi
|
|
|
205
216
|
Or use the bundled GitHub Action, which also writes the report to the job summary:
|
|
206
217
|
|
|
207
218
|
```yaml
|
|
208
|
-
- uses: bricksentry/bricksentry@v0.1.
|
|
219
|
+
- uses: bricksentry/bricksentry@v0.1.12
|
|
209
220
|
with:
|
|
210
221
|
config: bricksentry.yml
|
|
211
222
|
fail-on: needs_human
|
|
@@ -230,7 +241,7 @@ jobs:
|
|
|
230
241
|
fetch-depth: 0
|
|
231
242
|
# Build this PR's version of your pipeline into a per-PR schema first,
|
|
232
243
|
# for example: databricks bundle deploy -t ci && databricks bundle run -t ci
|
|
233
|
-
- uses: bricksentry/bricksentry@v0.1.
|
|
244
|
+
- uses: bricksentry/bricksentry@v0.1.12
|
|
234
245
|
with:
|
|
235
246
|
config: bricksentry.yml
|
|
236
247
|
fail-on: needs_human
|
|
@@ -292,7 +303,7 @@ sandbox_schema: main.bricksentry_sandbox
|
|
|
292
303
|
candidate_pattern: "{catalog}.{schema}_pr_{pr}.{table}"
|
|
293
304
|
sample_pct: 10 # sample_guard re-checks the whole table (on by default)
|
|
294
305
|
assessment_store: ~/.bricksentry/assessments # or false to keep assessments in memory
|
|
295
|
-
lineage: {type: databricks, depth: 3, lookback_days: 90} # also: exclude, exclude_dropped
|
|
306
|
+
lineage: {type: databricks, depth: 3, lookback_days: 90, column_depth: 2} # also: exclude, exclude_dropped
|
|
296
307
|
tables:
|
|
297
308
|
main.sales.orders:
|
|
298
309
|
keys: [order_id]
|
|
@@ -302,6 +313,23 @@ tables:
|
|
|
302
313
|
policy: policy.yml # or builtin:<template>, see "Policy templates" below
|
|
303
314
|
```
|
|
304
315
|
|
|
316
|
+
**Without Unity Catalog** (local DuckDB work, tests, or other platforms), give the lineage in the config instead. Edges map a table to what reads from it; column edges and tags are optional:
|
|
317
|
+
|
|
318
|
+
```yaml
|
|
319
|
+
lineage:
|
|
320
|
+
type: static
|
|
321
|
+
edges:
|
|
322
|
+
main.sales.orders: [main.sales.daily_revenue, "dashboard:Revenue Overview", "job:finance_close"]
|
|
323
|
+
owners:
|
|
324
|
+
main.sales.daily_revenue: finance-team
|
|
325
|
+
tags:
|
|
326
|
+
main.sales.daily_revenue: {certified: "true"}
|
|
327
|
+
column_edges: # "table.column" -> downstream "table.column"s
|
|
328
|
+
main.sales.orders.amount: [main.sales.daily_revenue.revenue]
|
|
329
|
+
column_tags: # table -> column -> tags
|
|
330
|
+
main.sales.orders: {customer_email: {pii: ""}}
|
|
331
|
+
```
|
|
332
|
+
|
|
305
333
|
Typos are caught: an unknown key such as `sample_pc` prints a warning that names the right one (`did you mean 'sample_pct'?`) instead of being silently ignored.
|
|
306
334
|
|
|
307
335
|
**Which totals are checked.** `sum_change_pct_gt` rules and summaries look at measures: by default every numeric column except keys and columns whose names look like IDs, codes, years and other date parts, coordinates, ratings, scores or rates (a 10% drop in `sum(established_year)` only says rows were removed). List `measures` for a table to choose exactly, or set `measures: all` to check every numeric column. A rule that names a column (`when: {column: rating, sum_change_pct_gt: 1}`) always checks it.
|
|
@@ -354,7 +382,9 @@ Use one directly with `policy: builtin:finance`, or write an editable copy with
|
|
|
354
382
|
|
|
355
383
|
### Policy conditions
|
|
356
384
|
|
|
357
|
-
`table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `any_change` · `diff_error` · `lineage_error`
|
|
385
|
+
`table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `changed_column` (glob) · `changed_column_tag` · `downstream_column_tag` · `any_change` · `diff_error` · `lineage_error`
|
|
386
|
+
|
|
387
|
+
**Column conditions** look only at the columns the change touched (changed values, new NULLs, dropped or retyped): `changed_column_tag: pii` matches when one of them is tagged `pii` in Unity Catalog, and `downstream_column_tag: certified` when one of them feeds a column tagged `certified`, following `system.access.column_lineage` up to `lineage.column_depth` hops (default 2; `0` turns it off). The default policy asks a human when a `pii` column changes; `strict`, `agent-safe` and `certified` also flag changes that feed certified columns.
|
|
358
388
|
|
|
359
389
|
All conditions in a `when` must hold. The most severe matching rule sets the verdict. Unknown conditions are rejected at load time, so a typo can't silently disable a rule.
|
|
360
390
|
|
|
@@ -362,12 +392,12 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
362
392
|
|
|
363
393
|
- `CAN USE` on a SQL warehouse.
|
|
364
394
|
- `SELECT` on the tables you assess and their candidates.
|
|
365
|
-
- `SELECT` on `system.access.table_lineage
|
|
395
|
+
- `SELECT` on `system.access.table_lineage` (and `system.access.column_lineage` for column-level impact), plus `system.information_schema` for owners, table tags and column tags. Without lineage access bricksentry still diffs, and adds a `lineage-unavailable` warning (blast radius unknown) instead of guessing.
|
|
366
396
|
- `CREATE TABLE` on `sandbox_schema`, for `preview_write`.
|
|
367
397
|
|
|
368
398
|
## Known limits (v0.1.x)
|
|
369
399
|
|
|
370
|
-
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping.
|
|
400
|
+
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
|
|
371
401
|
- **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
|
|
372
402
|
- **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
|
|
373
403
|
- **Validated on one Databricks workspace so far** (serverless, November 2026, on a 2-million-row table with 0.1.4): lineage, Delta rollback plans, previews on shallow clones, every verdict level, and the sampling guard catching a single changed row. The automated tests use DuckDB and a mocked SDK, so please [open an issue](https://github.com/bricksentry/bricksentry/issues) if something behaves differently on yours.
|
|
@@ -376,7 +406,7 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
376
406
|
|
|
377
407
|
**Top priority: validation across more workspaces.** Classic and serverless compute, AWS, Azure and GCP, and workspaces with restricted system-table access. If you run the quickstart notebook, please [share what you see](https://github.com/bricksentry/bricksentry/issues), whether it works or not.
|
|
378
408
|
|
|
379
|
-
Next: dbt support, so dbt models on Databricks get the same diff, blast radius and verdict (planned for 0.2) · Asset Bundle parsing for automatic table detection ·
|
|
409
|
+
Next: dbt support, so dbt models on Databricks get the same diff, blast radius and verdict (planned for 0.2) · Asset Bundle parsing for automatic table detection · an aggregate diff for keyless tables · Lakeflow expectations in the verdict · `bricksentry watch` for scheduled drift checks · a Databricks App UI.
|
|
380
410
|
|
|
381
411
|
## Contributing
|
|
382
412
|
|
|
@@ -51,7 +51,7 @@ Before a change reaches production, bricksentry answers three questions, in a
|
|
|
51
51
|
pull-request comment for humans and in structured JSON for agents:
|
|
52
52
|
|
|
53
53
|
1. **What does it do to the data?** A key-based data diff: added, removed and changed rows, schema changes, per-column changes, numeric totals, duplicate keys, and *where* the change is concentrated ("100% of affected rows are region = APAC").
|
|
54
|
-
2. **Who gets hurt?** The downstream blast radius from Unity Catalog lineage: tables, jobs, notebooks, Lakeflow pipelines, dashboards and queries, with owners and tags.
|
|
54
|
+
2. **Who gets hurt?** The downstream blast radius from Unity Catalog lineage: tables, jobs, notebooks, Lakeflow pipelines, dashboards and queries, with owners and tags. Down to the column: which columns the change touched, whether they are tagged (for example `pii`), and which downstream columns they feed.
|
|
55
55
|
3. **Is it safe, and how do I undo it?** A deterministic policy verdict (`pass` · `warn` · `needs_human` · `block`) and the exact `RESTORE TABLE … VERSION AS OF n` rollback.
|
|
56
56
|
|
|
57
57
|
For your Databricks workspace:
|
|
@@ -97,7 +97,7 @@ bricksentry is listed in the [official MCP Registry](https://registry.modelconte
|
|
|
97
97
|
|
|
98
98
|
| Tool | What the agent gets |
|
|
99
99
|
|---|---|
|
|
100
|
-
| `whats_downstream(table, depth)` | Downstream assets with owners and tags. Call it *before* editing. |
|
|
100
|
+
| `whats_downstream(table, depth, columns?)` | Downstream assets with owners and tags. Call it *before* editing. Pass the columns you'll change to see the downstream columns they feed and their tags. |
|
|
101
101
|
| `rollback_plan(table)` | The restore SQL. Capture it *before* changing anything. |
|
|
102
102
|
| `preview_write(sql, target, keys?)` | Runs one write against a **disposable shallow clone**, never production, and returns the diff plus verdict. |
|
|
103
103
|
| `assess_change(tables, candidates?, pr?)` | Diffs prod vs. the candidate built by your change, plus lineage and policy. Returns a verdict and an `id`. |
|
|
@@ -116,6 +116,17 @@ The same tools are plain Python functions in `bricksentry.agent_tools`, so you c
|
|
|
116
116
|
|
|
117
117
|
To watch the whole loop, run `bricksentry demo` (see the top of this page). `bricksentry demo --report report.md` also writes the pull-request comment a reviewer would see.
|
|
118
118
|
|
|
119
|
+
### Host it in your workspace (Databricks Apps)
|
|
120
|
+
|
|
121
|
+
Run the MCP server as a Databricks App so every agent in your workspace can reach it over HTTPS, with no tokens to manage: it runs as the app's service principal, and Unity Catalog grants decide what it can read. [`deploy/databricks-app`](deploy/databricks-app) is a ready app (`app.yaml`, an Asset Bundle, the grants) that deploys with two commands:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
databricks bundle deploy --var warehouse_id=<your-sql-warehouse-id>
|
|
125
|
+
databricks bundle run bricksentry_mcp
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Agents connect to `https://<app-url>/mcp`. The kit starts the server with `--read-only`, which leaves out `preview_write`, so the app never writes. On any other host, `bricksentry mcp --transport streamable-http --host 0.0.0.0 --port 8000` serves the same endpoint. Unity Catalog *MCP Services* are for servers hosted outside Databricks, so a Databricks App is the recommended way to run bricksentry inside it; see the [kit's README](deploy/databricks-app/README.md).
|
|
129
|
+
|
|
119
130
|
## For data engineers: CLI and CI
|
|
120
131
|
|
|
121
132
|
```bash
|
|
@@ -158,7 +169,7 @@ Check out with `fetch-depth: 0` and give the job `pull-requests: write` permissi
|
|
|
158
169
|
Or use the bundled GitHub Action, which also writes the report to the job summary:
|
|
159
170
|
|
|
160
171
|
```yaml
|
|
161
|
-
- uses: bricksentry/bricksentry@v0.1.
|
|
172
|
+
- uses: bricksentry/bricksentry@v0.1.12
|
|
162
173
|
with:
|
|
163
174
|
config: bricksentry.yml
|
|
164
175
|
fail-on: needs_human
|
|
@@ -183,7 +194,7 @@ jobs:
|
|
|
183
194
|
fetch-depth: 0
|
|
184
195
|
# Build this PR's version of your pipeline into a per-PR schema first,
|
|
185
196
|
# for example: databricks bundle deploy -t ci && databricks bundle run -t ci
|
|
186
|
-
- uses: bricksentry/bricksentry@v0.1.
|
|
197
|
+
- uses: bricksentry/bricksentry@v0.1.12
|
|
187
198
|
with:
|
|
188
199
|
config: bricksentry.yml
|
|
189
200
|
fail-on: needs_human
|
|
@@ -245,7 +256,7 @@ sandbox_schema: main.bricksentry_sandbox
|
|
|
245
256
|
candidate_pattern: "{catalog}.{schema}_pr_{pr}.{table}"
|
|
246
257
|
sample_pct: 10 # sample_guard re-checks the whole table (on by default)
|
|
247
258
|
assessment_store: ~/.bricksentry/assessments # or false to keep assessments in memory
|
|
248
|
-
lineage: {type: databricks, depth: 3, lookback_days: 90} # also: exclude, exclude_dropped
|
|
259
|
+
lineage: {type: databricks, depth: 3, lookback_days: 90, column_depth: 2} # also: exclude, exclude_dropped
|
|
249
260
|
tables:
|
|
250
261
|
main.sales.orders:
|
|
251
262
|
keys: [order_id]
|
|
@@ -255,6 +266,23 @@ tables:
|
|
|
255
266
|
policy: policy.yml # or builtin:<template>, see "Policy templates" below
|
|
256
267
|
```
|
|
257
268
|
|
|
269
|
+
**Without Unity Catalog** (local DuckDB work, tests, or other platforms), give the lineage in the config instead. Edges map a table to what reads from it; column edges and tags are optional:
|
|
270
|
+
|
|
271
|
+
```yaml
|
|
272
|
+
lineage:
|
|
273
|
+
type: static
|
|
274
|
+
edges:
|
|
275
|
+
main.sales.orders: [main.sales.daily_revenue, "dashboard:Revenue Overview", "job:finance_close"]
|
|
276
|
+
owners:
|
|
277
|
+
main.sales.daily_revenue: finance-team
|
|
278
|
+
tags:
|
|
279
|
+
main.sales.daily_revenue: {certified: "true"}
|
|
280
|
+
column_edges: # "table.column" -> downstream "table.column"s
|
|
281
|
+
main.sales.orders.amount: [main.sales.daily_revenue.revenue]
|
|
282
|
+
column_tags: # table -> column -> tags
|
|
283
|
+
main.sales.orders: {customer_email: {pii: ""}}
|
|
284
|
+
```
|
|
285
|
+
|
|
258
286
|
Typos are caught: an unknown key such as `sample_pc` prints a warning that names the right one (`did you mean 'sample_pct'?`) instead of being silently ignored.
|
|
259
287
|
|
|
260
288
|
**Which totals are checked.** `sum_change_pct_gt` rules and summaries look at measures: by default every numeric column except keys and columns whose names look like IDs, codes, years and other date parts, coordinates, ratings, scores or rates (a 10% drop in `sum(established_year)` only says rows were removed). List `measures` for a table to choose exactly, or set `measures: all` to check every numeric column. A rule that names a column (`when: {column: rating, sum_change_pct_gt: 1}`) always checks it.
|
|
@@ -307,7 +335,9 @@ Use one directly with `policy: builtin:finance`, or write an editable copy with
|
|
|
307
335
|
|
|
308
336
|
### Policy conditions
|
|
309
337
|
|
|
310
|
-
`table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `any_change` · `diff_error` · `lineage_error`
|
|
338
|
+
`table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `changed_column` (glob) · `changed_column_tag` · `downstream_column_tag` · `any_change` · `diff_error` · `lineage_error`
|
|
339
|
+
|
|
340
|
+
**Column conditions** look only at the columns the change touched (changed values, new NULLs, dropped or retyped): `changed_column_tag: pii` matches when one of them is tagged `pii` in Unity Catalog, and `downstream_column_tag: certified` when one of them feeds a column tagged `certified`, following `system.access.column_lineage` up to `lineage.column_depth` hops (default 2; `0` turns it off). The default policy asks a human when a `pii` column changes; `strict`, `agent-safe` and `certified` also flag changes that feed certified columns.
|
|
311
341
|
|
|
312
342
|
All conditions in a `when` must hold. The most severe matching rule sets the verdict. Unknown conditions are rejected at load time, so a typo can't silently disable a rule.
|
|
313
343
|
|
|
@@ -315,12 +345,12 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
315
345
|
|
|
316
346
|
- `CAN USE` on a SQL warehouse.
|
|
317
347
|
- `SELECT` on the tables you assess and their candidates.
|
|
318
|
-
- `SELECT` on `system.access.table_lineage
|
|
348
|
+
- `SELECT` on `system.access.table_lineage` (and `system.access.column_lineage` for column-level impact), plus `system.information_schema` for owners, table tags and column tags. Without lineage access bricksentry still diffs, and adds a `lineage-unavailable` warning (blast radius unknown) instead of guessing.
|
|
319
349
|
- `CREATE TABLE` on `sandbox_schema`, for `preview_write`.
|
|
320
350
|
|
|
321
351
|
## Known limits (v0.1.x)
|
|
322
352
|
|
|
323
|
-
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping.
|
|
353
|
+
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
|
|
324
354
|
- **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
|
|
325
355
|
- **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
|
|
326
356
|
- **Validated on one Databricks workspace so far** (serverless, November 2026, on a 2-million-row table with 0.1.4): lineage, Delta rollback plans, previews on shallow clones, every verdict level, and the sampling guard catching a single changed row. The automated tests use DuckDB and a mocked SDK, so please [open an issue](https://github.com/bricksentry/bricksentry/issues) if something behaves differently on yours.
|
|
@@ -329,7 +359,7 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
329
359
|
|
|
330
360
|
**Top priority: validation across more workspaces.** Classic and serverless compute, AWS, Azure and GCP, and workspaces with restricted system-table access. If you run the quickstart notebook, please [share what you see](https://github.com/bricksentry/bricksentry/issues), whether it works or not.
|
|
331
361
|
|
|
332
|
-
Next: dbt support, so dbt models on Databricks get the same diff, blast radius and verdict (planned for 0.2) · Asset Bundle parsing for automatic table detection ·
|
|
362
|
+
Next: dbt support, so dbt models on Databricks get the same diff, blast radius and verdict (planned for 0.2) · Asset Bundle parsing for automatic table detection · an aggregate diff for keyless tables · Lakeflow expectations in the verdict · `bricksentry watch` for scheduled drift checks · a Databricks App UI.
|
|
333
363
|
|
|
334
364
|
## Contributing
|
|
335
365
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Run the bricksentry MCP server as a Databricks App
|
|
2
|
+
|
|
3
|
+
Host bricksentry inside your workspace so any agent (Claude Code, Cursor, Agent Bricks, your own
|
|
4
|
+
LangGraph or OpenAI Agents SDK code) can call it over HTTPS. bricksentry runs as the app's service
|
|
5
|
+
principal: there are no tokens to manage, Unity Catalog grants decide what it can read, and access to
|
|
6
|
+
the server itself is controlled with the app's permissions. Unity AI Gateway can monitor its traffic
|
|
7
|
+
next to your other MCP servers.
|
|
8
|
+
|
|
9
|
+
This folder is a complete app:
|
|
10
|
+
|
|
11
|
+
| File | What it is |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `app.yaml` | Starts `bricksentry mcp --transport streamable-http --read-only`. bricksentry listens on `0.0.0.0:$DATABRICKS_APP_PORT` by itself. |
|
|
14
|
+
| `requirements.txt` | The pinned bricksentry release. |
|
|
15
|
+
| `bricksentry.yml` | Backend, policy (`builtin:agent-safe`) and the tables agents may check. **Edit `tables:` first.** |
|
|
16
|
+
| `databricks.yml` | Asset Bundle that creates the app with a SQL warehouse resource. |
|
|
17
|
+
| `grants.sql` | The Unity Catalog grants for the app's service principal. |
|
|
18
|
+
|
|
19
|
+
## Deploy (about 10 minutes)
|
|
20
|
+
|
|
21
|
+
You need the [Databricks CLI](https://docs.databricks.com/dev-tools/cli/) logged in to your workspace,
|
|
22
|
+
permission to create apps, and a SQL warehouse ID.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# 1. Copy this folder and edit bricksentry.yml: list your tables and their keys.
|
|
26
|
+
cp -r deploy/databricks-app my-bricksentry-app && cd my-bricksentry-app
|
|
27
|
+
|
|
28
|
+
# 2. Create and start the app.
|
|
29
|
+
databricks bundle deploy --var warehouse_id=<your-sql-warehouse-id>
|
|
30
|
+
databricks bundle run bricksentry_mcp
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
3. **Grant access.** Open the app in **Compute → Apps → mcp-bricksentry**, copy its service principal's
|
|
34
|
+
application ID, replace `<app-sp>` in `grants.sql`, and run it in the SQL editor.
|
|
35
|
+
4. **Check it.** The app page shows the URL. The MCP endpoint is `https://<app-url>/mcp`. The app log
|
|
36
|
+
should show `bricksentry MCP server (streamable-http, read-only) on http://0.0.0.0:<port>/mcp`.
|
|
37
|
+
|
|
38
|
+
Without the bundle: create an app in the UI (**Compute → Apps → Create app → Custom**), add a SQL
|
|
39
|
+
warehouse resource with the key `sql-warehouse` and **Can use**, then `databricks sync . <workspace-path>` and
|
|
40
|
+
`databricks apps deploy mcp-bricksentry --source-code-path <workspace-path>`.
|
|
41
|
+
|
|
42
|
+
## Connect an agent
|
|
43
|
+
|
|
44
|
+
Databricks Apps sit behind workspace sign-in, so clients send a Databricks OAuth token.
|
|
45
|
+
|
|
46
|
+
**Agent code in Databricks** (recommended), with `pip install databricks-mcp`:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from databricks.sdk import WorkspaceClient
|
|
50
|
+
from databricks_mcp import DatabricksMCPClient
|
|
51
|
+
|
|
52
|
+
client = DatabricksMCPClient(server_url="https://<app-url>/mcp", workspace_client=WorkspaceClient())
|
|
53
|
+
print([t.name for t in client.list_tools()])
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Claude Code or another HTTP client** on your laptop:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
TOKEN=$(databricks auth token --host https://<workspace-host> | jq -r .access_token)
|
|
60
|
+
claude mcp add --transport http bricksentry https://<app-url>/mcp --header "Authorization: Bearer $TOKEN"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
OAuth tokens expire after about an hour; refresh with the same command. Give each agent identity
|
|
64
|
+
**Can use** on the app (app page → Permissions).
|
|
65
|
+
|
|
66
|
+
## Read-only or previews
|
|
67
|
+
|
|
68
|
+
`--read-only` (the default here) leaves out `preview_write`, so the app only reads: agents use
|
|
69
|
+
`whats_downstream`, `rollback_plan`, `assess_change`, `explain_diff` and `safe_to_ship`. To let agents
|
|
70
|
+
preview a write on a disposable shallow clone, remove `--read-only` from `app.yaml` and run the
|
|
71
|
+
sandbox grants at the end of `grants.sql`.
|
|
72
|
+
|
|
73
|
+
## Unity Catalog MCP Services
|
|
74
|
+
|
|
75
|
+
Unity Catalog can register an MCP server as an *MCP Service* governed by Unity AI Gateway, but that is
|
|
76
|
+
for servers hosted outside Databricks: apps on Databricks Apps can't be registered as MCP Services, and
|
|
77
|
+
Databricks says to connect to them directly instead. For bricksentry, the app above is the
|
|
78
|
+
recommended setup. If you do host it elsewhere, it needs a public HTTPS URL with Streamable HTTP, and
|
|
79
|
+
its own Databricks credentials for the SQL warehouse; see
|
|
80
|
+
[Register an external MCP server](https://docs.databricks.com/aws/en/ai-gateway/register-mcp-service).
|
|
81
|
+
|
|
82
|
+
## Notes
|
|
83
|
+
|
|
84
|
+
- Saved assessments live in `/tmp` inside the app, so `safe_to_ship` and `explain_diff` find an
|
|
85
|
+
assessment from the same app instance. Call them right after `assess_change`, as agents normally do.
|
|
86
|
+
- Every check runs as the app's service principal, so all callers see what that principal can read.
|
|
87
|
+
Grant it only the schemas agents should check.
|
|
88
|
+
- App compute is billed at Databricks Apps rates.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bricksentry"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.12"
|
|
8
8
|
description = "Change-safety for Databricks pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -56,27 +56,42 @@ def _safe(fn):
|
|
|
56
56
|
def whats_downstream(
|
|
57
57
|
table: Annotated[str, _desc("Fully qualified table name, e.g. main.sales.orders.")],
|
|
58
58
|
depth: Annotated[int, _desc("How many lineage hops to follow downstream (default 3).")] = 3,
|
|
59
|
+
columns: Annotated[
|
|
60
|
+
list[str] | None,
|
|
61
|
+
_desc("Optional columns you plan to change, e.g. ['email']. Adds the downstream columns they feed, "
|
|
62
|
+
"with their tags, and the tags on these columns."),
|
|
63
|
+
] = None,
|
|
59
64
|
) -> dict[str, Any]:
|
|
60
65
|
"""List what depends on a table, so you know the blast radius BEFORE you edit it.
|
|
61
66
|
|
|
62
67
|
Use this first, when planning a change. It reads Unity Catalog lineage and
|
|
63
68
|
returns every downstream table, job, notebook, pipeline, dashboard and query,
|
|
64
69
|
up to `depth` hops, with owners and tags. Dropped tables are filtered out.
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
Pass `columns` when you will change specific columns to see the downstream
|
|
71
|
+
columns they feed (column lineage) and whether any carry tags such as pii or
|
|
72
|
+
certified. Read-only; changes nothing. To check a change you have already
|
|
73
|
+
made, use assess_change instead.
|
|
67
74
|
|
|
68
75
|
Returns {table, owner, tags, count, downstream: [{kind, name, depth, via,
|
|
69
|
-
owner, tags}]},
|
|
76
|
+
owner, tags}]}, plus {column_tags, column_downstream: [{source_column, table,
|
|
77
|
+
column, depth, tags}]} when `columns` is given, or {error} if the table or
|
|
78
|
+
lineage cannot be read."""
|
|
70
79
|
s = get_sentry()
|
|
71
80
|
nodes = s.downstream(table, depth)
|
|
72
81
|
owner, tags = s.lineage.owner_and_tags(table)
|
|
73
|
-
|
|
82
|
+
out: dict[str, Any] = {
|
|
74
83
|
"table": table,
|
|
75
84
|
"owner": owner,
|
|
76
85
|
"tags": tags,
|
|
77
86
|
"count": len(nodes),
|
|
78
87
|
"downstream": [n.to_dict() for n in nodes],
|
|
79
88
|
}
|
|
89
|
+
if columns:
|
|
90
|
+
col_tags = s.lineage.column_tags(table)
|
|
91
|
+
out["column_tags"] = {c: col_tags[c] for c in columns if col_tags.get(c)}
|
|
92
|
+
feeds = s.lineage.column_downstream(table, list(columns), int(s.config.lineage.get("column_depth", 2)))
|
|
93
|
+
out["column_downstream"] = [c.to_dict() for c in feeds]
|
|
94
|
+
return out
|
|
80
95
|
|
|
81
96
|
|
|
82
97
|
@_safe
|
|
@@ -103,6 +118,7 @@ def assess_change(
|
|
|
103
118
|
|
|
104
119
|
Returns {id, verdict: pass|warn|needs_human|block, risk_tier, safe_to_ship,
|
|
105
120
|
notify, rule_hits, tables: [{table, verdict, summary, diff, downstream,
|
|
121
|
+
changed_columns, column_tags, column_downstream,
|
|
106
122
|
rollback}]}. Pass `id` to safe_to_ship (and optionally explain_diff)."""
|
|
107
123
|
a = get_sentry().assess(list(tables), candidates=candidates, pr=pr)
|
|
108
124
|
return a.to_dict()
|
|
@@ -10,10 +10,10 @@ from typing import Any
|
|
|
10
10
|
from bricksentry.backends.base import Backend, make_backend
|
|
11
11
|
from bricksentry.config import Config
|
|
12
12
|
from bricksentry.diff import diff_tables
|
|
13
|
-
from bricksentry.explain import explain_diff, explain_impact
|
|
13
|
+
from bricksentry.explain import explain_columns, explain_diff, explain_impact
|
|
14
14
|
from bricksentry.lineage import LineageProvider, make_lineage
|
|
15
15
|
from bricksentry.models import Assessment, ImpactNode, TableAssessment, TableDiff, Verdict
|
|
16
|
-
from bricksentry.policy import Policy
|
|
16
|
+
from bricksentry.policy import ColumnContext, Policy
|
|
17
17
|
from bricksentry.preview import rewrite_for_preview, sandbox_name
|
|
18
18
|
|
|
19
19
|
|
|
@@ -104,13 +104,14 @@ class Sentry:
|
|
|
104
104
|
lineage_err = _first_line(e)
|
|
105
105
|
owner, tags = self.lineage.owner_and_tags(table)
|
|
106
106
|
measures = self.config.spec(table).measures
|
|
107
|
+
cols, col_note = self._column_context(table, diff)
|
|
107
108
|
verdict, hits = self.policy.evaluate(
|
|
108
|
-
table, diff, nodes, tags, diff_error=err, measures=measures, lineage_error=lineage_err
|
|
109
|
+
table, diff, nodes, tags, diff_error=err, measures=measures, lineage_error=lineage_err, columns=cols
|
|
109
110
|
)
|
|
110
111
|
summary = (explain_diff(diff, measures) if diff else f"{table}: diff unavailable ({err}).") + " " + (
|
|
111
112
|
f"{table}: blast radius unknown, lineage lookup failed ({lineage_err})."
|
|
112
113
|
if lineage_err else explain_impact(table, nodes)
|
|
113
|
-
)
|
|
114
|
+
) + explain_columns(cols, col_note)
|
|
114
115
|
ta = TableAssessment(
|
|
115
116
|
table=table,
|
|
116
117
|
diff=diff,
|
|
@@ -121,6 +122,9 @@ class Sentry:
|
|
|
121
122
|
verdict=verdict,
|
|
122
123
|
hits=hits,
|
|
123
124
|
summary=summary,
|
|
125
|
+
changed_columns=cols.changed,
|
|
126
|
+
column_tags={c: cols.tags[c] for c in cols.changed if cols.tags.get(c)},
|
|
127
|
+
column_downstream=cols.downstream,
|
|
124
128
|
)
|
|
125
129
|
results.append(ta)
|
|
126
130
|
if verdict.rank >= self.policy.notify_on.rank:
|
|
@@ -139,6 +143,27 @@ class Sentry:
|
|
|
139
143
|
self._save(a)
|
|
140
144
|
return a
|
|
141
145
|
|
|
146
|
+
def _column_context(self, table: str, diff: TableDiff | None) -> tuple[ColumnContext, str | None]:
|
|
147
|
+
"""Which columns changed, their tags, and the downstream columns they feed.
|
|
148
|
+
Lookups that fail leave that part empty and return a one-line note."""
|
|
149
|
+
changed = changed_columns(diff)
|
|
150
|
+
if not changed:
|
|
151
|
+
return ColumnContext(), None
|
|
152
|
+
notes: list[str] = []
|
|
153
|
+
col_tags: dict[str, dict[str, str]] = {}
|
|
154
|
+
feeds: list = []
|
|
155
|
+
try:
|
|
156
|
+
col_tags = self.lineage.column_tags(table)
|
|
157
|
+
except Exception as e: # e.g. no access to information_schema.column_tags
|
|
158
|
+
notes.append(f"column tags unavailable ({_first_line(e)})")
|
|
159
|
+
try:
|
|
160
|
+
depth = int(self.config.lineage.get("column_depth", 2))
|
|
161
|
+
if depth > 0:
|
|
162
|
+
feeds = self.lineage.column_downstream(table, changed, depth)
|
|
163
|
+
except Exception as e: # e.g. no SELECT on system.access.column_lineage
|
|
164
|
+
notes.append(f"column lineage unavailable ({_first_line(e)})")
|
|
165
|
+
return ColumnContext(changed, col_tags, feeds), "; ".join(notes) or None
|
|
166
|
+
|
|
142
167
|
# --- saved assessments -------------------------------------------------
|
|
143
168
|
def _save(self, a: Assessment) -> None:
|
|
144
169
|
"""Save an assessment as JSON so another Sentry (another process, the MCP
|
|
@@ -216,3 +241,17 @@ def _first_line(e: Exception, limit: int = 200) -> str:
|
|
|
216
241
|
"""A short, single-line error for verdict reasons and alerts."""
|
|
217
242
|
text = (str(e).strip().splitlines() or [type(e).__name__])[0]
|
|
218
243
|
return text if len(text) <= limit else text[: limit - 1] + "…"
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def changed_columns(diff: TableDiff | None) -> list[str]:
|
|
247
|
+
"""Columns a change touched: changed values, dropped or retyped, or new NULLs."""
|
|
248
|
+
if diff is None or diff.error:
|
|
249
|
+
return []
|
|
250
|
+
out: list[str] = []
|
|
251
|
+
for c in diff.columns:
|
|
252
|
+
if c.changed_rows or (
|
|
253
|
+
c.base_nulls is not None and c.candidate_nulls is not None and c.candidate_nulls > c.base_nulls
|
|
254
|
+
):
|
|
255
|
+
out.append(c.column)
|
|
256
|
+
out += list(diff.schema.removed) + list(diff.schema.type_changed)
|
|
257
|
+
return list(dict.fromkeys(out))
|
|
@@ -43,7 +43,10 @@ class DatabricksBackend(Backend):
|
|
|
43
43
|
from databricks.sdk import WorkspaceClient
|
|
44
44
|
except ImportError as e: # pragma: no cover
|
|
45
45
|
raise ImportError("Databricks backend needs `pip install bricksentry[databricks]`") from e
|
|
46
|
-
|
|
46
|
+
try:
|
|
47
|
+
client = WorkspaceClient(profile=profile) if profile else WorkspaceClient()
|
|
48
|
+
except Exception as e:
|
|
49
|
+
raise ValueError(_auth_help(e, profile)) from None
|
|
47
50
|
self.client = client
|
|
48
51
|
self.timeout_s = timeout_s
|
|
49
52
|
|
|
@@ -140,6 +143,21 @@ class DatabricksBackend(Backend):
|
|
|
140
143
|
return int(v) if v is not None else None
|
|
141
144
|
|
|
142
145
|
|
|
146
|
+
def _auth_help(e: Exception, profile: str | None) -> str:
|
|
147
|
+
"""One clear message when the Databricks SDK can't find credentials.
|
|
148
|
+
|
|
149
|
+
The SDK's own errors can be long or cryptic: for example a CLI started as a subprocess
|
|
150
|
+
of a notebook fails inside the notebook-auth code with a `parent_header` error."""
|
|
151
|
+
detail = (str(e).strip().splitlines() or [type(e).__name__])[0][:200]
|
|
152
|
+
what = f"credentials for profile {profile!r} in ~/.databrickscfg" if profile else "Databricks credentials"
|
|
153
|
+
return (
|
|
154
|
+
f"Could not sign in to Databricks: no usable {what} were found ({detail}). "
|
|
155
|
+
"Set DATABRICKS_HOST plus DATABRICKS_TOKEN (or DATABRICKS_CLIENT_ID and DATABRICKS_CLIENT_SECRET), "
|
|
156
|
+
"or run `databricks auth login`. In a notebook, use the Python API (from bricksentry import Sentry) "
|
|
157
|
+
"instead of calling the CLI in a subprocess, which can't use the notebook's credentials."
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
143
161
|
def _state(resp: Any) -> str:
|
|
144
162
|
st = getattr(getattr(resp, "status", None), "state", None)
|
|
145
163
|
return getattr(st, "value", st) or "UNKNOWN"
|
|
@@ -202,15 +202,24 @@ def rollback(table, config_path):
|
|
|
202
202
|
|
|
203
203
|
|
|
204
204
|
@main.command()
|
|
205
|
-
@click.option("--transport", type=click.Choice(["stdio", "sse", "streamable-http"]), default="stdio"
|
|
205
|
+
@click.option("--transport", type=click.Choice(["stdio", "sse", "streamable-http"]), default="stdio",
|
|
206
|
+
show_default=True, help="stdio for local agents; streamable-http to serve over HTTP (e.g. Databricks Apps)")
|
|
207
|
+
@click.option("--host", default=None,
|
|
208
|
+
help="HTTP only. Default 127.0.0.1, or 0.0.0.0 on Databricks Apps. Env: BRICKSENTRY_HOST")
|
|
209
|
+
@click.option("--port", type=int, default=None,
|
|
210
|
+
help="HTTP only. Default 8000, or $DATABRICKS_APP_PORT on Databricks Apps. Env: BRICKSENTRY_PORT")
|
|
211
|
+
@click.option("--read-only", is_flag=True, default=False,
|
|
212
|
+
help="Leave out preview_write, so the server never writes, not even to a sandbox clone. "
|
|
213
|
+
"Env: BRICKSENTRY_READ_ONLY=1")
|
|
206
214
|
@config_opt
|
|
207
|
-
def mcp(transport, config_path):
|
|
215
|
+
def mcp(transport, host, port, read_only, config_path):
|
|
208
216
|
"""Start the MCP server for AI agents."""
|
|
209
217
|
if config_path:
|
|
210
218
|
os.environ["BRICKSENTRY_CONFIG"] = str(Path(config_path).resolve())
|
|
219
|
+
read_only = read_only or os.environ.get("BRICKSENTRY_READ_ONLY", "").strip().lower() in ("1", "true", "yes")
|
|
211
220
|
from bricksentry.mcp_server import serve
|
|
212
221
|
|
|
213
|
-
serve(transport)
|
|
222
|
+
serve(transport, host=host, port=port, read_only=read_only)
|
|
214
223
|
|
|
215
224
|
|
|
216
225
|
_INIT_CONFIG = """# bricksentry configuration
|
|
@@ -259,6 +268,7 @@ rules:
|
|
|
259
268
|
- {name: type-change, when: {column_type_changed: true}, then: warn}
|
|
260
269
|
- {name: certified-downstream, when: {downstream_tag: certified}, then: needs_human}
|
|
261
270
|
- {name: pii-table, when: {tag: pii}, then: needs_human}
|
|
271
|
+
- {name: pii-column-changed, when: {changed_column_tag: pii}, then: needs_human}
|
|
262
272
|
- {name: row-loss, when: {removed_pct_gt: 1}, then: needs_human}
|
|
263
273
|
- {name: many-rows-changed, when: {changed_pct_gt: 10}, then: warn}
|
|
264
274
|
- {name: numeric-total-moved, when: {sum_change_pct_gt: 5}, then: warn}
|
|
@@ -45,7 +45,11 @@ TOP_LEVEL_KEYS = {
|
|
|
45
45
|
}
|
|
46
46
|
TABLE_KEYS = {"keys", "key", "segment_by", "paths", "candidate", "measures"}
|
|
47
47
|
NOTIFY_KEYS = {"on", "slack_webhook", "teams_webhook", "mentions", "run_url"}
|
|
48
|
-
LINEAGE_KEYS = {
|
|
48
|
+
LINEAGE_KEYS = {
|
|
49
|
+
"type", "depth", "lookback_days", "lineage_table", "tables_table", "tags_table", "max_nodes",
|
|
50
|
+
"exclude", "exclude_dropped", "edges", "owners", "tags",
|
|
51
|
+
"column_depth", "column_lineage_table", "column_tags_table", "column_edges", "column_tags",
|
|
52
|
+
}
|
|
49
53
|
|
|
50
54
|
|
|
51
55
|
def _unknown(where: str, given: Any, known: set[str]) -> list[str]:
|