bricksentry 0.1.7__tar.gz → 0.1.9__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 (58) hide show
  1. {bricksentry-0.1.7 → bricksentry-0.1.9}/CHANGELOG.md +18 -0
  2. {bricksentry-0.1.7 → bricksentry-0.1.9}/PKG-INFO +35 -7
  3. {bricksentry-0.1.7 → bricksentry-0.1.9}/README.md +34 -6
  4. bricksentry-0.1.9/examples/databricks/bricksentry_check_my_table.ipynb +311 -0
  5. bricksentry-0.1.9/examples/databricks/bricksentry_check_my_table.py +233 -0
  6. {bricksentry-0.1.7 → bricksentry-0.1.9}/pyproject.toml +1 -1
  7. {bricksentry-0.1.7 → bricksentry-0.1.9}/scripts/build_notebook.py +12 -7
  8. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/__init__.py +1 -1
  9. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/agent_tools.py +1 -1
  10. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/assess.py +17 -4
  11. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/cli.py +50 -7
  12. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/config.py +69 -1
  13. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/explain.py +7 -2
  14. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/mcp_server.py +9 -1
  15. bricksentry-0.1.9/src/bricksentry/measures.py +63 -0
  16. bricksentry-0.1.9/src/bricksentry/notify.py +362 -0
  17. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/policy.py +18 -3
  18. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/policy_templates.py +5 -0
  19. bricksentry-0.1.9/tests/test_018.py +288 -0
  20. bricksentry-0.1.9/tests/test_019.py +57 -0
  21. bricksentry-0.1.9/tests/test_check_notebook.py +153 -0
  22. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/test_notify_templates.py +29 -2
  23. bricksentry-0.1.7/src/bricksentry/notify.py +0 -156
  24. {bricksentry-0.1.7 → bricksentry-0.1.9}/.gitignore +0 -0
  25. {bricksentry-0.1.7 → bricksentry-0.1.9}/CONTRIBUTING.md +0 -0
  26. {bricksentry-0.1.7 → bricksentry-0.1.9}/LICENSE +0 -0
  27. {bricksentry-0.1.7 → bricksentry-0.1.9}/SECURITY.md +0 -0
  28. {bricksentry-0.1.7 → bricksentry-0.1.9}/action.yml +0 -0
  29. {bricksentry-0.1.7 → bricksentry-0.1.9}/examples/databricks/bricksentry.yml +0 -0
  30. {bricksentry-0.1.7 → bricksentry-0.1.9}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
  31. {bricksentry-0.1.7 → bricksentry-0.1.9}/examples/databricks/bricksentry_quickstart.py +0 -0
  32. {bricksentry-0.1.7 → bricksentry-0.1.9}/examples/databricks/github-workflow.yml +0 -0
  33. {bricksentry-0.1.7 → bricksentry-0.1.9}/examples/databricks/policy.yml +0 -0
  34. {bricksentry-0.1.7 → bricksentry-0.1.9}/examples/demo/agent_loop_demo.py +0 -0
  35. {bricksentry-0.1.7 → bricksentry-0.1.9}/packages/bricksentry-mcp/LICENSE +0 -0
  36. {bricksentry-0.1.7 → bricksentry-0.1.9}/packages/bricksentry-mcp/README.md +0 -0
  37. {bricksentry-0.1.7 → bricksentry-0.1.9}/packages/bricksentry-mcp/src/bricksentry_mcp/__init__.py +0 -0
  38. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/backends/__init__.py +0 -0
  39. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/backends/base.py +0 -0
  40. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/backends/databricks_backend.py +0 -0
  41. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/backends/duckdb_backend.py +0 -0
  42. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/changes.py +0 -0
  43. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/demo.py +0 -0
  44. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/diff.py +0 -0
  45. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/github.py +0 -0
  46. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/lineage.py +0 -0
  47. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/models.py +0 -0
  48. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/preview.py +0 -0
  49. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/py.typed +0 -0
  50. {bricksentry-0.1.7 → bricksentry-0.1.9}/src/bricksentry/report.py +0 -0
  51. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/conftest.py +0 -0
  52. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/test_assess_policy.py +0 -0
  53. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/test_databricks_and_uc.py +0 -0
  54. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/test_demo.py +0 -0
  55. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/test_diff.py +0 -0
  56. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/test_notebook.py +0 -0
  57. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/test_preview_agents.py +0 -0
  58. {bricksentry-0.1.7 → bricksentry-0.1.9}/tests/test_sample_guard_and_store.py +0 -0
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.9 (2026-11-11)
4
+
5
+ - 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`.
6
+ - 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.
7
+ - 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`.
8
+
9
+ ## 0.1.8 (2026-11-11)
10
+
11
+ From the first real Slack alert sent from a Databricks workspace:
12
+
13
+ - Totals checks skip columns where a total means nothing. `numeric-total-moved` and diff summaries now ignore keys and columns that look like IDs, codes, years and other date parts, coordinates, ratings, scores or rates, so a real move in `sum(bed_count)` is no longer buried under `sum(established_year)`. Choose exactly with `measures: [...]` per table, or `measures: all` for the old behaviour. Rules that name a column still check it.
14
+ - Slack alerts can @-mention reviewers: map owners to Slack member or group ids under `notify.mentions`.
15
+ - Alerts link back to the run: the Databricks job run when the check runs in a job (new), the PR or Actions run in GitHub, or any URL in `BRICKSENTRY_RUN_URL` / `notify.run_url`.
16
+ - New `bricksentry test-alert` sends a clearly labelled sample alert to check the webhook setup (`--verdict`, `--owner`). Exits 1 if delivery fails.
17
+ - More robust delivery: one retry when Slack or Teams answers 429 or 5xx or the connection fails; clear messages for revoked webhooks (404/410); the webhook URL never appears in an error; Slack text is escaped so table names or values can't break or inject formatting; long reasons are clipped. Teams cards use plain text runs, so names like `my_table_name` show exactly. Bad `notify.on` or `mentions` values give a clear error.
18
+ - Config typos are reported. Unknown keys in bricksentry.yml (top level, `tables`, `notify`, `lineage`) print a warning with the closest valid key; also warns about tables without keys, short table names on Databricks, and webhook URLs written into the file.
19
+ - `bricksentry-mcp --help` shows `Usage: bricksentry-mcp [OPTIONS]`, and the MCP server reports the bricksentry version to clients (the version used to be empty).
20
+
3
21
  ## 0.1.7 (2026-11-11)
