bricksentry 0.1.4__tar.gz → 0.1.6__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 (49) hide show
  1. {bricksentry-0.1.4 → bricksentry-0.1.6}/CHANGELOG.md +12 -0
  2. {bricksentry-0.1.4 → bricksentry-0.1.6}/PKG-INFO +71 -5
  3. {bricksentry-0.1.4 → bricksentry-0.1.6}/README.md +70 -4
  4. {bricksentry-0.1.4 → bricksentry-0.1.6}/action.yml +12 -0
  5. {bricksentry-0.1.4 → bricksentry-0.1.6}/pyproject.toml +1 -1
  6. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/__init__.py +1 -1
  7. bricksentry-0.1.6/src/bricksentry/agent_tools.py +228 -0
  8. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/assess.py +11 -0
  9. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/cli.py +44 -4
  10. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/config.py +13 -2
  11. bricksentry-0.1.6/src/bricksentry/notify.py +156 -0
  12. bricksentry-0.1.6/src/bricksentry/policy_templates.py +126 -0
  13. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/preview.py +29 -3
  14. bricksentry-0.1.6/tests/test_notify_templates.py +142 -0
  15. bricksentry-0.1.4/src/bricksentry/agent_tools.py +0 -139
  16. {bricksentry-0.1.4 → bricksentry-0.1.6}/.gitignore +0 -0
  17. {bricksentry-0.1.4 → bricksentry-0.1.6}/CONTRIBUTING.md +0 -0
  18. {bricksentry-0.1.4 → bricksentry-0.1.6}/LICENSE +0 -0
  19. {bricksentry-0.1.4 → bricksentry-0.1.6}/SECURITY.md +0 -0
  20. {bricksentry-0.1.4 → bricksentry-0.1.6}/examples/databricks/bricksentry.yml +0 -0
  21. {bricksentry-0.1.4 → bricksentry-0.1.6}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
  22. {bricksentry-0.1.4 → bricksentry-0.1.6}/examples/databricks/bricksentry_quickstart.py +0 -0
  23. {bricksentry-0.1.4 → bricksentry-0.1.6}/examples/databricks/github-workflow.yml +0 -0
  24. {bricksentry-0.1.4 → bricksentry-0.1.6}/examples/databricks/policy.yml +0 -0
  25. {bricksentry-0.1.4 → bricksentry-0.1.6}/examples/demo/agent_loop_demo.py +0 -0
  26. {bricksentry-0.1.4 → bricksentry-0.1.6}/scripts/build_notebook.py +0 -0
  27. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/backends/__init__.py +0 -0
  28. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/backends/base.py +0 -0
  29. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/backends/databricks_backend.py +0 -0
  30. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/backends/duckdb_backend.py +0 -0
  31. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/changes.py +0 -0
  32. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/demo.py +0 -0
  33. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/diff.py +0 -0
  34. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/explain.py +0 -0
  35. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/github.py +0 -0
  36. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/lineage.py +0 -0
  37. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/mcp_server.py +0 -0
  38. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/models.py +0 -0
  39. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/policy.py +0 -0
  40. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/py.typed +0 -0
  41. {bricksentry-0.1.4 → bricksentry-0.1.6}/src/bricksentry/report.py +0 -0
  42. {bricksentry-0.1.4 → bricksentry-0.1.6}/tests/conftest.py +0 -0
  43. {bricksentry-0.1.4 → bricksentry-0.1.6}/tests/test_assess_policy.py +0 -0
  44. {bricksentry-0.1.4 → bricksentry-0.1.6}/tests/test_databricks_and_uc.py +0 -0
  45. {bricksentry-0.1.4 → bricksentry-0.1.6}/tests/test_demo.py +0 -0
  46. {bricksentry-0.1.4 → bricksentry-0.1.6}/tests/test_diff.py +0 -0
  47. {bricksentry-0.1.4 → bricksentry-0.1.6}/tests/test_notebook.py +0 -0
  48. {bricksentry-0.1.4 → bricksentry-0.1.6}/tests/test_preview_agents.py +0 -0
  49. {bricksentry-0.1.4 → bricksentry-0.1.6}/tests/test_sample_guard_and_store.py +0 -0
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.6 (2026-11-11)
4
+
5
+ - Slack and Teams alerts. Set `notify:` in bricksentry.yml (or `BRICKSENTRY_SLACK_WEBHOOK` / `BRICKSENTRY_TEAMS_WEBHOOK`) and `assess` / `preview` post the verdict, the rules that fired, the reviewers and a PR link when the verdict reaches `notify.on` (default `needs_human`). `--no-notify` turns it off; `Sentry.notify()` does it from Python; the GitHub Action takes `slack-webhook`, `teams-webhook` and `notify-on`. A failed webhook never changes the verdict.
6
+ - Policy templates: `default`, `strict`, `pii`, `certified` and `finance`. Use `policy: builtin:<name>`, `bricksentry init --policy <name>`, or list them with `bricksentry policies`.
7
+ - When `preview_write` refuses DROP, TRUNCATE, ALTER, GRANT, REVOKE, VACUUM or RESTORE, the error now says what to do instead.
8
+ - Listed in the official MCP Registry as `io.github.bricksentry/bricksentry` (published automatically on each release).
9
+ - A complete copy-paste GitHub Actions workflow in the README.
10
+
11
+ ## 0.1.5 (2026-11-10)
12
+
13
+ - Clearer MCP tool definitions for agents. Each tool now says when to use it versus its sibling tools and what it returns, and every parameter has a description in the tool schema (for example the `candidates` map format for `assess_change`). No behavior changes.
14
+
3
15
  ## 0.1.4 (2026-11-10)
