Skip to main content
Pre-hooks and post-hooks run before and after materialization. Each entry is either sql("...") or python("hook_name").

SQL hooks

SQL hooks support macros, project variables, environment variables, and context variables. Hook SQL is syntax-validated when the model’s effective SQL-validation gate is enabled: SQL analysis must be enabled, --no-sql-validation must be absent, and the effective project or model sql_validation value must be true.

Python hooks

SQLBuild discovers @hook functions recursively under hooks/:
Reference the hook by name and optionally pass keyword arguments:
SQL and Python hooks can appear in the same list.

Hook context

Python hooks declare a HookContext parameter named ctx, context, _ctx, or hook_context. It need not be the first parameter when providers or configured arguments are also present: Providers may also be injected into hook parameters by name.

Skip timing

Returning ctx.skip(...) from a pre-hook prevents materialization. Returning it from a post-hook changes the reported execution result, but the relation has already been created, promoted, or incrementally updated and audited. mode="hard" blocks downstream nodes. A soft skip does not automatically block every downstream node; scheduler propagation depends on the other upstream results.

Failure timing

Post-hooks are not promotion gates. A failed post-hook marks the model run as failed after warehouse mutation has already occurred. Put logic that must prevent materialization in a pre-hook, contract, pre-promotion audit, or the materialization itself.

Discovery and validation

  • Files beginning with _, including __init__.py, are skipped.
  • Hook names must be unique across the project.
  • The decorator accepts optional name and description arguments.
  • Unknown hooks, unknown keyword arguments, and missing required arguments fail compilation.
  • A function without **kwargs rejects undeclared hook arguments.