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).

You can read more about this project in a blog post Deploying Databricks Genie Agents to multiple environments with 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 or volume 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.

The same rules apply to Unity Catalog volume paths: in volume data sources (data_sources.volumes[].path, used by Genie Agents that read files in volumes) and in any text or SQL, /Volumes/<catalog>/<schema>/<volume>/... is matched as the name catalog.schema.volume. With main.gold: dev.gold_v2, /Volumes/main/gold/raw/ becomes /Volumes/dev/gold_v2/raw/. A 3-part rule renames a table or a volume with that name.

After a rewrite, the mutator sorts data_sources.tables by identifier and data_sources.volumes by path, 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.
  • Tables, volumes, schemas, and catalogs are retargeted. Other data sources (for example, MCP connections) are not changed.
  • 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.2.0

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.2.0
File Size Uploaded Provenance Actions
pydabs_genie_agent_retarget-0.2.0.tar.gz 45.0 kB With provenance Details for pydabs_genie_agent_retarget-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 57.3 kB

Release files / pydabs_genie_agent_retarget-0.2.0.tar.gz

Download URL pydabs_genie_agent_retarget-0.2.0.tar.gz
Size 45.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6b6c5a1ea9378975b19292e26df4572438dfe66b168ac3fd48fe0a95a2648889
BLAKE2b-256 checksum
How to use checksums
85b52610afd28e506541009e099d71c610cd3183522bb792fdee920bef98d698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 10, 2026.

Transparency log

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

Download URL pydabs_genie_agent_retarget-0.2.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e79980ed5f961b64fbc9185c7fdadae2f342443b80b68bf34c1f9c568e2502c
BLAKE2b-256 checksum
How to use checksums
4e1e0866f985949d1d7d031c71947debd3ba7772c39a54e4f261cc6b851602cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 10, 2026.

Transparency log

Security for pydabs-genie-agent-retarget 0.2.0

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.2.0.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 Nov 10, 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