Snowflake assessment tools

Normalize approved metadata exports

This offline stdlib tool converts recorded exports into the existing 13-table practices schema. It does not connect to Snowflake, classify patient data, verify operator privileges, create client findings, or supply missing business context. It supports warehouse configuration/load, successful query work, and explicitly prepared role/privacy/operator inputs. Missing evidence stays UNKNOWN.

Inputs and operator workflow

Obtain owner approval for account, exact warehouse allowlist, assessment period, role visibility, metadata export handling and retention. Use capture to render and record client-run metadata exports with the true query ID, observation time and operator attestation. Keep synthetic rehearsals separate from client evidence. Record actual account/role declarations; these files do not authenticate them.

Run from this checkout, with fresh output outside it:

PYTHONPATH=src python3 -m sf_eval.normalize --help
PYTHONPATH=src python3 -m sf_eval.normalize --input /tmp/assessment-config-capture --input /tmp/assessment-load-capture --input /tmp/assessment-query-capture --output /tmp/assessment-normalized --context /tmp/assessment-owner-context.json
PYTHONPATH=src python3 -c 'from pathlib import Path; from sf_eval.normalize import validate_normalized; manifest, database = validate_normalized(Path("/tmp/assessment-normalized")); print(manifest["evidence_kind"], database)'
PYTHONPATH=src python3 -m unittest discover -s tests -p test_normalize.py -v

Omit --context when no attributed context is available. Repeat --input for one to twelve capture directories; a parent directory is not implicitly searched. Each source table may occur only once across all captures and context. All captures must agree on account, role, operational window, evidence kind, warehouse allowlist and row limit. File hashes and actual parsed row counts must reconcile. Inputs are never written.

Native CSV mappings

Headers must exactly match these sets, with no extra columns, duplicate names or malformed record widths. Order may differ. Empty cells mean null; numeric zero remains zero. Patient rows, query text and bind values are not accepted.

Native COMPLETE sources require an attestation and real query ID. COMPLETE at zero rows or the row cap is rejected; capture must label zero EMPTY and a reached cap PARTIAL. DENIED, UNSUPPORTED and UNKNOWN cannot carry data rows. PARTIAL preserves all supplied rows without upgrading coverage or health.

Manual normalized CSV and owner context

Every other input uses source_kind: normalized_csv, exact normalized column headers below, and a nonempty manual_source provenance field in its capture record. This route supports all twelve input tables. It does not interpret native grant strings, reconstruct object names, infer role edge direction, classify columns or synthesize policy lifecycle. Manual COMPLETE evidence requires an attestation; query ID may be null because interview facts have no native query ID. Actual source/window/count/hash metadata remain mandatory. Manual QUERY_WORK additionally requires the exact typed field query_population: "SUCCESS_COMPLETED" in its source record, attributable through manual_source and attestation. Missing or unsupported declarations reject the entire export. This field is forbidden for all other source kinds/tables; a native query export instead proves its supported population structurally through EXECUTION_STATUS. An attributable declaration is not authenticated evidence and does not make failed queries successful.

Context JSON has the following strict schema. Its account/evidence kind must match the capture. attributed_to and attestation are required nonempty declarations. warehouse_owner_targets_ms must be an object (use {} if none); supplied values are positive finite milliseconds or null. Optional tables provides explicitly prepared rows for any of the twelve input tables and cannot replace a captured table. Each entry has exactly rows,status,observed_at,artifact; a QUERY_WORK entry must also supply query_population: "SUCCESS_COMPLETED". No other context table accepts that field. Each row has exactly all schema column names. JSON null preserves unknown values. Status and cap rules match capture inputs. Never copy synthetic fixture controls into client targets or context.

{
  "schema_version": "sf-assessment-context-v1",
  "account": "DECLARED_APPROVED_ACCOUNT",
  "evidence_kind": "client_metadata",
  "attributed_to": "Named accountable platform owner",
  "attestation": "Owner reviewed these declared targets and linked evidence",
  "warehouse_owner_targets_ms": {},
  "tables": {
    "QUERY_CONTEXT": {
      "status": "PARTIAL",
      "observed_at": "2026-11-05T15:00:00Z",
      "artifact": "Approved query review register reference",
      "rows": [{
        "QUERY_ID": "owner-selected-query-id",
        "PURPOSE": "FULL_AGGREGATION",
        "EXPECTED_JOIN_CARDINALITY": "NOT_APPLICABLE",
        "REPRESENTATIVE": null,
        "PROFILE_STATUS": "UNAVAILABLE",
        "MAX_SCAN_RATIO": null,
        "MAX_JOIN_EXPANSION": null
      }]
    }
  }
}

