ai-powered-conversational-intelligence

PROMPT 48 — ENTERPRISE BI INTEGRATIONS

Role

Act as a Principal AI Architect, Enterprise Data Platform Architect and Senior Product Engineer.

Mission

Integrate governed analytics with approved BI/productivity targets such as Power BI, Tableau, Looker or Excel. Inspect current APIs, visualization contracts, auth and semantic layer. Reuse governed metrics and permissions; do not create duplicate metric definitions. Implement secure export/connectors, refresh/status/error handling and audit. Preserve tenant identity and evidence metadata. Test authorization and refresh failures.

Mandatory workflow

INSPECT → PLAN → IMPLEMENT → TEST → REVIEW → FIX → DOCUMENT → REPORT

Mandatory controls

§0. Concurrent-work note

This prompt was executed in the same shared working tree as a separate, concurrent session’s own “Prompt 47” work (47_MODEL_ROUTING_COST_OPTIMIZATION_CONTRACT.md — governed model routing), which committed mid-task (89a4576’s successor) while this prompt’s own work was in progress. Five shared files were touched by both sessions at the same time: config/settings.py, .env.example, api/main.py, identity/models.py, identity/rbac.py, and CLAUDE.md. Every one was confirmed, by direct git diff, to carry cleanly separable, non-overlapping hunks — this session’s own edits were isolated via git stash push -- <file> / reapply-on-clean-base / git stash pop, per the user’s own standing direction from an earlier, structurally identical collision (“leave it alone, commit mine separately”). identity/models.py/identity/rbac.py’s own diffs were confirmed to be entirely this prompt’s own (the model-routing feature needed neither a new table nor a new RBAC permission) — no isolation was needed there.

§1. INSPECT — what already existed

§2. PLAN

  1. A new top-level package, bi_integration/, mirroring eval_platform/’s own recent shape (pure typed vocabulary, a deny-by-default policy module, zero-I/O helpers) plus the two genuinely new concerns this feature needs: outbound-call rendering (push.py) and SSRF hardening for a caller-supplied destination URL (outbound_safety.py).
  2. Persistence: identity.models.BiConnector + identity/repositories/bi_integration.py, mirroring EvaluationRun’s own “loose string reference to a governed asset, never a copy of its definition” shape, applied here to a semantic-catalog metric instead of a governance-center asset version.
  3. New RBAC (Permission.BI_INTEGRATION_MANAGE, single-tier — this feature has no SME-approval step the mission asks for, unlike ONBOARDING_*/CATALOG_*/GOVERNANCE_*) and a new REST surface, api/bi_integration.py, reusing POST /execute’s own governed execution sequence verbatim for every connector refresh.
  4. Behind Settings.enable_bi_integration (default off — the first genuinely external-network-calling feature in this prompt series since enable_web_search/ enable_media_generation, not a pure-compute engine).

§3. IMPLEMENT

§3.1 bi_integration/ — pure vocabulary, policy, and helpers

§3.2 The SSRF-duplication decision (a real, considered tradeoff, not an oversight)

media_gen/download.py’s own test suite (tests/test_media_gen.py) patches media_gen.download.log_security_event directly, at that module’s own namespace. Extracting the shared resolve-and-blocklist-check logic into a common module and having it call log_security_event would silently break that patch target (the call would then happen inside the new shared module’s namespace instead), a real risk to an already-audited, passing security test suite for a marginal de-duplication benefit on roughly 15 lines of logic. bi_integration .outbound_safety.assert_safe_outbound_url is therefore a deliberate, disclosed second copy, logging from its own namespace — the identical per-module-logs-its-own-event convention this codebase already uses at every other ssrf_blocked call site. Verified directly, via a live unittest.mock.patch("bi_integration.outbound_safety.log_security_event") test, that this module’s own rejections are independently audit-logged the same way.

§3.3 Push vs. pull: the honest shape of each target

Power BI’s push-dataset REST API and a Looker Action-Hub-shaped webhook are both genuinely implementable, documented, simple-POST integrations — real “push” connectors. Tableau and Excel have no equivalent generic push-dataset API this application could target without a live tenant to verify against; both are instead pull-style: GET /bi/connectors/{id}/export?format=... is a plain, authenticated CSV/XLSX/JSON file/feed a tool’s own generic “Web Data Connector”/ “Get Data from Web” connector can read. This is disclosed explicitly as not a native plugin — the real, honest shape of this integration without a live Tableau/Excel tenant, rather than a literal reading of the mission’s own named list that would have required inventing an unverifiable native-plugin claim.

§3.4 Persistence (identity/models.py + identity/repositories/bi_integration.py)

§3.5 RBAC (identity/rbac.py)

Permission.BI_INTEGRATION_MANAGE (admin tier) — a single permission, not a *_MANAGE/ *_REVIEW pair: every action a connector supports (create/refresh/export/delete) is equally operational, with no SME-approval/domain-judgment step the mission asks for the way onboarding/ catalog/governance each have.

§3.6 REST surface (api/bi_integration.py + api/bi_integration_schemas.py)

Six routes under /bi, behind Settings.enable_bi_integration (404 when off, the identical _require_enabled() pattern api/optimization.py/api/scenarios.py already establish):

§4. TEST

One real test-authoring mistake was caught and fixed before it could land as a wrong expectation: an initial CSV-export assertion expected bare \n line endings; csv.writer’s own default dialect correctly uses \r\n (RFC 4180) — fixed in the test, not the production code, which was already correct.

Testing summary: 68/68 new tests passing (30 + 12 + 26). ruff check/black --check clean on every touched/new file (several auto-fixable import-order/Yoda-condition findings, fixed; one UP038 tuple-isinstance style finding, fixed). bandit -r clean on every new production module, zero findings. mypy clean on every new production module after fixing two real Mapped[...]-nullable-column assignment gaps in identity/repositories/bi_integration.py (last_row_count/last_error, the identical Python-3.14 Mapped[...]-union-annotation workaround identity/models.py’s own module docstring already documents — fixed with # type: ignore[assignment] + an explanatory comment, matching identity/repositories /governance.py’s own established precedent for the identical pattern). The one remaining mypy finding across every file this prompt touched (db/schema_introspection.py:342) is confirmed pre-existing and untouched by this session via git diff --stat. Full-repo regression run (pytest -q, no filter) captured in the final report’s own “Tests and results” section.

§5. REVIEW / FIX

One real bug caught by mypy before any test exercised it: record_refresh_result’s own connector.last_row_count = row_count/connector.last_error = error assignments, where the ORM column is declared with its bare (non-Optional) type per this codebase’s own disclosed Python 3.14 Mapped[...]-union-annotation workaround — mypy correctly flagged the type mismatch even though the assignment is semantically correct (the column really is nullable at the database level, just annotated without | None on the Python side). Fixed with the identical # type: ignore [assignment] + explanatory-comment pattern identity/repositories/governance.py’s own nullable-FK assignments already establish, rather than leaving a type-incorrect-looking assignment with no explanation.

No other genuine review findings beyond ordinary lint/style nits (import ordering, Yoda conditions, nested-with consolidation), all fixed.

§6. DOCUMENT

§7. REPORT

See the final chat-turn report for the full inspected-areas/reused-components/files-changed/ API-DB-config-changes/tests-and-results/security-tenant-review/performance-cost-impact/ limitations/remaining-risks/recommended-next-prompt structure the mission’s own “Final report” section requires.