4
22
 
5
23
  - New companion package `bricksentry-mcp`: `uvx bricksentry-mcp --config /full/path/bricksentry.yml` starts the MCP server with everything it needs. Before, `uvx bricksentry mcp` installed the package without its MCP extra and failed, and that is what MCP Registry clients ran. The registry listing now points at `bricksentry-mcp`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bricksentry
3
- Version: 0.1.7
3
+ Version: 0.1.9
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
 
@@ -194,7 +205,7 @@ Check out with `fetch-depth: 0` and give the job `pull-requests: write` permissi
194
205
  Or use the bundled GitHub Action, which also writes the report to the job summary:
195
206
 
196
207
  ```yaml
197
- - uses: bricksentry/bricksentry@v0.1.7
208
+ - uses: bricksentry/bricksentry@v0.1.9
198
209
  with:
199
210
  config: bricksentry.yml
200
211
  fail-on: needs_human
@@ -219,7 +230,7 @@ jobs:
219
230
  fetch-depth: 0
220
231
  # Build this PR's version of your pipeline into a per-PR schema first,
221
232
  # for example: databricks bundle deploy -t ci && databricks bundle run -t ci
222
- - uses: bricksentry/bricksentry@v0.1.7
233
+ - uses: bricksentry/bricksentry@v0.1.9
223
234
  with:
224
235
  config: bricksentry.yml
225
236
  fail-on: needs_human
@@ -236,7 +247,7 @@ To make the check binding, mark this job as a required status check in your bran
236
247
 
237
248
  ### Alerts in Slack and Teams
238
249
 
239
- When the verdict is `needs_human` or worse, bricksentry can post a short alert: the verdict, the rules that fired, who should review, and a link to the PR.
250
+ When the verdict is `needs_human` or worse, bricksentry can post a short alert: the verdict, the rules that fired, who should review, and a link back to where the check ran.
240
251
 
241
252
  ```yaml
242
253
  # bricksentry.yml
@@ -244,9 +255,21 @@ notify:
244
255
  on: needs_human # alert at this verdict or worse
245
256
  slack_webhook: env:SLACK_WEBHOOK_URL # Slack incoming webhook
