Skip to main content

pydabs-genie-agent-retarget

This project allows to rewrite Unity Catalog references in Databricks Genie Agent (formerly Genie space) definitions when you deploy them with Declarative Automation Bundles (DABs).

A serialized Genie space hardcodes catalog.schema.table names in table identifiers, join specs, SQL snippets, example and benchmark SQL, and text instructions. genie_agent_retarget is a Python mutator for DABs that rewrites all of them per target with prefix rules:

Rule level Example
table main.intel.oss_iocs: ${var.catalog}.intel.iocs
schema main.gold: ${var.catalog}.${var.gold_schema}
catalog main: ${var.catalog}

The most specific rule wins, and each name is rewritten once (rules never chain). Matching is case-insensitive and handles backtick-quoted names, in the space and in the rules. A rule whose two sides have a different number of parts fails databricks bundle validate.

After a rewrite, the mutator sorts data_sources.tables by identifier, because the Genie API rejects an unsorted list. If a table rule renames a table, the mutator also renames the short table qualifiers in SQL fields: join specs, SQL snippets (filters, measures, expressions), example SQL, and benchmark SQL (oss_iocs.ioc_type = 'URL' becomes iocs.ioc_type = 'URL'). It skips a short name that another table of the space also has, because it is ambiguous.

Usage

  1. Add the package to the bundle's virtual environment (with uv):

    [dependency-groups]
    dev = [
        "databricks-bundles==1.19.0",
        "pydabs-genie-agent-retarget",
    ]
    

    databricks-bundles is a dependency of pydabs-genie-agent-retarget; pin it in your project to match your Databricks CLI version. Or copy src/genie_agent_retarget.py next to databricks.yml. It has no dependencies except databricks-bundles.

  2. Register the mutator and define the genie_table_mapping variable in databricks.yml:

    python:
      venv_path: .venv
      mutators:
        - 'genie_agent_retarget:retarget_genie_spaces'
    
    variables:
      genie_table_mapping:
        type: complex
        default:
          main.gold: ${var.catalog}.${var.gold_schema}
    
  3. Keep each space as src/<name>.geniespace.json (the output of databricks bundle generate genie-space) and reference it with file_path.

Use genie_table_mapping: {} in a target that needs no rewriting.

Command line

The same code works on a single file. This is useful when you export a space from an environment that is not the authoring one, and must convert it back to the authoring names:

python -m genie_agent_retarget src/x.geniespace.json --in-place \
  -m dev_catalog.gold_dev=main.gold

Example

example/ deploys 3 Genie spaces (CVE analysis, IoC analysis, and Lakewatch security operations over 22 OCSF gold tables). Each data source location is a variable (ocsf_schema, cve_schema, iocs_table):

  • dev moves the spaces to other schemas and renames one table.
  • azure deploys them to another workspace, where the data is in other catalogs and schemas.
  • prod keeps the names, so the files are deployed without changes.
cd example
uv sync
databricks bundle validate -t dev
databricks bundle deploy -t dev

The example uses names from our environments: the CLI profiles (lw-field, az-alexott), the catalogs and schemas of each target, and the warehouse name. The JSON files keep the names they were authored against (fe_lakewatch_catalog...), because the rules map from these names. To try the example in your workspace, change workspace.profile, warehouse_name, and the ocsf_schema, cve_schema, and iocs_table variables of a target to your tables. The tables must have the same columns, otherwise the instructions and example SQL of the spaces do not match the data.

The tables must exist before you deploy (see Limitations).

If the DATABRICKS_CONFIG_PROFILE environment variable is set, the CLI uses that profile instead of the target's workspace.profile. Unset it when you deploy targets that use different workspaces.

Limitations

  • The rules work only with 3-part names. If the SQL in a space uses unqualified table names (FROM authentication), the mutator does not change it, and the query uses the default catalog and schema of the session. Genie writes fully-qualified names into serialized content by default, so this is mainly a problem for SQL that was written by hand.
  • A catalog rule rewrites any 3-part name that starts with this catalog, in any field. If your catalog has the same name as a struct column (for example, a catalog actor), a struct path such as actor.user.name is also rewritten. In this case, use schema rules instead.
  • The Genie API checks that all tables of the space exist when it creates or updates the space. If a table does not exist, the deployment fails with an error such as Table 'main.gold.authentication' does not exist. So in a new environment, the tables must exist before you deploy the space. If the same bundle has the jobs that create these tables, keep the spaces in a separate bundle, and deploy it after the jobs ran for the first time.
  • The mutator changes only table references. Set other values of the space, such as the warehouse ID, with fields of the resource declaration and bundle variables.
  • Only tables, schemas, and catalogs are retargeted. Other data sources, such as Unity Catalog volumes, are not supported yet.
  • databricks bundle generate genie-space --watch downloads the deployed definition. If you edit the space in a target that uses other table names, the downloaded file contains those names. Edit the space in the target whose names match the JSON files, or convert the file back with the command line.

Tests

uv sync && uv run pytest

License

This project is licensed under the Databricks License.

Metadata

Release files for pydabs-genie-agent-retarget 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydabs-genie-agent-retarget 0.1.2
File Size Uploaded Provenance Actions
pydabs_genie_agent_retarget-0.1.2.tar.gz 43.2 kB With provenance Details for pydabs_genie_agent_retarget-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydabs-genie-agent-retarget 0.1.2
File Interpreter ABI Platform Actions
pydabs_genie_agent_retarget-0.1.2-py3-none-any.whl Python 3 none any Details for pydabs_genie_agent_retarget-0.1.2-py3-none-any.whl

Total release size: 54.9 kB

Release files / pydabs_genie_agent_retarget-0.1.2.tar.gz

Download URL pydabs_genie_agent_retarget-0.1.2.tar.gz
Size 43.2 kB
Tags Source
SHA-256 checksum
How to use checksums
64a6d32da71407edcd79a1dd7c8cecb9c1ebe999200da0eeac56af0dcb6eaac2
BLAKE2b-256 checksum
How to use checksums
4d6fb1d18e654c8c0cfae98d686f8dd54870767a79da82aba6726a88df598188
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release files / pydabs_genie_agent_retarget-0.1.2-py3-none-any.whl

Download URL pydabs_genie_agent_retarget-0.1.2-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0650b04cebf0c144ac1ac74690b85182ecf491171708b01167bb3b8ed6d999e6
BLAKE2b-256 checksum
How to use checksums
1663ac58a5c7327180a0de71dfe3d9dd0f2daf64e9865c47a7045d0e8ddcb15e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Security for pydabs-genie-agent-retarget 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydabs_genie_agent_retarget-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page