# Cortex Framework extensibility guide

**[Google Cloud Cortex Framework](https://docs.cloud.google.com/cortex/docs/overview.md.txt)** provides data product
accelerators for advanced analytics and AI. This documentation explains how to
customize and extend Cortex Framework.

For proper isolation and lifecycle management, package custom foundation and
data product modules within a
**[custom namespace](https://docs.cloud.google.com/cortex/docs/extensibility-guide-namespaces.md.txt)**. This guide
covers the following major areas of extensibility:

- **[Data foundation module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-foundation.md.txt)**: Register custom data modules to define custom compilation behaviors or ingest tables from source systems not supported out of the box (for example, PostgreSQL or MySQL databases).
- **[Data product module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-product.md.txt)** : Create new analytical data products with custom logic using Dataform JavaScript (`.js`) definitions (recommended) or `.sqlx` files.
- **[Agentic creation of data products](https://docs.cloud.google.com/cortex/docs/agentic-skills-for-data-product-building.md.txt)**: Use the packaged AI coding assistant skills to configure workspaces, onboard sources, inspect schemas, generate ER diagrams, scaffold and extend data products, run unit tests and validation gates, and deploy validated artifacts.

> [!NOTE]
> **Note:** You don't need to create a custom data foundation module to ingest and transform additional standard or custom tables. You can add extra tables directly to the table configuration of the standard modules, or configure multiple instances of the existing modules in `config/config.yaml` as described in [Deployment configuration](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt#add-table-to-data-foundation).

> [!NOTE]
> **Note:** If you want to add custom code (such as `.js` or `.sqlx` files) directly in your remote Dataform workspace in the Google Cloud console without creating a full data product module in source control, place it inside the `definitions/custom/` directory. Otherwise, your custom files are deleted or overwritten during the next Cortex Framework deployment run (`cortex-deploy`).

## Extensibility architecture

Cortex Framework separates core build orchestration from source
system and domain content across four explicit contract surfaces:

| Contract surface | Audience | Mechanism |
| Tier 1: Declarative YAML | Workspace and module authors (no Python required) | `config.yaml`, `manifest.yaml`, `table_settings.yaml`, `table_settings.default.yaml`, `inlineTableSettings`, and `annotations/<table>.yaml`. |
| Tier 2: Model runtime JavaScript (`includes/*.js`) | Dataform model authors | Vendor-neutral runtime helpers in `includes/*.js` (`publisher.js`, `publish_config.js`, `incremental.js`, `assertion_helper.js`, `blocking_assertions.js`, `security_helper.js`, `sql_helper.js`, `label_helper.js`, and `date.js`) plus build-injected `moduleContext` and `tableConfig` objects. |
| Tier 3: Python Plugin SDK (`common.sdk`) | Custom builder, schema, and metadata plugin authors | Single public Python import surface (`from common.sdk import ...`) backed by structural protocols, Pydantic v2 models, immutable `ResolvedWorkspace` nodes, root-anchored `<namespace>/{builders,metadata,schemas}/` directories, and deterministic `ModuleCatalog` and `BuilderResolver` discovery. |
| Content-to-content data contract | Cross-module BigQuery dependencies | Declared upstream `dependencies` in `manifest.yaml` bound through `dependencyBindings` in `config.yaml` (`ResolvedFoundationModule`, `ResolvedProductModule`, or `ResolvedCatalogBinding`). |
|---|---|---|

> [!IMPORTANT]
> **Important:** Author custom foundation and data product models as Dataform JavaScript (`.js`) definitions using `publisher.publish()` or `publisher.operate()` from `includes/publisher.js` rather than `.sqlx` files or bare Dataform `publish()` and `operate()` calls. `.sqlx` files and ungated calls bypass `includes/publisher.js` compile-time hooks, which attach upstream `blocking: true` [data quality assertions](https://docs.cloud.google.com/cortex/docs/data-quality-assertions.md.txt) to downstream action dependencies and, in `publisher.publish()`, enforce [row- and column-level security](https://docs.cloud.google.com/cortex/docs/row-and-column-security.md.txt) governance (column policy tags, row-level security post-operations DDL, and zero-fail-open refreshes).

## Example scenarios

The following extensibility guides walk through practical end-to-end scenarios:

- **Custom namespace setup** : Package and isolate custom foundations, data products, shared `includes/*.js` helpers, SQL assertion templates, and Python plugins inside a dedicated custom namespace (such as `ticketing` or `sap_bookingdatamodel`). See [Custom namespace setup](https://docs.cloud.google.com/cortex/docs/extensibility-guide-namespaces.md.txt#custom-namespace-configuration) for details.
- **Custom data foundation module** : Walks through creating a custom PostgreSQL `ticketing` foundation (`customers`, `tickets`, and `ticketlogitem` tables) in the `ticketing` namespace, including a Python `FoundationBuilder` plugin built on `common.sdk`. See [Data foundation module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-foundation.md.txt) for details.
- **Custom data product modules** : Walks through an SAP ERP versioned data product (`flights_usd` in `sap_bookingdatamodel` using `sap_product`, joining `sflight` with `tcurr` to convert flight pricing into USD) and a cross-source composite data product using `flat_product` that combines SAP deliveries, Salesforce accounts, and Google WeatherNext forecasts from BigQuery sharing. See [Data product module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-product.md.txt) for details.

## What's next

- [Setting up a custom namespace](https://docs.cloud.google.com/cortex/docs/extensibility-guide-namespaces.md.txt)
- [Data foundation module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-foundation.md.txt)
- [Data product module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-product.md.txt)