246
257
  teams_webhook: env:TEAMS_WEBHOOK_URL # Teams Workflows "webhook request" URL
258
+ mentions: # optional: @-mention reviewers in Slack
259
+ finance-analytics: S0123ABCD # a user group id (starts with S)
260
+ jane@acme.com: U0456EFGH # a member id (starts with U)
247
261
  ```
248
262
 
249
- Keep webhook URLs in secrets or environment variables, never in the file. `BRICKSENTRY_SLACK_WEBHOOK` and `BRICKSENTRY_TEAMS_WEBHOOK` work too. `assess` and `preview` send alerts automatically when a webhook is set (`--no-notify` turns them off), and in Python call `sentry.notify(assessment)`. A failed webhook is reported but never changes the verdict or fails the run.
263
+ Then check the setup with one command. It sends a clearly labelled sample alert and reads no tables:
264
+
265
+ ```bash
266
+ bricksentry test-alert
267
+ ```
268
+
269
+ - **Keep webhook URLs secret.** Put them in CI secrets or environment variables (`BRICKSENTRY_SLACK_WEBHOOK` and `BRICKSENTRY_TEAMS_WEBHOOK` work too), never in the file; bricksentry warns if it finds one there.
270
+ - **Links back to the run.** In GitHub Actions the alert links to the PR or run. In a Databricks job it links to the job run. Anywhere else, set `BRICKSENTRY_RUN_URL` (or `notify.run_url`).
271
+ - **Mentions.** Owners come from Unity Catalog. Map them to Slack ids under `mentions` and the alert @-mentions them; unmapped owners are shown as text. Find an id in Slack under a person's profile or a user group's menu, "Copy member ID" / "Copy group ID".
272
+ - **Never breaks a run.** `assess` and `preview` send alerts automatically when a webhook is set (`--no-notify` turns them off); in Python call `sentry.notify(assessment)`. If Slack or Teams is busy the alert is retried once, a failure is reported without the webhook URL, and the verdict always stands.
250
273
 
251
274
  ## Python API
252
275
 
@@ -274,10 +297,15 @@ tables:
274
297
  main.sales.orders:
275
298
  keys: [order_id]
276
299
  segment_by: [region]
300
+ measures: [amount, quantity] # totals worth checking (see below)
277
301
  paths: ["src/pipelines/orders/**", "resources/orders_job.yml"]
278
302
  policy: policy.yml # or builtin:<template>, see "Policy templates" below
279
303
  ```
280
304
 
305
+ 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
+
307
+ **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.
308
+
281
309
  ### Policy example
282
310
 
283
311
  A small `policy.yml` with one rule per severity. `pass` is the default: a change gets it when no rule matches.
@@ -326,7 +354,7 @@ Use one directly with `policy: builtin:finance`, or write an editable copy with
326
354
 
327
355
  ### Policy conditions
328
356
 
329
- `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`
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`
330
358
 
331
359
  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.
332
360
 
@@ -334,7 +362,7 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
334
362
 
335
363
  - `CAN USE` on a SQL warehouse.
336
364
  - `SELECT` on the tables you assess and their candidates.
337
- - `SELECT` on `system.access.table_lineage`, plus `system.information_schema` for owners and tags. Without these, bricksentry still diffs; lineage is just empty.
365
+ - `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.
338
366
  - `CREATE TABLE` on `sandbox_schema`, for `preview_write`.
339
367
 
340
368
  ## 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
 
@@ -147,7 +158,7 @@ Check out with `fetch-depth: 0` and give the job `pull-requests: write` permissi
147
158
  Or use the bundled GitHub Action, which also writes the report to the job summary:
148
159
 
149
160
  ```yaml
150
- - uses: bricksentry/bricksentry@v0.1.7
161
+ - uses: bricksentry/bricksentry@v0.1.9
151
162
  with:
152
163
  config: bricksentry.yml
153
164
  fail-on: needs_human
@@ -172,7 +183,7 @@ jobs:
172
183
  fetch-depth: 0
173
184
  # Build this PR's version of your pipeline into a per-PR schema first,
174
185
  # for example: databricks bundle deploy -t ci && databricks bundle run -t ci
175
- - uses: bricksentry/bricksentry@v0.1.7
186
+ - uses: bricksentry/bricksentry@v0.1.9
176
187
  with:
177
188
  config: bricksentry.yml
178
189
  fail-on: needs_human
@@ -189,7 +200,7 @@ To make the check binding, mark this job as a required status check in your bran
189
200
 
190
201
  ### Alerts in Slack and Teams
191
202
 
192
- When the verdict is `needs_human` or worse, bricksentry can post a short alert: the verdict, the rules that fired, who should review, and a link to the PR.
203
+ When the verdict is `needs_human` or worse, bricksentry can post a short alert: the verdict, the rules that fired, who should review, and a link back to where the check ran.
193
204
 
194
205
  ```yaml
