> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

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

> [!WARNING]
> Early access
> Workflows is in early access, built in public. Read [How early access works](https://www.sanity.io/docs/workflows/prerelease) before you rely on it.



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](https://www.sanity.io/docs/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.

> [!NOTE]
> **Early access limitation.** The engine and the Studio plugin honor a deployed guard. The Content Lake does not enforce Workflows’ temporary guard documents, so a guard does not stop a client that writes to the lake directly. Use [dataset access control](https://www.sanity.io/docs/content-lake/roles-concepts) when a rule must hold against every writer.

Before you start, you need:

- A workflow definition with a `subject` field, such as the one in the [quick start](https://www.sanity.io/docs/workflows/getting-started).
- The [Workflows Studio plugin](https://www.sanity.io/docs/workflows/studio-plugin) installed, so you can see the hold in Studio.

## 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`:

**workflows/article-review.ts**

```typescript
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:

**workflows/article-review.ts**

```typescript
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](https://www.sanity.io/docs/workflows/workflow-authoring-reference) 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](https://www.sanity.io/docs/workflows/upgrade) 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](https://www.sanity.io/docs/workflows/getting-started). 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:

```groq
*[_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

- Look up every guard property in [Guard declaration](https://www.sanity.io/docs/workflows/workflow-authoring-reference).
- Learn which checks honor a guard in [Architecture, actors, and enforcement](https://www.sanity.io/docs/workflows/actors-and-enforcement).
- Check guards from a custom integration with `documentActionDenials` in [@sanity/workflows](https://reference.sanity.io/_sanity/workflow-engine/) on reference.sanity.io.

> [!NOTE]
> Visiting agent?
> Workflows has MCP tools that let an agent inspect, operate, author, validate, and deploy workflows. An agent host embeds these tools. Ask the person you work for whether your host [includes the Workflows tools](https://www.sanity.io/docs/workflows/mcp).