4
16
 
5
17
  From a second end-to-end run on Databricks serverless against a 2-million-row table:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bricksentry
3
- Version: 0.1.4
3
+ Version: 0.1.6
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
@@ -47,6 +47,8 @@ Description-Content-Type: text/markdown
47
47
 
48
48
  # Welcome to bricksentry
49
49
 
50
+ <!-- mcp-name: io.github.bricksentry/bricksentry -->
51
+
50
52
  [![PyPI](https://img.shields.io/pypi/v/bricksentry)](https://pypi.org/project/bricksentry/) [![Python](https://img.shields.io/pypi/pyversions/bricksentry)](https://pypi.org/project/bricksentry/) [![Tests](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml/badge.svg)](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [![Lint](https://github.com/bricksentry/bricksentry/actions/workflows/lint.yml/badge.svg)](https://github.com/bricksentry/bricksentry/actions/workflows/lint.yml) [![Coverage](https://img.shields.io/badge/coverage-%E2%89%A575%25%20enforced-brightgreen)](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
51
53
 
52
54
  ***The safety check for data changes in the AI era.***
@@ -135,6 +137,8 @@ To watch the whole loop, run `bricksentry demo` (see the top of this page). `bri
135
137
 
136
138
  ```bash
137
139
  bricksentry init # starter bricksentry.yml + policy.yml
140
+ bricksentry init --policy finance # ...or start from a policy template
141
+ bricksentry policies # list the policy templates
138
142
  bricksentry impact main.sales.orders # blast radius
139
143
  bricksentry diff main.sales.orders main.sales_pr_42.orders
140
144
  bricksentry preview main.sales.orders --sql "MERGE INTO {{target}} t USING updates u ON t.order_id = u.order_id WHEN MATCHED THEN UPDATE SET *"
@@ -171,12 +175,60 @@ Check out with `fetch-depth: 0` and give the job `pull-requests: write` permissi
171
175
  Or use the bundled GitHub Action, which also writes the report to the job summary:
172
176
 
173
177
  ```yaml
174
- - uses: bricksentry/bricksentry@v0.1.0
178
+ - uses: bricksentry/bricksentry@v0.1.6
175
179
  with:
176
180
  config: bricksentry.yml
177
181
  fail-on: needs_human
178
182
  ```
179
183
 
184
+ A complete workflow you can copy to `.github/workflows/bricksentry.yml`:
185
+
186
+ ```yaml
187
+ name: bricksentry
188
+ on: pull_request
189
+
190
+ permissions:
191
+ contents: read
192
+ pull-requests: write
193
+
194
+ jobs:
195
+ check-data:
196
+ runs-on: ubuntu-latest
197
+ steps:
198
+ - uses: actions/checkout@v4
199
+ with:
200
+ fetch-depth: 0
201
+ # Build this PR's version of your pipeline into a per-PR schema first,
202
+ # for example: databricks bundle deploy -t ci && databricks bundle run -t ci
203
+ - uses: bricksentry/bricksentry@v0.1.6
204
+ with:
205
+ config: bricksentry.yml
206
+ fail-on: needs_human
207
+ slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }} # optional
208
+ teams-webhook: ${{ secrets.TEAMS_WEBHOOK_URL }} # optional
209
+ env:
210
+ DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
211
+ DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
212
+ DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
213
+ DATABRICKS_WAREHOUSE_ID: ${{ secrets.DATABRICKS_WAREHOUSE_ID }}
214
+ ```
215
+
216
+ To make the check binding, mark this job as a required status check in your branch protection rules. Then a `needs_human` or `block` verdict stops the merge, whatever the author or an agent decides.
217
+
218
+ ### Alerts in Slack and Teams
219
+
220
+ 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.
221
+
222
+ ```yaml
223
+ # bricksentry.yml
224
+ notify:
225
+ on: needs_human # alert at this verdict or worse
226
+ slack_webhook: env:SLACK_WEBHOOK_URL # Slack incoming webhook
227
+ teams_webhook: env:TEAMS_WEBHOOK_URL # Teams Workflows "webhook request" URL
228
+ ```
229
+
230
+ 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.
231
+
180
232
  ## Python API
181
233
 
182
234
  ```python
@@ -204,7 +256,7 @@ tables:
204
256
  keys: [order_id]
205
257
  segment_by: [region]
206
258
  paths: ["src/pipelines/orders/**", "resources/orders_job.yml"]
207
- policy: policy.yml
259
+ policy: policy.yml # or builtin:<template>, see "Policy templates" below
208
260
  ```
209
261
 
210
262
  ### Policy example
@@ -238,6 +290,20 @@ rules:
238
290
 
239
291
  If several rules match, the most severe one wins. The full starter policy is in [`examples/databricks/policy.yml`](examples/databricks/policy.yml), and `bricksentry init` writes one for you.
240
292
 
293
+ ### Policy templates
294
+
295
+ Start from a ready-made policy instead of writing one:
296
+
297
+ | Template | For |
298
+ |---|---|
299
+ | `default` | Balanced: block duplicate keys, a human for row loss, dropped columns, PII and certified downstream |
300
+ | `strict` | Production-critical pipelines: small changes need a human, failed checks block |
301
+ | `pii` | Tables with personal data: any change to a `pii`-tagged table, or one feeding it, needs a human |
302
+ | `certified` | Certified or gold tables that dashboards and AI rely on |
303
+ | `finance` | Revenue and money tables: totals can't move quietly, double counting is blocked |
304
+
305
+ Use one directly with `policy: builtin:finance`, or write an editable copy with `bricksentry init --policy finance`. `bricksentry policies finance` prints it. Tags come from Unity Catalog, so tag your tables `pii` or `certified` for those templates to apply.
306
+
241
307
  ### Policy conditions
242
308
 
243
309
  `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`
@@ -256,13 +322,13 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
256
322
  - **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.
257
323
  - **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
258
324
  - **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
259
- - **Validated on one Databricks workspace so far** (serverless, November 2026, on a 2-million-row table): lineage, Delta rollback plans, previews on shallow clones, every verdict level and sampling. 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.
325
+ - **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.
260
326
 
261
327
  ## Roadmap
262
328
 
263
329
  **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.
264
330
 
265
- Next: Asset Bundle parsing for automatic table detection · column-level blast radius from `system.access.column_lineage` · an aggregate diff for keyless tables · Lakeflow expectations in the verdict · `bricksentry watch` for scheduled drift checks · a Databricks App UI.
331
+ 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 · column-level blast radius from `system.access.column_lineage` · an aggregate diff for keyless tables · Lakeflow expectations in the verdict · `bricksentry watch` for scheduled drift checks · a Databricks App UI.
266
332
 
267
333
  ## Contributing
268
334
 
@@ -1,5 +1,7 @@
1
1
  # Welcome to bricksentry
2
2
 
3
+ <!-- mcp-name: io.github.bricksentry/bricksentry -->
4
+
3
5
  [![PyPI](https://img.shields.io/pypi/v/bricksentry)](https://pypi.org/project/bricksentry/) [![Python](https://img.shields.io/pypi/pyversions/bricksentry)](https://pypi.org/project/bricksentry/) [![Tests](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml/badge.svg)](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [![Lint](https://github.com/bricksentry/bricksentry/actions/workflows/lint.yml/badge.svg)](https://github.com/bricksentry/bricksentry/actions/workflows/lint.yml) [![Coverage](https://img.shields.io/badge/coverage-%E2%89%A575%25%20enforced-brightgreen)](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
4
6
 
5
7
  ***The safety check for data changes in the AI era.***
@@ -88,6 +90,8 @@ To watch the whole loop, run `bricksentry demo` (see the top of this page). `bri
88
90
 
89
91
  ```bash
90
92
  bricksentry init # starter bricksentry.yml + policy.yml
93
+ bricksentry init --policy finance # ...or start from a policy template
94
+ bricksentry policies # list the policy templates
91
95
  bricksentry impact main.sales.orders # blast radius
92
96
  bricksentry diff main.sales.orders main.sales_pr_42.orders
93
97
  bricksentry preview main.sales.orders --sql "MERGE INTO {{target}} t USING updates u ON t.order_id = u.order_id WHEN MATCHED THEN UPDATE SET *"
@@ -124,12 +128,60 @@ Check out with `fetch-depth: 0` and give the job `pull-requests: write` permissi
124
128
  Or use the bundled GitHub Action, which also writes the report to the job summary:
125
129
 
126
130
  ```yaml
127
- - uses: bricksentry/bricksentry@v0.1.0
131
+ - uses: bricksentry/bricksentry@v0.1.6
128
132
  with:
129
133
  config: bricksentry.yml
130
134
  fail-on: needs_human
131
135
  ```
132
136
 
137
+ A complete workflow you can copy to `.github/workflows/bricksentry.yml`:
138
+
139
+ ```yaml
140
+ name: bricksentry
141
+ on: pull_request
142
+
143
+ permissions:
144
+ contents: read
145
+ pull-requests: write
146
+
147
+ jobs:
148
+ check-data:
149
+ runs-on: ubuntu-latest
150
+ steps:
151
+ - uses: actions/checkout@v4
152
+ with:
153
+ fetch-depth: 0
154
+ # Build this PR's version of your pipeline into a per-PR schema first,
155
+ # for example: databricks bundle deploy -t ci && databricks bundle run -t ci
156
+ - uses: bricksentry/bricksentry@v0.1.6
157
+ with:
158
+ config: bricksentry.yml
159
+ fail-on: needs_human
160
+ slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }} # optional
161
+ teams-webhook: ${{ secrets.TEAMS_WEBHOOK_URL }} # optional
162
+ env:
163
+ DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
164
+ DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
165
+ DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
166
+ DATABRICKS_WAREHOUSE_ID: ${{ secrets.DATABRICKS_WAREHOUSE_ID }}
167
+ ```
168
+
169
+ To make the check binding, mark this job as a required status check in your branch protection rules. Then a `needs_human` or `block` verdict stops the merge, whatever the author or an agent decides.
170
+
171
+ ### Alerts in Slack and Teams
172
+
173
+ 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.
174
+
175
+ ```yaml
176
+ # bricksentry.yml
177
+ notify:
178
+ on: needs_human # alert at this verdict or worse
179
+ slack_webhook: env:SLACK_WEBHOOK_URL # Slack incoming webhook
180
+ teams_webhook: env:TEAMS_WEBHOOK_URL # Teams Workflows "webhook request" URL
181
+ ```
182
+
183
+ 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.
184
+
133
185
  ## Python API
134
186
 
135
187
  ```python
@@ -157,7 +209,7 @@ tables:
157
209
  keys: [order_id]
158
210
  segment_by: [region]
159
211
  paths: ["src/pipelines/orders/**", "resources/orders_job.yml"]
160
- policy: policy.yml
212
+ policy: policy.yml # or builtin:<template>, see "Policy templates" below
161
213
  ```
162
214
 
163
215
  ### Policy example
@@ -191,6 +243,20 @@ rules:
191
243
 
192
244
  If several rules match, the most severe one wins. The full starter policy is in [`examples/databricks/policy.yml`](examples/databricks/policy.yml), and `bricksentry init` writes one for you.
193
245
 
246
+ ### Policy templates
247
+
248
+ Start from a ready-made policy instead of writing one:
249
+
250
+ | Template | For |
251
+ |---|---|
252
+ | `default` | Balanced: block duplicate keys, a human for row loss, dropped columns, PII and certified downstream |
253
+ | `strict` | Production-critical pipelines: small changes need a human, failed checks block |
254
+ | `pii` | Tables with personal data: any change to a `pii`-tagged table, or one feeding it, needs a human |
255
+ | `certified` | Certified or gold tables that dashboards and AI rely on |
256
+ | `finance` | Revenue and money tables: totals can't move quietly, double counting is blocked |
257
+
258
+ Use one directly with `policy: builtin:finance`, or write an editable copy with `bricksentry init --policy finance`. `bricksentry policies finance` prints it. Tags come from Unity Catalog, so tag your tables `pii` or `certified` for those templates to apply.
259
+
194
260
  ### Policy conditions
195
261
 
196
262
  `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`
@@ -209,13 +275,13 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
209
275
  - **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.
210
276
  - **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
211
277
  - **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
212
- - **Validated on one Databricks workspace so far** (serverless, November 2026, on a 2-million-row table): lineage, Delta rollback plans, previews on shallow clones, every verdict level and sampling. 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.
278
+ - **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.
213
279
 
214
280
  ## Roadmap
215
281
 
216
282
  **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.
217
283
 
218
- Next: Asset Bundle parsing for automatic table detection · column-level blast radius from `system.access.column_lineage` · an aggregate diff for keyless tables · Lakeflow expectations in the verdict · `bricksentry watch` for scheduled drift checks · a Databricks App UI.
284
+ 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 · column-level blast radius from `system.access.column_lineage` · an aggregate diff for keyless tables · Lakeflow expectations in the verdict · `bricksentry watch` for scheduled drift checks · a Databricks App UI.
219
285
 
220
286
  ## Contributing
221
287
 
@@ -20,6 +20,15 @@ inputs:
20
20
  comment:
21
21
  description: Post or update a PR comment with the report
22
22
  default: "true"
23
+ slack-webhook:
24
+ description: Slack incoming webhook URL for verdict alerts. Pass it from a secret, e.g. secrets.SLACK_WEBHOOK_URL
25
+ default: ""
26
+ teams-webhook:
27
+ description: Microsoft Teams Workflows webhook URL for verdict alerts. Pass it from a secret
28
+ default: ""
29
+ notify-on:
30
+ description: Send an alert at this verdict or worse (pass, warn, needs_human, block)
31
+ default: needs_human
23
32
  version:
24
33
  description: bricksentry version spec to install (e.g. "==0.1.0"); empty = latest
25
34
  default: ""
@@ -44,6 +53,9 @@ runs:
44
53
  env:
45
54
  BRICKSENTRY_PR: ${{ github.event.pull_request.number }}
46
55
  GITHUB_TOKEN: ${{ github.token }}
56
+ BRICKSENTRY_SLACK_WEBHOOK: ${{ inputs.slack-webhook }}
57
+ BRICKSENTRY_TEAMS_WEBHOOK: ${{ inputs.teams-webhook }}
58
+ BRICKSENTRY_NOTIFY_ON: ${{ inputs.notify-on }}
47
59
  run: |
48
60
  set +e
49
61
  BASE="${{ inputs.base-ref }}"
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bricksentry"
7
- version = "0.1.4"
7
+ version = "0.1.6"
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"
@@ -23,4 +23,4 @@ __all__ = [
23
23
  "TableDiff",
24
24
  "Verdict",
25
25
  ]
26
- __version__ = "0.1.4"
26
+ __version__ = "0.1.6"
@@ -0,0 +1,228 @@
1
+ """Agent tools as plain Python functions returning JSON-safe dicts.
2
+
3
+ The MCP server registers these, but they work in any agent framework
4
+ (LangGraph, OpenAI Agents SDK, Databricks Agent Framework...): import and wrap.
5
+
6
+ Errors come back as ``{"error": "..."}`` instead of exceptions, so an agent
7
+ can read them and recover.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import functools
13
+ from typing import Annotated, Any
14
+
15
+ from bricksentry.assess import Sentry
16
+ from bricksentry.explain import explain_diff as _explain_diff
17
+
18
+ try: # pydantic ships with the `mcp` extra; parameter descriptions are optional without it
19
+ from pydantic import Field as _Field
20
+ except ImportError: # pragma: no cover
21
+ _Field = None
22
+
23
+
24
+ def _desc(text: str):
25
+ """Parameter description that MCP servers expose in the tool schema."""
26
+ return _Field(description=text) if _Field is not None else text
27
+
28
+
29
+ _SENTRY: Sentry | None = None
30
+
31
+
32
+ def get_sentry() -> Sentry:
33
+ global _SENTRY
34
+ if _SENTRY is None:
35
+ _SENTRY = Sentry()
36
+ return _SENTRY
37
+
38
+
39
+ def set_sentry(sentry: Sentry | None) -> None:
40
+ global _SENTRY
41
+ _SENTRY = sentry
42
+
43
+
44
+ def _safe(fn):
45
+ @functools.wraps(fn)
46
+ def wrapper(*args, **kwargs):
47
+ try:
48
+ return fn(*args, **kwargs)
49
+ except Exception as e:
50
+ return {"error": f"{type(e).__name__}: {e}"}
51
+
52
+ return wrapper
53
+
54
+
55
+ @_safe
56
+ def whats_downstream(
57
+ table: Annotated[str, _desc("Fully qualified table name, e.g. main.sales.orders.")],
58
+ depth: Annotated[int, _desc("How many lineage hops to follow downstream (default 3).")] = 3,
59
+ ) -> dict[str, Any]:
60
+ """List what depends on a table, so you know the blast radius BEFORE you edit it.
61
+
62
+ Use this first, when planning a change. It reads Unity Catalog lineage and
63
+ returns every downstream table, job, notebook, pipeline, dashboard and query,
64
+ up to `depth` hops, with owners and tags. Dropped tables are filtered out.
65
+ Read-only; changes nothing. To check a change you have already made, use
66
+ assess_change instead.
67
+
68
+ Returns {table, owner, tags, count, downstream: [{kind, name, depth, via,
69
+ owner, tags}]}, or {error} if the table or lineage cannot be read."""
70
+ s = get_sentry()
71
+ nodes = s.downstream(table, depth)
72
+ owner, tags = s.lineage.owner_and_tags(table)
73
+ return {
74
+ "table": table,
75
+ "owner": owner,
76
+ "tags": tags,
77
+ "count": len(nodes),
78
+ "downstream": [n.to_dict() for n in nodes],
79
+ }
80
+
81
+
82
+ @_safe
83
+ def assess_change(
84
+ tables: Annotated[list[str], _desc("Production tables your change affects, fully qualified.")],
85
+ candidates: Annotated[
86
+ dict[str, str] | None,
87
+ _desc(
88
+ "Optional map of production table -> candidate table your change built "
89
+ "(e.g. {'main.sales.orders': 'dev.sales.orders'}). Omit to use the "
90
+ "candidate pattern from bricksentry.yml."
91
+ ),
92
+ ] = None,
93
+ pr: Annotated[str | None, _desc("Optional pull request number or id, used to name candidates and the report.")] = None,
94
+ ) -> dict[str, Any]:
95
+ """Assess a change that has already been built into candidate tables.
96
+
97
+ Use this after your pipeline change has written candidate (dev/PR) tables.
98
+ For a single SQL write that has not run yet, use preview_write instead.
99
+ For each table it diffs production against the candidate (row, column and
100
+ schema changes, null-safe keys), walks downstream lineage and applies the
101
+ rules in policy.yml. The verdict is deterministic: rules decide, not an LLM.
102
+ Read-only on production and candidates.
103
+
104
+ Returns {id, verdict: pass|warn|needs_human|block, risk_tier, safe_to_ship,
105
+ notify, rule_hits, tables: [{table, verdict, summary, diff, downstream,
106
+ rollback}]}. Pass `id` to safe_to_ship (and optionally explain_diff)."""
107
+ a = get_sentry().assess(list(tables), candidates=candidates, pr=pr)
108
+ return a.to_dict()
109
+
110
+
111
+ @_safe
112
+ def preview_write(
113
+ sql: Annotated[
114
+ str,
115
+ _desc(
116
+ "Exactly one INSERT, MERGE, UPDATE, DELETE or CREATE OR REPLACE TABLE "
117
+ "statement. Write {{target}} where the table name goes, or use the literal name."
118
+ ),
119
+ ],
120
+ target: Annotated[str, _desc("Fully qualified production table the statement would write to.")],
121
+ keys: Annotated[
122
+ list[str] | None, _desc("Optional key columns for the row diff. Omit to use keys from bricksentry.yml.")
123
+ ] = None,
124
+ ) -> dict[str, Any]:
125
+ """Dry-run ONE write statement on a disposable shallow clone of `target`,
126
+ never on production, and report what it would change plus the policy verdict.
127
+
128
+ Use this before running any direct write. It clones the table, rewrites the
129
+ statement to hit the clone, runs it, diffs clone vs production, applies policy
130
+ and drops the clone, even on failure. DROP, TRUNCATE, ALTER, GRANT and
131
+ multiple statements are refused.
132
+
133
+ Returns the same shape as assess_change (with an `id` for safe_to_ship), or
134
+ {error} if the statement is refused or fails."""
135
+ return get_sentry().preview_write(sql, target, keys=keys)
136
+
137
+
138
+ @_safe
139
+ def explain_diff(
140
+ assessment_id: Annotated[
141
+ str | None, _desc("Id returned by assess_change or preview_write. Give this or `table`.")
142
+ ] = None,
143
+ table: Annotated[
144
+ str | None, _desc("Table name, to explain its most recent diff in this session. Give this or `assessment_id`.")
145
+ ] = None,
146
+ ) -> dict[str, Any]:
147
+ """Explain in plain English what a diff changed, for a PR description or a
148
+ human reviewer.
149
+
150
+ Use after assess_change or preview_write when you need readable text rather
151
+ than raw numbers, e.g. "removed 1 row (0.00%); revenue sum -3.1%". Read-only.
152
+ Works across processes because assessments are saved to disk.
153
+
154
+ Returns {assessment_id, explanations: {table: text}} when given an id, or
155
+ {table, explanation} when given a table, or {error} if nothing matches."""
156
+ s = get_sentry()
157
+ if assessment_id:
158
+ a = s.get_assessment(assessment_id)
159
+ if a is None:
160
+ return {"error": f"unknown assessment id {assessment_id}"}
161
+ return {"assessment_id": a.id, "explanations": {t.table: t.summary for t in a.tables}}
162
+ if table:
163
+ d = s.get_diff(table)
164
+ if d is None:
165
+ return {"error": f"no diff for {table} yet; call assess_change or preview_write first"}
166
+ return {"table": table, "explanation": _explain_diff(d)}
167
+ return {"error": "pass assessment_id or table"}
168
+
169
+
170
+ @_safe
171
+ def safe_to_ship(
172
+ assessment_id: Annotated[str, _desc("Id returned by assess_change or preview_write.")],
173
+ ) -> dict[str, Any]:
174
+ """Final gate: decide whether to merge or apply a change. Call this last,
175
+ and follow `next_step` exactly.
176
+
177
+ safe_to_ship is true only for pass and warn. For needs_human, do not merge:
178
+ open the PR with the report and request review from the listed owners. For
179
+ block, stop and fix the issues in rule_hits. Never bypass needs_human or
180
+ block. Read-only.
181
+
182
+ Returns {assessment_id, safe_to_ship: bool, verdict, risk_tier, rule_hits:
183
+ [{rule, verdict, table, reason}], notify, next_step}, or {error} if the id
184
+ is unknown."""
185
+ a = get_sentry().get_assessment(assessment_id)
186
+ if a is None:
187
+ return {"error": f"unknown assessment id {assessment_id}"}
188
+ v = a.verdict.value
189
+ next_step = {
190
+ "pass": "Proceed: open or merge the pull request.",
191
+ "warn": "Proceed, but include the warnings in the pull request description.",
192
+ "needs_human": "Do not merge. Open the pull request with the report and request review from: "
193
+ + (", ".join(a.notify) or "a data owner") + ".",
194
+ "block": "Stop. Fix the blocking issues listed in rule_hits, rebuild the candidate and assess again.",
195
+ }[v]
196
+ return {
197
+ "assessment_id": a.id,
198
+ "safe_to_ship": v in ("pass", "warn"),
199
+ "verdict": v,
200
+ "risk_tier": a.verdict.risk_tier,
201
+ "rule_hits": [h.to_dict() for h in a.hits],
202
+ "notify": a.notify,
203
+ "next_step": next_step,
204
+ }
205
+
206
+
207
+ @_safe
208
+ def rollback_plan(
209
+ table: Annotated[str, _desc("Fully qualified Delta table name.")],
210
+ ) -> dict[str, Any]:
211
+ """Get the exact SQL to restore `table` to its current Delta version.
212
+
213
+ Call this BEFORE applying a change and keep the SQL (e.g. in the PR or job
214
+ log), so undo is one statement if the change goes wrong. Read-only: it reads
215
+ DESCRIBE HISTORY and runs nothing.
216
+
217
+ Returns {table, current_version, rollback_sql}, e.g. "RESTORE TABLE
218
+ main.sales.orders TO VERSION AS OF 42", or {error}."""
219
+ s = get_sentry()
220
+ return {
221
+ "table": table,
222
+ "current_version": s.backend.current_version(table),
223
+ "rollback_sql": s.rollback_plan(table),
224
+ }
225
+
226
+
227
+ TOOLS = [whats_downstream, assess_change, preview_write, explain_diff, safe_to_ship, rollback_plan]
228
+ READ_ONLY = {"whats_downstream", "assess_change", "explain_diff", "safe_to_ship", "rollback_plan"}
@@ -186,6 +186,17 @@ class Sentry:
186
186
  out["preview"] = {"sandbox_table": clone if keep else None, "executed_sql": rewritten}
187
187
  return out
188
188
 
189
+ # --- alerts ---------------------------------------------------------------
190
+ def notify(self, assessment: Assessment, pr: str | None = None, force: bool = False) -> list[str]:
191
+ """Send a Slack / Teams alert for ``assessment`` if configured. Never raises."""
192
+ from bricksentry.notify import NotifySettings, send
193
+
194
+ try:
195
+ settings = NotifySettings.from_config(self.config.notify)
196
+ except ValueError as e:
197
+ return [f"notify: bad config ({e})"]
198
+ return send(assessment, settings, pr=pr, force=force)
199
+
189
200
  # --- lookups for agents -------------------------------------------------
190
201
  def get_assessment(self, assessment_id: str) -> Assessment | None:
191
202
  return self._assessments.get(assessment_id) or self._load(assessment_id)