195
206
  # bricksentry.yml
@@ -197,9 +208,21 @@ notify:
197
208
  on: needs_human # alert at this verdict or worse
198
209
  slack_webhook: env:SLACK_WEBHOOK_URL # Slack incoming webhook
199
210
  teams_webhook: env:TEAMS_WEBHOOK_URL # Teams Workflows "webhook request" URL
211
+ mentions: # optional: @-mention reviewers in Slack
212
+ finance-analytics: S0123ABCD # a user group id (starts with S)
213
+ jane@acme.com: U0456EFGH # a member id (starts with U)
200
214
  ```
201
215
 
202
- Keep webhook URLs in secrets or environment variables, never in the file. `BRICKSENTRY_SLACK_WEBHOOK` and `BRICKSENTRY_TEAMS_WEBHOOK` work too. `assess` and `preview` send alerts automatically when a webhook is set (`--no-notify` turns them off), and in Python call `sentry.notify(assessment)`. A failed webhook is reported but never changes the verdict or fails the run.
216
+ Then check the setup with one command. It sends a clearly labelled sample alert and reads no tables:
217
+
218
+ ```bash
219
+ bricksentry test-alert
220
+ ```
221
+
222
+ - **Keep webhook URLs secret.** Put them in CI secrets or environment variables (`BRICKSENTRY_SLACK_WEBHOOK` and `BRICKSENTRY_TEAMS_WEBHOOK` work too), never in the file; bricksentry warns if it finds one there.
223
+ - **Links back to the run.** In GitHub Actions the alert links to the PR or run. In a Databricks job it links to the job run. Anywhere else, set `BRICKSENTRY_RUN_URL` (or `notify.run_url`).
224
+ - **Mentions.** Owners come from Unity Catalog. Map them to Slack ids under `mentions` and the alert @-mentions them; unmapped owners are shown as text. Find an id in Slack under a person's profile or a user group's menu, "Copy member ID" / "Copy group ID".
225
+ - **Never breaks a run.** `assess` and `preview` send alerts automatically when a webhook is set (`--no-notify` turns them off); in Python call `sentry.notify(assessment)`. If Slack or Teams is busy the alert is retried once, a failure is reported without the webhook URL, and the verdict always stands.
203
226
 
204
227
  ## Python API
205
228
 
@@ -227,10 +250,15 @@ tables:
227
250
  main.sales.orders:
228
251
  keys: [order_id]
229
252
  segment_by: [region]
253
+ measures: [amount, quantity] # totals worth checking (see below)
230
254
  paths: ["src/pipelines/orders/**", "resources/orders_job.yml"]
231
255
  policy: policy.yml # or builtin:<template>, see "Policy templates" below
232
256
  ```
233
257
 
258
+ 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
+
260
+ **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.
261
+
234
262
  ### Policy example
235
263
 
236
264
  A small `policy.yml` with one rule per severity. `pass` is the default: a change gets it when no rule matches.
@@ -279,7 +307,7 @@ Use one directly with `policy: builtin:finance`, or write an editable copy with
279
307
 
280
308
  ### Policy conditions
281
309
 
282
- `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`
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`
283
311
 
284
312
  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.
285
313
 
@@ -287,7 +315,7 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
287
315
 
288
316
  - `CAN USE` on a SQL warehouse.
289
317
  - `SELECT` on the tables you assess and their candidates.
290
- - `SELECT` on `system.access.table_lineage`, plus `system.information_schema` for owners and tags. Without these, bricksentry still diffs; lineage is just empty.
318
+ - `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.
291
319
  - `CREATE TABLE` on `sandbox_schema`, for `preview_write`.
292
320
 
293
321
  ## Known limits (v0.1.x)
@@ -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
+ }