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

# Cookbook

Worked, runnable workflow examples for Sanity: editorial review, AI content pipelines, coordinated releases, and more, each a complete definition.

> [!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.



The examples run from the smallest useful review to a coordinated multi-document [release](https://www.sanity.io/docs/user-guides/content-releases). Between them they cover the constructs you reach for most often:

- Every example is built from stages, transitions, and the actions that do the work.
- Review loops send rejected work back to drafting, and claims let a writer take the open commission.
- Triggered actions queue the effects that generate [drafts](https://www.sanity.io/docs/content-lake/drafts-and-versions) and run the checks.
- The engine routes work to a human only when a completed check flags it.
- Subworkflows give each [document](https://www.sanity.io/docs/content-lake/documents) in a release its own review.
- Guards hold a [document](https://www.sanity.io/docs/content-lake/documents) while its review is open. The Content Lake doesn’t enforce guards; the engine and the Workflows surfaces check them.

## Editorial review

One article from assignment to publish, gated by a single editor.

1. **Assignment**: a writer takes the open commission.
2. **Drafting**: the assigned writer writes, then submits for review.
3. **Review**: a desk editor approves it, or sends it back with a reason. Rejection loops to drafting.
4. **Published**: terminal.

This is the loop the other examples build on, so read it first.

→ [Cookbook: Editorial review](https://www.sanity.io/docs/workflows/cookbook-editorial-review)

## AI content pipeline

An agent drafts, automated checks run, and a person steps in only when a check flags the piece.

1. **Drafting**: an AI effect generates the draft.
2. **Checks**: automated effects score it (brand voice, SEO, links, facts) and flag what fails.
3. **Verification**: the engine moves only flagged pieces here. Clean ones skip straight to publishing.
4. **Publishing**: the engine fires triggered actions that queue an effect to publish the document, then a notification effect.
5. **Published**: terminal.

→ [Cookbook: AI content pipeline](https://www.sanity.io/docs/workflows/cookbook-ai-content-pipeline)

## Coordinated release

Many documents reviewed and published together as one Content Release.

1. **Assembly**: documents are grouped into a named release. The engine starts a review subworkflow for each document. A guard holds publishing for each document until a reviewer approves it.
2. **Scheduled**: once every document is approved, the release is [scheduled](https://www.sanity.io/docs/user-guides/content-releases) for an embargoed go-live (or published on demand).
3. **Published**: the release publishes as one unit, and the engine queues the build and notification effects.
4. **Archived**: terminal, with revert as the rollback.

→ [Cookbook: Coordinated release](https://www.sanity.io/docs/workflows/cookbook-coordinated-release)

## Handle workflows when referenced content is deleted

Choose what happens to in-flight workflow instances when referenced content is deleted. A document-delete Function finds affected instances with `instancesForDocument` and can retain them or abort them through the engine without deleting their audit records.

→ [Cookbook: Handle workflows when referenced content is deleted](https://www.sanity.io/docs/workflows/cookbook-handle-deleted-subject)

## Running a workflow

A definition does nothing on its own. To run it, something has to call the engine when a person acts or content changes. That caller is the runtime. Most deployments use two runtimes: a user interface for people, and Sanity Functions for automatic work.

For people, use the ready-made [Studio plugin](https://www.sanity.io/docs/studio). To build your own workflow UI, use the [Studio or App SDK adapters](https://www.sanity.io/docs/workflows/reactive-session).

Generate the Functions that run workflows autonomously with [Generate Functions from your workflow definitions](https://www.sanity.io/docs/workflows/generate-functions). The generated runtime does three jobs:

- **Start watchers**: Document Functions that start an autonomous workflow on the write that makes its start condition true.
- **Drains**: Document Functions that call `drainEffects()` when unclaimed effect work appears.
- **A heartbeat**: a Scheduled Function that calls `tick` on in-flight instances so the engine rechecks time-based conditions, and re-queues effects no drain picked up.

Any service that can call the engine can run a workflow. Give each trigger source one owner, and make sure a repeated delivery is safe. To write the Functions yourself, [Run Workflows with Sanity Functions](https://www.sanity.io/docs/workflows/sanity-functions) lists what they must do.

## How much to enforce

Workflows offers three ways to control who can change what. They give different guarantees:

- Engine checks on actions: the engine refuses an action and explains why. Only callers that go through the engine are checked.
- Guards: hold a document while the instance is in a stage. The engine and the Workflows surfaces check them; the Content Lake doesn’t.
- Dataset access control: the Content Lake checks it for every writer. This is the only one of the three that holds for every client.

[Actors, tokens, and what’s actually enforced](https://www.sanity.io/docs/workflows/actors-and-enforcement) compares the three. [Guards and enforcement](https://www.sanity.io/docs/workflows/guards) shows how to declare a guard.

The editorial review example relies on engine checks only. The coordinated release example combines roles on its actions, guards on its documents, and Content Lake access control on the release.

## Partitions and client factories

Every real deployment needs partitions and resource routing.

Use a distinct [partition](https://www.sanity.io/docs/workflows/deployments-and-resources) for each environment so definitions and instances from production, staging, and local development remain separate.

Workflow data and the content it governs can live in different datasets or projects. To read content in another resource at runtime, pass `resourceClients` to the engine. It also routes references that callers supply at runtime. See [Global document references](https://www.sanity.io/docs/workflows/global-document-references) for the routing rules.

Resource aliases keep definitions portable between environments. In the definition, refer to a named alias. In each deployment, bind that alias to a project and dataset.

At deploy, the engine expands each `@content:` reference to a full global document reference (GDR) for the bound dataset. To move between environments, deploy the same definitions with a different alias binding. Bare document IDs and full GDRs stay as they are.

Resource aliases work at deploy time. `resourceClients` works at runtime.

This configuration deploys the same definitions under two partitions. In each one, the `content` alias points to that environment’s dataset:

The configuration uses the `articleReview` definition from [Test your workflows](https://www.sanity.io/docs/workflows/testing). Its required subject field needs reader model 10, the lowest stored-data model version an engine must support to read it, so each deployment sets `expectedMinReaderModel: 10`. Before you set it, follow [Upgrade Workflows packages](https://www.sanity.io/docs/workflows/upgrade) to upgrade every runtime in that environment.

```typescript
// sanity.workflow.ts
import {defineWorkflowConfig} from '@sanity/workflows/define'

import {articleReview} from './article-review'

export default defineWorkflowConfig({
  deployments: [
    {
      name: 'production',
      partition: 'prod',
      expectedMinReaderModel: 10,
      workflowResource: {type: 'dataset', id: 'yourprojectid.workflows'},
      resourceAliases: [{name: 'content', resource: {type: 'dataset', id: 'yourprojectid.production'}}],
      definitions: [articleReview],
    },
    {
      name: 'staging',
      partition: 'staging',
      expectedMinReaderModel: 10,
      workflowResource: {type: 'dataset', id: 'yourprojectid.workflows-staging'},
      resourceAliases: [{name: 'content', resource: {type: 'dataset', id: 'yourprojectid.staging'}}],
      definitions: [articleReview],
    },
  ],
})
```

To generate Sanity Functions from this configuration, also export each deployment object under its `name`, for example `export const production = {...}`. The generated Functions import each deployment by that name.

## Next steps

- [Quick start: run your first workflow](https://www.sanity.io/docs/workflows/getting-started) walks the shortest path from nothing to a running workflow.
- [Workflows](https://www.sanity.io/docs/workflows/introduction) explains the model behind the workflow definition language.
- [Reference](https://www.sanity.io/docs/workflows/reference) has every construct and verb, with exact shapes.
- [Test your workflows](https://www.sanity.io/docs/workflows/testing) shows how to cover a recipe’s paths with the in-memory bench before deploying it.

> [!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).



