bricksentry 0.1.8__tar.gz → 0.1.11__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.
Files changed (60) hide show
  1. {bricksentry-0.1.8 → bricksentry-0.1.11}/CHANGELOG.md +21 -0
  2. {bricksentry-0.1.8 → bricksentry-0.1.11}/PKG-INFO +27 -5
  3. {bricksentry-0.1.8 → bricksentry-0.1.11}/README.md +26 -4
  4. bricksentry-0.1.11/deploy/databricks-app/README.md +88 -0
  5. bricksentry-0.1.11/examples/databricks/bricksentry_check_my_table.ipynb +311 -0
  6. bricksentry-0.1.11/examples/databricks/bricksentry_check_my_table.py +233 -0
  7. {bricksentry-0.1.8 → bricksentry-0.1.11}/pyproject.toml +1 -1
  8. {bricksentry-0.1.8 → bricksentry-0.1.11}/scripts/build_notebook.py +12 -7
  9. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/__init__.py +1 -1
  10. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/assess.py +16 -4
  11. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/backends/databricks_backend.py +19 -1
  12. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/cli.py +12 -3
  13. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/config.py +4 -1
  14. bricksentry-0.1.11/src/bricksentry/mcp_server.py +110 -0
  15. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/policy.py +10 -2
  16. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/policy_templates.py +5 -0
  17. bricksentry-0.1.11/tests/test_0110.py +211 -0
  18. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_018.py +2 -1
  19. bricksentry-0.1.11/tests/test_019.py +57 -0
  20. bricksentry-0.1.11/tests/test_check_notebook.py +153 -0
  21. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_notify_templates.py +1 -1
  22. bricksentry-0.1.8/src/bricksentry/mcp_server.py +0 -55
  23. {bricksentry-0.1.8 → bricksentry-0.1.11}/.gitignore +0 -0
  24. {bricksentry-0.1.8 → bricksentry-0.1.11}/CONTRIBUTING.md +0 -0
  25. {bricksentry-0.1.8 → bricksentry-0.1.11}/LICENSE +0 -0
  26. {bricksentry-0.1.8 → bricksentry-0.1.11}/SECURITY.md +0 -0
  27. {bricksentry-0.1.8 → bricksentry-0.1.11}/action.yml +0 -0
  28. {bricksentry-0.1.8 → bricksentry-0.1.11}/examples/databricks/bricksentry.yml +0 -0
  29. {bricksentry-0.1.8 → bricksentry-0.1.11}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
  30. {bricksentry-0.1.8 → bricksentry-0.1.11}/examples/databricks/bricksentry_quickstart.py +0 -0
  31. {bricksentry-0.1.8 → bricksentry-0.1.11}/examples/databricks/github-workflow.yml +0 -0
  32. {bricksentry-0.1.8 → bricksentry-0.1.11}/examples/databricks/policy.yml +0 -0
  33. {bricksentry-0.1.8 → bricksentry-0.1.11}/examples/demo/agent_loop_demo.py +0 -0
  34. {bricksentry-0.1.8 → bricksentry-0.1.11}/packages/bricksentry-mcp/LICENSE +0 -0
  35. {bricksentry-0.1.8 → bricksentry-0.1.11}/packages/bricksentry-mcp/README.md +0 -0
  36. {bricksentry-0.1.8 → bricksentry-0.1.11}/packages/bricksentry-mcp/src/bricksentry_mcp/__init__.py +0 -0
  37. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/agent_tools.py +0 -0
  38. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/backends/__init__.py +0 -0
  39. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/backends/base.py +0 -0
  40. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/backends/duckdb_backend.py +0 -0
  41. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/changes.py +0 -0
  42. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/demo.py +0 -0
  43. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/diff.py +0 -0
  44. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/explain.py +0 -0
  45. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/github.py +0 -0
  46. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/lineage.py +0 -0
  47. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/measures.py +0 -0
  48. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/models.py +0 -0
  49. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/notify.py +0 -0
  50. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/preview.py +0 -0
  51. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/py.typed +0 -0
  52. {bricksentry-0.1.8 → bricksentry-0.1.11}/src/bricksentry/report.py +0 -0
  53. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/conftest.py +0 -0
  54. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_assess_policy.py +0 -0
  55. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_databricks_and_uc.py +0 -0
  56. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_demo.py +0 -0
  57. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_diff.py +0 -0
  58. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_notebook.py +0 -0
  59. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_preview_agents.py +0 -0
  60. {bricksentry-0.1.8 → bricksentry-0.1.11}/tests/test_sample_guard_and_store.py +0 -0
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.11 (2026-11-11)
4
+
5
+ From a full live test of 0.1.9 on Databricks serverless:
6
+
7
+ - 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.
8
+ - The `lineage.type` false warning that test also found was already fixed in 0.1.10.
9
+
10
+ ## 0.1.10 (2026-11-11)
11
+
12
+ - **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`.
13
+ - `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.
14
+ - New `--read-only` (or `BRICKSENTRY_READ_ONLY=1`) leaves out `preview_write`, so a shared server never writes, not even to a sandbox clone.
15
+ - 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.
16
+ - 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.
17
+
18
+ ## 0.1.9 (2026-11-11)
19
+
20
+ - 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`.
21
+ - New issue form, "What bricksentry found", for sharing what a check caught, missed or got wrong. The notebook prefills it without table or column names.
22
+ - Fix: when the lineage lookup failed (for example no `SELECT` on `system.access.table_lineage`), the verdict said "diff could not run" and was raised to `needs_human`, although the diff had run. Now it adds a `lineage-unavailable` hit with a one-line reason and the summary says the blast radius is unknown. It is a `warn` in the default and finance policies and `needs_human` in strict, agent-safe, pii and certified. New policy condition: `lineage_error`.
23
+
3
24
  ## 0.1.8 (2026-11-11)
4
25
 
5
26
  From the first real Slack alert sent from a Databricks workspace:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bricksentry
3
- Version: 0.1.8
3
+ Version: 0.1.11
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
@@ -74,6 +74,17 @@ An AI agent changes a 20,000-row revenue table. bricksentry previews its DELETE
74
74
 
75
75
  ## Run it in your Databricks workspace
76
76
 
77
+ ### What did your last pipeline run do? (10 minutes, read-only)
78
+
79
+ > **Check-my-table notebook:** in your workspace, go to **Workspace → Import → URL** and paste
80
+ > `https://raw.githubusercontent.com/bricksentry/bricksentry/main/examples/databricks/bricksentry_check_my_table.py`
81
+
82
+ Point the [check-my-table notebook](examples/databricks/bricksentry_check_my_table.py) at a Delta table your pipeline writes to. It finds the latest data change in the table's history (a WRITE, MERGE, UPDATE or DELETE), compares it with the version before, and shows the verdict a reviewer would have seen before that change shipped: rows added, removed and changed, duplicate keys, totals that moved, what depends on the table, and the `RESTORE` command to undo it. Your table is only read; the comparison uses two shallow clones in a scratch schema, dropped at the end.
83
+
84
+ If it shows you something, please [share what it found](https://github.com/bricksentry/bricksentry/issues/new?template=it_caught_this.yml) (no table names needed). Real results decide what gets built next.
85
+
86
+ ### Guided tour on demo data
87
+
77
88
  > **Databricks quickstart notebook:** in your workspace, go to **Workspace → Import → URL** and paste
78
89
  > `https://raw.githubusercontent.com/bricksentry/bricksentry/main/examples/databricks/bricksentry_quickstart.py`
79
90
 
@@ -152,6 +163,17 @@ The same tools are plain Python functions in `bricksentry.agent_tools`, so you c
152
163
 
153
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.
154
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
+
155
177
  ## For data engineers: CLI and CI
156
178
 
157
179
  ```bash
@@ -194,7 +216,7 @@ Check out with `fetch-depth: 0` and give the job `pull-requests: write` permissi
194
216
  Or use the bundled GitHub Action, which also writes the report to the job summary:
195
217
 
196
218
  ```yaml
197
- - uses: bricksentry/bricksentry@v0.1.8
219
+ - uses: bricksentry/bricksentry@v0.1.11
198
220
  with:
199
221
  config: bricksentry.yml
200
222
  fail-on: needs_human
@@ -219,7 +241,7 @@ jobs:
219
241
  fetch-depth: 0
220
242
  # Build this PR's version of your pipeline into a per-PR schema first,
221
243
  # for example: databricks bundle deploy -t ci && databricks bundle run -t ci
222
- - uses: bricksentry/bricksentry@v0.1.8
244
+ - uses: bricksentry/bricksentry@v0.1.11
223
245
  with:
224
246
  config: bricksentry.yml
225
247
  fail-on: needs_human
@@ -343,7 +365,7 @@ Use one directly with `policy: builtin:finance`, or write an editable copy with
343
365
 
344
366
  ### Policy conditions
345
367
 
346
- `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`
368
+ `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`
347
369
 
348
370
  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.
349
371
 
@@ -351,7 +373,7 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
351
373
 
352
374
  - `CAN USE` on a SQL warehouse.
353
375
  - `SELECT` on the tables you assess and their candidates.
354
- - `SELECT` on `system.access.table_lineage`, plus `system.information_schema` for owners and tags. Without these, bricksentry still diffs; lineage is just empty.
376
+ - `SELECT` on `system.access.table_lineage`, plus `system.information_schema` for owners and tags. Without lineage access bricksentry still diffs, and adds a `lineage-unavailable` warning (blast radius unknown) instead of guessing.
355
377
  - `CREATE TABLE` on `sandbox_schema`, for `preview_write`.
356
378
 
357
379
  ## Known limits (v0.1.x)
@@ -27,6 +27,17 @@ An AI agent changes a 20,000-row revenue table. bricksentry previews its DELETE
27
27
 
28
28
  ## Run it in your Databricks workspace
29
29
 
30
+ ### What did your last pipeline run do? (10 minutes, read-only)
31
+
32
+ > **Check-my-table notebook:** in your workspace, go to **Workspace → Import → URL** and paste
33
+ > `https://raw.githubusercontent.com/bricksentry/bricksentry/main/examples/databricks/bricksentry_check_my_table.py`
34
+
35
+ Point the [check-my-table notebook](examples/databricks/bricksentry_check_my_table.py) at a Delta table your pipeline writes to. It finds the latest data change in the table's history (a WRITE, MERGE, UPDATE or DELETE), compares it with the version before, and shows the verdict a reviewer would have seen before that change shipped: rows added, removed and changed, duplicate keys, totals that moved, what depends on the table, and the `RESTORE` command to undo it. Your table is only read; the comparison uses two shallow clones in a scratch schema, dropped at the end.
36
+
37
+ If it shows you something, please [share what it found](https://github.com/bricksentry/bricksentry/issues/new?template=it_caught_this.yml) (no table names needed). Real results decide what gets built next.
38
+
39
+ ### Guided tour on demo data
40
+
30
41
  > **Databricks quickstart notebook:** in your workspace, go to **Workspace → Import → URL** and paste
31
42
  > `https://raw.githubusercontent.com/bricksentry/bricksentry/main/examples/databricks/bricksentry_quickstart.py`
32
43
 
@@ -105,6 +116,17 @@ The same tools are plain Python functions in `bricksentry.agent_tools`, so you c
105
116
 
106
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.
107
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
+
108
130
  ## For data engineers: CLI and CI
109
131
 
110
132
  ```bash
@@ -147,7 +169,7 @@ Check out with `fetch-depth: 0` and give the job `pull-requests: write` permissi
147
169
  Or use the bundled GitHub Action, which also writes the report to the job summary:
148
170
 
149
171
  ```yaml
150
- - uses: bricksentry/bricksentry@v0.1.8
172
+ - uses: bricksentry/bricksentry@v0.1.11
151
173
  with:
152
174
  config: bricksentry.yml
153
175
  fail-on: needs_human
@@ -172,7 +194,7 @@ jobs:
172
194
  fetch-depth: 0
173
195
  # Build this PR's version of your pipeline into a per-PR schema first,
174
196
  # for example: databricks bundle deploy -t ci && databricks bundle run -t ci
175
- - uses: bricksentry/bricksentry@v0.1.8
197
+ - uses: bricksentry/bricksentry@v0.1.11
176
198
  with:
177
199
  config: bricksentry.yml
178
200
  fail-on: needs_human
@@ -296,7 +318,7 @@ Use one directly with `policy: builtin:finance`, or write an editable copy with
296
318
 
297
319
  ### Policy conditions
298
320
 
299
- `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`
321
+ `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`
300
322
 
301
323
  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.
302
324
 
@@ -304,7 +326,7 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
304
326
 
305
327
  - `CAN USE` on a SQL warehouse.
306
328
  - `SELECT` on the tables you assess and their candidates.
307
- - `SELECT` on `system.access.table_lineage`, plus `system.information_schema` for owners and tags. Without these, bricksentry still diffs; lineage is just empty.
329
+ - `SELECT` on `system.access.table_lineage`, plus `system.information_schema` for owners and tags. Without lineage access bricksentry still diffs, and adds a `lineage-unavailable` warning (blast radius unknown) instead of guessing.
308
330
  - `CREATE TABLE` on `sandbox_schema`, for `preview_write`.
309
331
 
310
332
  ## Known limits (v0.1.x)
@@ -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.
@@ -0,0 +1,311 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# What did my last pipeline run do? Check one of your tables with bricksentry\n",
8
+ "\n",
9
+ "**10 minutes, on your real data, without changing it.** Pick a Delta table that a pipeline writes to.\n",
10
+ "bricksentry finds its most recent data change in the Delta history (a WRITE, MERGE, UPDATE or DELETE) and shows\n",
11
+ "what a reviewer would have seen *before* that change shipped:\n",
12
+ "\n",
13
+ "- rows added, removed and changed, duplicate or NULL keys, schema changes, and totals that moved\n",
14
+ "- what depends on the table (Unity Catalog lineage), with owners and tags such as `certified` or `pii`\n",
15
+ "- a verdict from a policy (`pass`, `warn`, `needs_human` or `block`), and the `RESTORE` command to undo it\n",
16
+ "\n",
17
+ "**How it stays safe:** your table is only read. To compare two versions, the notebook makes two *shallow clones*\n",
18
+ "(metadata only, no data copied) in a scratch schema you choose, and drops them at the end.\n",
19
+ "\n",
20
+ "**You need:** a SQL warehouse you can use, `SELECT` on the table, `CREATE TABLE` on the scratch schema, and for the\n",
21
+ "blast radius `SELECT` on `system.access.table_lineage`. The table's history must still be there (not removed by `VACUUM`).\n",
22
+ "\n",
23
+ "If it shows you something useful, or something wrong, please [tell us](https://github.com/bricksentry/bricksentry/issues/new?template=it_caught_this.yml).\n",
24
+ "Docs: [bricksentry.org](https://bricksentry.org)"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": null,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "%pip install --quiet --upgrade \"bricksentry[databricks]\""
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": null,
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "dbutils.library.restartPython()"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "markdown",
47
+ "metadata": {},
48
+ "source": [
49
+ "## Settings\n",
50
+ "Fill in the widgets at the top, then run all cells.\n",
51
+ "- **table:** `catalog.schema.table`, a Delta table your pipeline writes to.\n",
52
+ "- **keys:** the column(s) that identify a row, comma-separated (e.g. `order_id` or `customer_id, day`). Leave empty to use the table's primary key if it has one.\n",
53
+ "- **warehouse_id:** SQL Warehouses → your warehouse → Connection details.\n",
54
+ "- **scratch_schema:** `catalog.schema` for the two temporary clones. It is created if missing.\n",
55
+ "- **version:** leave empty to check the latest data change, or enter a table version number to check that one.\n",
56
+ "- **policy:** the rule set for the verdict (`default`, `strict`, `finance`, `pii`, `certified`, `agent-safe`).\n",
57
+ "- **sample_pct:** leave empty for a full comparison; on very large tables try `10` (a full-table checksum still catches any change the sample misses)."
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": null,
63
+ "metadata": {},
64
+ "outputs": [],
65
+ "source": [
66
+ "import re\n",
67
+ "\n",
68
+ "dbutils.widgets.text(\"table\", \"\")\n",
69
+ "dbutils.widgets.text(\"keys\", \"\")\n",
70
+ "dbutils.widgets.text(\"warehouse_id\", \"\")\n",
71
+ "dbutils.widgets.text(\"scratch_schema\", \"main.bricksentry_scratch\")\n",
72
+ "dbutils.widgets.text(\"version\", \"\")\n",
73
+ "dbutils.widgets.dropdown(\"policy\", \"default\", [\"default\", \"strict\", \"finance\", \"pii\", \"certified\", \"agent-safe\"])\n",
74
+ "dbutils.widgets.text(\"sample_pct\", \"\")\n",
75
+ "\n",
76
+ "TABLE = dbutils.widgets.get(\"table\").strip()\n",
77
+ "KEYS = [k.strip() for k in dbutils.widgets.get(\"keys\").split(\",\") if k.strip()]\n",
78
+ "WAREHOUSE_ID = dbutils.widgets.get(\"warehouse_id\").strip()\n",
79
+ "SCRATCH = dbutils.widgets.get(\"scratch_schema\").strip()\n",
80
+ "VERSION = dbutils.widgets.get(\"version\").strip()\n",
81
+ "POLICY = dbutils.widgets.get(\"policy\")\n",
82
+ "SAMPLE = dbutils.widgets.get(\"sample_pct\").strip()\n",
83
+ "\n",
84
+ "NAME = r\"[A-Za-z0-9_]+\"\n",
85
+ "if not re.fullmatch(rf\"{NAME}\\.{NAME}\\.{NAME}\", TABLE):\n",
86
+ " raise ValueError(f\"Set the 'table' widget to catalog.schema.table (letters, digits, underscores); got {TABLE!r}\")\n",
87
+ "if not re.fullmatch(rf\"{NAME}\\.{NAME}\", SCRATCH):\n",
88
+ " raise ValueError(f\"Set 'scratch_schema' to catalog.schema; got {SCRATCH!r}\")\n",
89
+ "if not re.fullmatch(r\"[A-Za-z0-9]+\", WAREHOUSE_ID):\n",
90
+ " raise ValueError(\"Set the 'warehouse_id' widget to your SQL warehouse ID (SQL Warehouses → Connection details).\")\n",
91
+ "if VERSION and not VERSION.isdigit():\n",
92
+ " raise ValueError(f\"'version' must be a number or empty; got {VERSION!r}\")\n",
93
+ "SAMPLE_PCT = float(SAMPLE) if SAMPLE else None\n",
94
+ "\n",
95
+ "import bricksentry\n",
96
+ "from bricksentry import Config, Sentry\n",
97
+ "\n",
98
+ "sentry = Sentry(Config.from_dict({\n",
99
+ " \"backend\": {\"type\": \"databricks\", \"warehouse_id\": WAREHOUSE_ID},\n",
100
+ " \"sandbox_schema\": SCRATCH,\n",
101
+ " \"assessment_store\": False,\n",
102
+ " \"lineage\": {\"type\": \"databricks\", \"depth\": 3, \"lookback_days\": 90},\n",
103
+ " \"policy\": f\"builtin:{POLICY}\",\n",
104
+ "}))\n",
105
+ "db = sentry.backend\n",
106
+ "print(f\"bricksentry {bricksentry.__version__} · checking {TABLE} · policy {POLICY}\")"
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "markdown",
111
+ "metadata": {},
112
+ "source": [
113
+ "## 1. Recent history of the table\n",
114
+ "The last 15 versions from `DESCRIBE HISTORY`. bricksentry checks the most recent one that changed data,\n",
115
+ "comparing it with the version just before it."
116
+ ]
117
+ },
118
+ {
119
+ "cell_type": "code",
120
+ "execution_count": null,
121
+ "metadata": {},
122
+ "outputs": [],
123
+ "source": [
124
+ "DATA_OPS = (\"WRITE\", \"MERGE\", \"UPDATE\", \"DELETE\", \"TRUNCATE\", \"STREAMING UPDATE\",\n",
125
+ " \"CREATE OR REPLACE TABLE AS SELECT\", \"REPLACE TABLE AS SELECT\", \"COPY INTO\")\n",
126
+ "\n",
127
+ "history = db.query(f\"DESCRIBE HISTORY {db.qualified(TABLE)} LIMIT 15\")\n",
128
+ "for h in history:\n",
129
+ " metrics = str(h.get(\"operationMetrics\") or \"\")\n",
130
+ " print(f\"v{h['version']:<6} {str(h.get('timestamp'))[:19]} {h.get('operation', ''):<34} {metrics[:90]}\")\n",
131
+ "\n",
132
+ "if VERSION:\n",
133
+ " CHECK = int(VERSION)\n",
134
+ "else:\n",
135
+ " changes = [h for h in history if str(h.get(\"operation\", \"\")).upper() in DATA_OPS and int(h[\"version\"]) > 0]\n",
136
+ " if not changes:\n",
137
+ " raise ValueError(\"No data change found in the last 15 versions. Enter a version number in the 'version' widget.\")\n",
138
+ " CHECK = int(changes[0][\"version\"])\n",
139
+ "if CHECK < 1:\n",
140
+ " raise ValueError(\"Version 0 is the table's creation; there is nothing before it to compare with.\")\n",
141
+ "op = next((h.get(\"operation\") for h in history if int(h[\"version\"]) == CHECK), \"?\")\n",
142
+ "print(f\"\\nChecking version {CHECK} ({op}) against version {CHECK - 1}.\")"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "markdown",
147
+ "metadata": {},
148
+ "source": [
149
+ "## 2. Keys\n",
150
+ "Rows are matched by key. If you left `keys` empty, the table's primary key constraint is used."
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "execution_count": null,
156
+ "metadata": {},
157
+ "outputs": [],
158
+ "source": [
159
+ "if not KEYS:\n",
160
+ " cat, sch, tbl = TABLE.split(\".\")\n",
161
+ " try:\n",
162
+ " rows = db.query(f\"\"\"\n",
163
+ " SELECT k.column_name\n",
164
+ " FROM {db.quote(cat)}.information_schema.table_constraints c\n",
165
+ " JOIN {db.quote(cat)}.information_schema.key_column_usage k\n",
166
+ " ON k.constraint_catalog = c.constraint_catalog\n",
167
+ " AND k.constraint_schema = c.constraint_schema\n",
168
+ " AND k.constraint_name = c.constraint_name\n",
169
+ " WHERE c.constraint_type = 'PRIMARY KEY'\n",
170
+ " AND c.table_schema = '{sch}' AND c.table_name = '{tbl}'\n",
171
+ " ORDER BY k.ordinal_position\"\"\")\n",
172
+ " KEYS = [r[\"column_name\"] for r in rows]\n",
173
+ " except Exception as e:\n",
174
+ " print(\"Could not read the primary key:\", str(e)[:200])\n",
175
+ "if not KEYS:\n",
176
+ " raise ValueError(\"No primary key found. Enter the key column(s) in the 'keys' widget and run again.\")\n",
177
+ "print(\"Keys:\", \", \".join(KEYS))"
178
+ ]
179
+ },
180
+ {
181
+ "cell_type": "markdown",
182
+ "metadata": {},
183
+ "source": [
184
+ "## 3. Compare the two versions and get the verdict"
185
+ ]
186
+ },
187
+ {
188
+ "cell_type": "code",
189
+ "execution_count": null,
190
+ "metadata": {},
191
+ "outputs": [],
192
+ "source": [
193
+ "short = re.sub(r\"[^A-Za-z0-9_]\", \"_\", TABLE.split(\".\")[-1])[:40]\n",
194
+ "BASE = f\"{SCRATCH}.bs_check_{short}_v{CHECK - 1}\"\n",
195
+ "CAND = f\"{SCRATCH}.bs_check_{short}_v{CHECK}\"\n",
196
+ "\n",
197
+ "db.ensure_schema(SCRATCH)\n",
198
+ "assessment = None\n",
199
+ "try:\n",
200
+ " for target, v in ((BASE, CHECK - 1), (CAND, CHECK)):\n",
201
+ " try:\n",
202
+ " db.execute(f\"CREATE OR REPLACE TABLE {db.qualified(target)} \"\n",
203
+ " f\"SHALLOW CLONE {db.qualified(TABLE)} VERSION AS OF {v}\")\n",
204
+ " except Exception as e:\n",
205
+ " raise RuntimeError(\n",
206
+ " f\"Could not read version {v} of {TABLE}. Its files may have been removed by VACUUM, \"\n",
207
+ " f\"or you may lack CREATE TABLE on {SCRATCH}. Details: {str(e)[:300]}\") from None\n",
208
+ " diff = sentry.diff(BASE, CAND, keys=KEYS, table=TABLE, sample_pct=SAMPLE_PCT)\n",
209
+ " assessment = sentry.assess([TABLE], diffs={TABLE: diff})\n",
210
+ "finally:\n",
211
+ " for t in (BASE, CAND):\n",
212
+ " try:\n",
213
+ " db.drop(t)\n",
214
+ " except Exception as e:\n",
215
+ " print(\"Could not drop\", t, str(e)[:120])\n",
216
+ "\n",
217
+ "t = assessment.tables[0]\n",
218
+ "UNDO = f\"RESTORE TABLE {db.qualified(TABLE)} TO VERSION AS OF {CHECK - 1}\"\n",
219
+ "t.rollback = UNDO # the change already happened: undoing it means going back to the version before it\n",
220
+ "print(f\"VERDICT: {assessment.verdict.value.upper()} (risk {assessment.verdict.risk_tier})\\n\")\n",
221
+ "print(t.summary, \"\\n\")\n",
222
+ "for h in assessment.hits:\n",
223
+ " print(f\" [{h.verdict.value}] {h.rule}: {h.reason}\")\n",
224
+ "if assessment.notify:\n",
225
+ " print(\"\\nWould ask for review from:\", \", \".join(assessment.notify))\n",
226
+ "print(f\"\\nTo undo version {CHECK}: {UNDO}\")"
227
+ ]
228
+ },
229
+ {
230
+ "cell_type": "markdown",
231
+ "metadata": {},
232
+ "source": [
233
+ "### The pull-request comment a reviewer would have seen"
234
+ ]
235
+ },
236
+ {
237
+ "cell_type": "code",
238
+ "execution_count": null,
239
+ "metadata": {},
240
+ "outputs": [],
241
+ "source": [
242
+ "from bricksentry.report import to_markdown\n",
243
+ "\n",
244
+ "report = to_markdown(assessment)\n",
245
+ "try:\n",
246
+ " from IPython.display import Markdown, display\n",
247
+ " display(Markdown(report))\n",
248
+ "except Exception:\n",
249
+ " print(report)"
250
+ ]
251
+ },
252
+ {
253
+ "cell_type": "markdown",
254
+ "metadata": {},
255
+ "source": [
256
+ "## 4. Tell us what it found (optional, 1 minute)\n",
257
+ "Did it catch something, miss something, or get it wrong? The link below opens a short GitHub form with the\n",
258
+ "verdict and rules filled in. **No table or column names are included**; add only what you're happy to share."
259
+ ]
260
+ },
261
+ {
262
+ "cell_type": "code",
263
+ "execution_count": null,
264
+ "metadata": {},
265
+ "outputs": [],
266
+ "source": [
267
+ "from urllib.parse import urlencode\n",
268
+ "\n",
269
+ "rules = \"; \".join(sorted({f\"{h.rule} ({h.verdict.value})\" for h in assessment.hits})) or \"none\"\n",
270
+ "d = t.diff\n",
271
+ "facts = (f\"rows {d.base_rows:,} -> {d.candidate_rows:,}; added {d.added_rows:,}, removed {d.removed_rows:,}, \"\n",
272
+ " f\"changed {d.changed_rows:,}; downstream assets {len(t.downstream)}\") if d else \"diff unavailable\"\n",
273
+ "params = {\n",
274
+ " \"template\": \"it_caught_this.yml\",\n",
275
+ " \"title\": f\"[check] {assessment.verdict.value} on a {op} change\",\n",
276
+ " \"verdict\": assessment.verdict.value,\n",
277
+ " \"rules\": rules,\n",
278
+ " \"facts\": f\"Operation: {op}\\n{facts}\",\n",
279
+ " \"version\": bricksentry.__version__,\n",
280
+ "}\n",
281
+ "print(\"Share what it found:\\nhttps://github.com/bricksentry/bricksentry/issues/new?\" + urlencode(params))"
282
+ ]
283
+ },
284
+ {
285
+ "cell_type": "markdown",
286
+ "metadata": {},
287
+ "source": [
288
+ "## Next steps\n",
289
+ "- **Check every change before it ships:** run the same check in CI on pull requests. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).\n",
290
+ "- **Let AI agents check their own changes:** `uvx bricksentry-mcp`. See [bricksentry.org/docs/agents](https://bricksentry.org/docs/agents).\n",
291
+ "- **Get alerts:** set a Slack or Teams webhook and run `bricksentry test-alert`. See [bricksentry.org/docs/configuration](https://bricksentry.org/docs/configuration)."
292
+ ]
293
+ }
294
+ ],
295
+ "metadata": {
296
+ "kernelspec": {
297
+ "display_name": "Python 3",
298
+ "language": "python",
299
+ "name": "python3"
300
+ },
301
+ "language_info": {
302
+ "name": "python"
303
+ },
304
+ "application/vnd.databricks.v1+notebook": {
305
+ "notebookName": "bricksentry_check_my_table",
306
+ "language": "python"
307
+ }
308
+ },
309
+ "nbformat": 4,
310
+ "nbformat_minor": 5
311
+ }