Workflows

Hold publishing and freeze fields with guards

Add stage guards that hold publishing and freeze fields on the subject document while a workflow instance is in a stage.

Early access

A guard tells the engine and Workflows surfaces to refuse certain changes to a document while a workflow instance is in one stage. The Content Lake doesn’t enforce guards, so a client that writes to it directly isn’t stopped. You declare a guard on the stage. The engine writes it to the Content Lake as its own document when the instance enters the stage and removes it when the instance leaves.

This guide adds two guards to a review stage: one that holds publishing of the subject document, and one that freezes its headline and body.

Before you start, you need:

Hold publishing during a stage

Add a guard to the stage's guards array. This one denies publishing the subject document while the instance is in review:

import {defineGuard, defineStage} from '@sanity/workflows/define'

defineStage({
  name: 'review',
  title: 'Editorial review',
  guards: [
    defineGuard({
      name: 'hold-publishing',
      title: 'No publishing during review',
      match: {
        idRefs: [{type: 'fieldRead', field: 'subject'}],
        actions: ['publish'],
      },
      // No predicate: deny every publish while the instance is in this stage.
    }),
  ],
  // activities and transitions as before
})

When the instance enters the stage, idRefs resolves which document the guard protects. A fieldRead reads a workflow field, so here the guard protects whatever document the subject field points to. Stage and activity fields aren't available to a guard. The guard has no predicate, so it denies every publish it matches.

Freeze fields during a stage

Studio doesn’t check update guards while someone edits, so this freeze applies only to integrations that call documentActionDenials. To refuse changes to some fields while allowing other edits, guard the update action and add a predicate. Add this guard to the same guards array:

defineGuard({
  name: 'freeze-copy',
  title: 'Freeze the headline and body during review',
  match: {
    idRefs: [{type: 'fieldRead', field: 'subject'}],
    actions: ['update'],
  },
  // Allow a draft edit only when it leaves title and body unchanged.
  predicate: '!delta::changedAny((title, body))',
})

A predicate is a GROQ expression that can read document, guard, and mutation. Only a strict true allows a matching mutation. An omitted or empty predicate denies it. Here, delta::changedAny((title, body)) is true when an edit touches either field, so the negated expression allows every other edit. See Guard predicates for the variables a predicate can read.

Choose which mutations to guard

Each guard lists one or more actions in match.actions:

  • update: edits to the draft.
  • publish: publishing the draft.
  • unpublish: unpublishing the published document.
  • create and delete: creating or deleting the document under the ID the guard matches.

Give each rule its own guard with its own name, as the two examples above do. Every matching guard is evaluated on its own, and one denial denies the mutation. No guard can widen what another one denies, and there is no evaluation order to depend on. A single guard whose actions span more than one group (update; publish and unpublish; create and delete) needs reader model 9 or later: every engine that reads the definition must support stored-data model 9. Upgrade Workflows packages explains reader models.

Check that the guard is active

Deploy the definition, start an instance, and move it to the guarded stage, as in the quick start. Then open the subject document in Studio. The Publish action is disabled, and its tooltip names the workflow holding the document.

The Studio plugin checks guards only for Publish, Unpublish, and Delete, so Studio doesn’t stop edits to frozen fields in the form.

To confirm the guard documents exist, query them by instance ID:

*[_type == "temp.system.guard" && sourceInstanceId == $instanceId]{
  _id,
  match
}

The query returns one document per guard, with the resolved document IDs and Content Lake actions it matches.

Next steps

Visiting agent?

Was this page helpful?

Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change site theme