8: Data Governance

    Create and add descriptions/metadata about enterprise data to make it more discoverable.

    Key points

    Discoverability is the half of governance that production data engineers tend to under-invest in.

    A table without a description is still queryable, still secured, still on the bill, and still scanned by predictive optimization, but it is invisible to any analyst who does not already know the fully qualified name.

    The Unity Catalog search index, the Catalog Explorer UI, the Genie data rooms, and every downstream BI tool that pulls metadata over JDBC all read from the same surface:

    • the COMMENT text on each securable,
    • the TBLPROPERTIES key-value bag on each table,
    • the tags applied to objects at any level,
    • the structured certification and documentation URLs that ride along on the table descriptor.

    A senior data engineer treats those fields the same way a software engineer treats docstrings: an undocumented public interface is a defect, regardless of whether the runtime accepts it. The cost of skipping documentation surfaces three ways.

    • First, analysts re-derive the same Silver tables in their own Bronze workspaces, doubling storage and shifting the failure surface into ungoverned territory.
    • Second, when an upstream schema changes, the steward has no way to alert downstream consumers because the consumer list lives in nobody's spreadsheet.
    • Third, audit and lineage tools downgrade undocumented tables to "uncertified" status, which the privacy team then flags as a residual risk, which the security team then resolves by removing read access entirely.

    The pipeline that did the work disappears from the data product catalogue because no one wrote down what it produced.

    How it works

    Unity Catalog provides four documentation surfaces, each of which the exam tests separately.

    • The plain-text COMMENT is the most flexible because it accepts free-form prose up to 1024 characters per object.
    • The structured tag, attached through ALTER ... SET TAGS ('domain' = 'finance'), is the right surface for facets that an analyst will use to filter the catalogue.
    • The TBLPROPERTIES key-value bag is the right surface for technical metadata that pipelines read at runtime, such as classification level, retention window, or SLA tier.
    • The fourth surface, AI-generated comments, fills the column-level documentation gap by running a foundation model over a sample of rows and emitting a draft description that a steward reviews and accepts.

    The Catalog Explorer UI threads all four surfaces into a single page per object, and the workspace search bar reads the combined index.

    Search ranks results by exact name match first, then by COMMENT text contains, then by tag value contains, then by lineage proximity to objects the searcher already owns. Any documentation field a steward fills is immediately a signal that pushes the right object to the top of the search list when an analyst types a fragment of the table name or topic.

    Table and column comments

    Comments are written with the COMMENT clause on CREATE TABLE, with ALTER TABLE ... SET TBLPROPERTIES or COMMENT ON TABLE for retrofitting existing tables, and with ALTER TABLE ... ALTER COLUMN ... COMMENT for individual columns.

    The same SQL surface applies to catalogs, schemas, volumes, functions, and registered models with the corresponding COMMENT ON CATALOG, COMMENT ON SCHEMA, COMMENT ON VOLUME, COMMENT ON FUNCTION, and COMMENT ON MODEL statements.

    Free text is the right format for a description that explains:

    • the business question the table answers
    • the grain of a row
    • the refresh cadence
    • the canonical join keys
    -- Catalog and schema documentation: orientation for the data domain
    COMMENT ON CATALOG acme_prd IS
     'Production curated data for ACME Retail. Owned by the central data platform team. '
     'All datasets in this catalog have completed steward review and lineage validation. '
     'Contact: data-platform-oncall@acme.example';
    
    COMMENT ON SCHEMA acme_prd.sales IS
     'Sales transactional and analytical layer. Bronze in acme_prd.sales_bronze. '
     'Silver tables here are append-only with merge-into upserts on natural keys. '
     'Gold tables here are materialised views refreshed nightly at 02:00 UTC.';
    
    -- Table-level description, including row grain, SLA, and join keys
    COMMENT ON TABLE acme_prd.sales.fact_orders IS
     'One row per confirmed retail order across all channels. '
     'Grain: order_id. Join to dim_customer on customer_id, dim_product on product_id. '
     'SLA: rows available within 15 minutes of confirmation. '
     'Source: acme_prd.sales_bronze.orders_stream (Kafka topic orders.v3).';
    
    -- Column-level descriptions for the columns that drive joins, filters, and KPIs
    ALTER TABLE acme_prd.sales.fact_orders
     ALTER COLUMN order_id COMMENT 'Surrogate key for the order. Unique across all channels and regions.';
    
    ALTER TABLE acme_prd.sales.fact_orders
     ALTER COLUMN order_status COMMENT
     'Lifecycle state of the order. One of CONFIRMED, FULFILLED, RETURNED, CANCELLED. '
     'Only CONFIRMED orders count toward gross-orders KPI; FULFILLED is the revenue-recognition trigger.';
    
    ALTER TABLE acme_prd.sales.fact_orders
     ALTER COLUMN customer_id COMMENT 'FK to acme_prd.sales.dim_customer.customer_id. Nullable for guest checkout.';
    

    Comments are mutable through the same ALTER surface, which matters for the schema-evolution workflow.

    When a column is added by an upstream contract change, the on-call engineer should write the column comment in the same pull request that adds the column to the Silver promotion job.

    The reviewer rejects the PR if the comment is missing, which makes documentation a build-time concern rather than a backlog-cleanup concern.

    💡 Exam Trap: COMMENT ON COLUMN is not a valid Databricks SQL statement. Column comments require either the COMMENT 'text' clause inline in CREATE TABLE, or ALTER TABLE <name> ALTER COLUMN <col> COMMENT 'text'. Questions that present COMMENT ON COLUMN acme.sales.fact_orders.customer_id as the answer are distractors.

    Tags on catalog objects

    Tags are key-value pairs attached to a securable through ALTER ... SET TAGS.

    They are the right surface for facets that the catalogue search needs to slice across:

    • domain
    • data product
    • sensitivity
    • owner team
    • refresh cadence
    • SLA tier

    The key is up to 255 characters and the value is up to 1000 characters; both are case-sensitive.

    A securable can hold up to 20 tags, which forces stewardship discipline because the steward has to choose the small set of facets that matter most for that object.

    -- Tag the catalog with high-level facets
    ALTER CATALOG acme_prd
     SET TAGS ('environment' = 'production',
     'data_owner' = 'data_platform_team',
     'cost_center' = 'CC4271');
    
    -- Tag the schema with domain ownership
    ALTER SCHEMA acme_prd.sales
     SET TAGS ('domain' = 'sales',
     'data_steward' = 'jdoe@acme.example',
     'sla_tier' = 'tier1');
    
    -- Tag the table with the data product slug and the row grain
    ALTER TABLE acme_prd.sales.fact_orders
     SET TAGS ('data_product' = 'sales-orders-v3',
     'grain' = 'order',
     'pii_level' = 'low',
     'retention_days' = '2555');
    
    -- Tag specific columns that drive privacy and compliance behaviour
    ALTER TABLE acme_prd.sales.fact_orders
     ALTER COLUMN customer_id
     SET TAGS ('classification' = 'pseudonymous_identifier');
    
    -- Drop a tag when the facet no longer applies
    ALTER TABLE acme_prd.sales.fact_orders
     UNSET TAGS ('grain');
    

    Tags are inheritable for search ranking but not for access decisions.

    An analyst who types domain:sales sla_tier:tier1 into Catalog Explorer matches the schema and every table inside it through tag inheritance at search time, even when the table has not been individually tagged with domain = sales.

    The same domain = sales tag is also the natural attribute against which attribute-based row filters and column masks can later be defined, so writing the tag once early in the table's life lets the security team build access policies later without retroactively rewriting metadata.

    TBLPROPERTIES for technical metadata

    TBLPROPERTIES is the right surface for metadata that a pipeline reads at runtime rather than metadata that a human reads in the UI.

    The previous chapter on data security and compliance already covered the convention of writing pii_level, data_classification, retention_days, and subject_rights_path through TBLPROPERTIES; that pattern remains the audit-of-record surface because system tables and downstream automation read it deterministically.

    Comments and tags belong to the human-discoverability layer; properties belong to the machine-readable layer.

    -- Combine human-readable comments with machine-readable properties on the same table
    CREATE TABLE acme_prd.sales.dim_customer (
     customer_id STRING COMMENT 'Surrogate key. Stable across all channels and regions.',
     customer_hk STRING COMMENT 'SHA-256 salted hash of customer email; safe to expose to downstream analytics.',
     loyalty_tier STRING COMMENT 'One of BRONZE, SILVER, GOLD, PLATINUM.',
     signup_date DATE,
     pii_redacted_at TIMESTAMP
    )
    USING DELTA
    CLUSTER BY (loyalty_tier, signup_date)
    COMMENT 'Customer dimension with SCD Type 2 history on loyalty_tier. One row per customer per loyalty change.'
    TBLPROPERTIES (
     'delta.enableChangeDataFeed' = 'true',
     'delta.enableDeletionVectors' = 'true',
     'pii_level' = 'medium',
     'data_classification' = 'restricted_internal',
     'retention_days' = '2555',
     'data_product' = 'customer-360-v2',
     'refresh_cadence' = 'hourly',
     'source_system' = 'salesforce_crm'
    );
    

    When an audit tool walks the metastore, it reads the TBLPROPERTIES bag from system.information_schema.table_tags and system.information_schema.tables.table_properties to build the classification report. When an analyst searches the Catalog Explorer, the same audit tool can be configured to write a human-readable summary into the table's COMMENT field as a derived artifact, which keeps the two surfaces consistent without requiring the steward to update both manually.

    📊 Limit: Tags allow up to 20 per securable, with keys up to 255 characters and values up to 1000 characters. TBLPROPERTIES allows up to 1024 properties per table, with keys up to 255 characters and values up to 1024 characters. COMMENT text is capped at 1024 characters on any single securable.

    AI-generated comments

    The AI-generated comment surface is the production answer to the documentation backlog problem.

    A typical mature lakehouse contains thousands of Silver and Gold tables, tens of thousands of columns, and a steward team of perhaps three. Hand-writing a comment for every column is not a finite project.

    The Catalog Explorer in a UC-enabled workspace exposes an "AI generate" affordance on the column description field, which reads a sample of column values and the column name, runs the request through the Mosaic AI foundation model gateway configured for the workspace, and returns a draft description that the steward edits and accepts.

    The drafting model receives only the column name, the column data type, and a small sampled set of distinct values. It does not receive row-level data outside the sample.

    The output is a single sentence that names the entity and notes any obvious format pattern, for example "Primary identifier for the customer, formatted as an eight-character alphanumeric code."

    The draft remains in pending state until the steward clicks Accept; accepted drafts are written through the same ALTER TABLE ... ALTER COLUMN ... COMMENT path described above, so the final stored representation is indistinguishable from a hand-written comment.

    # Programmatic batch acceptance of AI-suggested comments through the SDK
    # This is the pattern stewards use to clear hundreds of pending suggestions in bulk
    from databricks.sdk import WorkspaceClient
    
    w = WorkspaceClient()
    
    # Iterate over all tables in a target schema and emit AI suggestions for any
    # column that lacks a comment. The Catalog Explorer would do the same for a
    # single table in the UI; this script applies the pattern at schema scale.
    TARGET_CATALOG = "acme_prd"
    TARGET_SCHEMA = "sales"
    
    for table in w.tables.list(catalog_name=TARGET_CATALOG, schema_name=TARGET_SCHEMA):
     full_name = f"{TARGET_CATALOG}.{TARGET_SCHEMA}.{table.name}"
     for column in table.columns or []:
     if column.comment:
     continue
     # The actual AI suggestion endpoint is called by the Catalog Explorer
     # behind the scenes; this code shows the pattern by which a steward
     # would accept the suggestion via the SDK once it has been generated.
     suggested = _fetch_suggested_comment(full_name, column.name)
     if suggested is None:
     continue
     w.statement_execution.execute_statement(
     warehouse_id="abc123def456",
     statement=(
     f"ALTER TABLE {full_name} "
     f"ALTER COLUMN {column.name} COMMENT '{suggested.replace(chr(39), chr(39)*2)}'"
     ),
     )
    

    The AI-generated comment is not a substitute for steward judgment.

    Sample-based generation can mislabel a column whose values look like one thing but mean another, for example a column called code that stores postal codes when the model guesses currency codes.

    The steward review step is the safeguard.

    The exam expects candidates to know that AI suggestions are draft state, never automatically committed, and reviewable through the Catalog Explorer pending-suggestion queue.

    ⚠️ Anti-Pattern: Wiring AI-suggested comments straight to a scheduled ACCEPT_ALL job that bypasses steward review. The model is good enough to fill gaps but not good enough to be trusted with a definition for a regulated column. Accepting every suggestion automatically poisons the catalogue with confidently wrong descriptions that downstream search will surface to analysts as authoritative.

    Certification, documentation URLs, and the search index

    Beyond comments and tags, Unity Catalog exposes two further structured fields on tables: a certification flag for stewardship status and a documentation URL for the long-form description that does not fit in a 1024-character comment.

    The certification flag is a boolean that the steward toggles after manually reviewing the table; certified tables float to the top of search results and are visible in the data-product catalogue at the workspace level.

    The documentation URL is a link to a Confluence page, an internal data-product portal, or a Git-hosted markdown file; Catalog Explorer renders it as a clickable link in the table description panel.

    -- Mark the table as steward-reviewed and link to external documentation
    ALTER TABLE acme_prd.sales.fact_orders
     SET TBLPROPERTIES (
     'documentation_url' = 'https://data-portal.acme.example/products/sales-orders-v3',
     'steward_review_date' = '2120-04-12',
     'steward_reviewer' = 'jdoe@acme.example'
     );
    

    The search index refreshes within a small number of minutes after a change to comments, tags, or properties.

    A common production pattern is to wire the CI job for the Silver promotion to write the comment and tags from a sidecar YAML file that lives next to the pipeline source, which keeps the documentation in version control alongside the code that produces the data.

    The same CI job runs a check that fails the build if any newly added column lacks a comment, which enforces the documentation contract on every change.

    # data_contracts/fact_orders.yaml
    # Sidecar contract file. The CI step renders this into ALTER TABLE statements.
    catalog: acme_prd
    schema: sales
    table: fact_orders
    description: |
     One row per confirmed retail order across all channels.
     Grain: order_id. SLA: rows available within 15 minutes of confirmation.
    tags:
     data_product: sales-orders-v3
     grain: order
     pii_level: low
     retention_days: '2555'
    properties:
     documentation_url: https://data-portal.acme.example/products/sales-orders-v3
     refresh_cadence: streaming
     source_system: kafka_orders_v3
    columns:
     - name: order_id
     description: Surrogate key for the order. Unique across all channels and regions.
     - name: order_status
     description: |
     Lifecycle state of the order. One of CONFIRMED, FULFILLED, RETURNED, CANCELLED.
     Only CONFIRMED orders count toward gross-orders KPI.
     tags:
     classification: business_metric_driver
     - name: customer_id
     description: FK to acme_prd.sales.dim_customer.customer_id. Nullable for guest checkout.
     tags:
     classification: pseudonymous_identifier
    

    Information schema as the source of truth for metadata audits

    Once descriptions and tags are in place, the audit surface is system.information_schema. Every UC metastore exposes a per-catalog information_schema containing catalogs, schemata, tables, columns, views, volumes, routines, routine_columns, catalog_tags, schema_tags, table_tags, column_tags, volume_tags, and routine_tags views. The metadata audit runs as a SQL query over these views; the result is the inventory the steward team uses to find documentation gaps.

    -- Find every Silver table in the production catalog that lacks a comment
    SELECT table_catalog,
     table_schema,
     table_name,
     table_owner,
     created
    FROM system.information_schema.tables
    WHERE table_catalog = 'acme_prd'
     AND table_schema LIKE '%_silver'
     AND (comment IS NULL OR length(trim(comment)) = 0)
     AND table_type = 'MANAGED'
    ORDER BY created DESC;
    
    -- Find every column without a comment in any Gold table
    SELECT c.table_catalog,
     c.table_schema,
     c.table_name,
     c.column_name,
     c.data_type
    FROM system.information_schema.columns c
    JOIN system.information_schema.tables t
     ON c.table_catalog = t.table_catalog
     AND c.table_schema = t.table_schema
     AND c.table_name = t.table_name
    WHERE c.table_catalog = 'acme_prd'
     AND c.table_schema LIKE '%_gold'
     AND (c.comment IS NULL OR length(trim(c.comment)) = 0)
    ORDER BY c.table_schema, c.table_name, c.ordinal_position;
    
    -- Find every table that is tagged as tier1 SLA so the on-call rotation can subscribe to alerts
    SELECT tt.catalog_name, tt.schema_name, tt.table_name, tt.tag_value
    FROM system.information_schema.table_tags tt
    WHERE tt.tag_name = 'sla_tier'
     AND tt.tag_value = 'tier1'
     AND tt.catalog_name = 'acme_prd';
    

    The Catalog Explorer search bar reads from the same underlying index, but information_schema is the right surface for scheduled audits because it is queryable from SQL warehouses, Lakeflow Jobs, and SQL Alerts. A nightly SQL Alert on the first query above routes a Slack message to the steward team listing any newly created table without a comment; the alert closes when the team writes the comment.

    💡 Exam Trap: system.information_schema is per-catalog, not workspace-global. Each catalog has its own information_schema. To audit metadata across the entire metastore, query system.information_schema.tables, which is the metastore-wide aggregation view, rather than acme_prd.information_schema.tables, which is scoped to the single catalog.

    🎯 Scenario: The platform team rolls out a discoverability initiative. The brief is to make every Gold table in acme_prd searchable by domain and data product, and to fail any CI build that ships a new Gold table without a comment. The engineer writes a sidecar contracts/*.yaml file alongside each pipeline source, renders it into ALTER TABLE statements at deploy time through Databricks Asset Bundles, runs a SQL Alert against system.information_schema.tables to detect undocumented additions, and configures the Catalog Explorer search index to expose the data_product tag as a primary facet. Within one refresh cycle the analyst team reports a measurable drop in duplicate-table creation; the steward team reports the on-call queue is now zero.

    Decision Anchor for the documentation surface

    When to use

    • Choose COMMENT text when the audience is a human reading the Catalog Explorer or a downstream BI tool that pulls comment text into its own metadata pane.
    • Choose TBLPROPERTIES when the audience is a pipeline or an audit job that reads the value at runtime and behaves differently based on it.
    • Choose tags when the audience is the search index and the facet has fewer than ten distinct values across the catalog.
    • Choose AI-generated comments when the column-level documentation gap exceeds the steward team's manual throughput and you have the review queue capacity to ratify suggestions before they ship.

    ⚠️ Anti-Pattern: Storing classification or retention metadata only in the COMMENT text rather than in TBLPROPERTIES. The compliance audit job reads system.information_schema.tables.table_properties deterministically; it cannot parse free-form comment prose. A table whose comment says "retention 7 years" but whose retention_days property is missing will be flagged by the audit as having no retention policy at all.


    Continue with the interactive course

    Track your progress, jump into practice questions and use the Shark AI tutor inside the Databricks - Data Engineer Professional learning hub.