Manual context source records retain the context file checksum, attributable owner, artifact reference, observation time, attestation and count, with a null native query ID. The operator remains responsible for underlying artifact accuracy and approval. Missing purpose/threshold/exception data is not guessed; full aggregation and NOT_APPLICABLE join context remain intact.

Exact normalized columns and types

The authoritative unchanged schema is schema.json. T = TEXT (timestamps require UTC ISO YYYY-MM-DDTHH:MM:SS[.ffffff]Z); I = signed 64-bit INTEGER; R = finite REAL. All columns permit null to retain source uncertainty. Unknown/inapplicable ratios remain null, never defaults. Numeric strings parse strictly for CSV; NaN/infinity are rejected. Operational records must be fully within the declared window when endpoints exist. Current snapshots and grant lifecycle timestamps are not forced into that historical window.

SOURCE_COVERAGE is generated only: exactly thirteen rows, one for each table, with missing sources UNKNOWN and their observation time null. Its own COMPLETE status means the coverage register was generated, not that source populations or the estate are healthy. Source rows retain actual observed times and declared operational windows.

Repeated WAREHOUSE_CONFIG.WAREHOUSE_NAME identities reject across native CSV, normalized CSV and manual context, including identical rows or different snapshot timestamps: the input is one current snapshot per warehouse. Reconcile snapshots before collection instead of feeding contradictory configurations into advisory SQL. Historical role grant/revocation records are not subject to this warehouse-only uniqueness rule.

Output, checks and limits

Output contains normalized.sqlite and manifest.json (sf-assessment-normalized-v1). The manifest records evidence kind, account/role/window/allowlist, database filename/checksum, row counts, all thirteen source states, input manifest checksums, original source_records, query execution statuses and manual context provenance. Files do not provide cryptographic authentication: checksums detect changed bytes, while source accuracy and completeness remain operator attestations. Do not edit manifests to relabel synthetic evidence as client evidence.

validate_normalized(Path(...)) returns (manifest, database_path) after readonly immutable SQLite checks: checksum, exact tables/columns/types, no extra views/triggers, finite/UTC typed cells, counts, source statuses, thirteen-row coverage consistency, warehouse/time bounds, current warehouse uniqueness, typed manual query population, native query ID/status-map consistency and SQLite integrity. It rejects existing fixture manifests. The advice engine uses this API before executing the protected SQL. It never writes the input database.

Limits: one to twelve captures, at most 10,000 rows per input table, at most 1,000 exact warehouse names, maximum 20 MiB per input file/database and 4,096 characters per text value. No symlinks (including ancestors), traversal paths, in-checkout output, existing output directory, arbitrary SQL or implicit network access. JSON duplicate keys and nonfinite constants reject. Failures abort before creating the output except unexpected filesystem/database errors; discard an incomplete output and choose a new destination. No native execution or client health qualification is claimed. Manual fallback is the exact CSV contract plus owner-attributed context, not a generated fixture.

The controls supported are the existing practices analyses for warehouse configuration/load, bounded role access, declared sensitive-column requirements and query/operator diagnosis; this module adds source plumbing, not new assessed controls or a revised 74-control capability claim.

Shared typed provenance validation

validate_provenance(manifest, query_work_ids) is a pure validator reused by emitted normalization, normalized database validation and self-contained assessment reporting. It checks the 13-table status/count population, exact supported source kinds and fields, bounded integer counts/caps, COMPLETE versus empty/at-cap states, no rows in unavailable/empty states, UTC windows/observation times, relative CSV/checksum provenance, mandatory attestations and manual attribution/source declarations. Raw QUERY_WORK identifiers must be unique and match every SUCCESS execution-map entry and the declared source count; manual sources require SUCCESS_COMPLETED and cannot carry a native execution map. Snapshot/data bytes and database counts remain checked separately by normalization; the pure validator does not authenticate clients or read external sources. Reports retain the exact normalized manifest plus actual QUERY_WORK IDs for the same checks, and older evaluated formats must be regenerated.

The normalized manifest has an exact generated key contract; missing or additional keys are rejected at normalized-input and retained-report validation. There is no top-level manual_context_sha256 field: the sole manual-context digest is manual_context_source.sha256 when attributed context is present. Unsupported checksum aliases must not be injected into artifacts.

Normalization builds its database and manifest in a private .sf-normalize-* temporary directory under the approved destination parent, then performs full normalized database/provenance validation. Only after success does it reserve the fresh requested destination and atomically replace that empty reservation with the validated directory. Ordinary validation failures leave no requested output and temporary staging is cleaned. Inputs remain read-only; existing destinations are refused. Unexpected filesystem failures can still require operator investigation.