Cookbook: Editorial review
A four-stage editorial review workflow for Sanity: assignment, drafting, review, and published, driven by human actions in the Studio.
Early access
Workflows is in early access, built in public. Read How early access works before you rely on it.
This is the base loop the other Cookbook recipes build on: an editorial review where every step is a human action in the Studio. It runs in four stages:
- Assignment: a writer takes the open commission.
- Drafting: the assigned writer writes the article, then submits it for review.
- Review: a desk editor approves it, or sends it back with a reason. A rejection loops back to drafting.
- Published: a terminal stage.
The loop runs assignment → drafting → desk-editor review → publication. Copy edit, fact-check, and SEO are real stages too, but which exist and who owns them varies by organization, so the base loop leaves them out. The Adapting it section shows where they slot in.
Before you get started
- Packages:
@sanity/workflowsand@sanity/workflows-uifor the ready-made human surface in Studio. No AI packages and no Functions. - The engine (
createEngine) and a dataset for its instances; the articles can live in the same dataset. - No effect handlers: every step here is a human action fired from the Studio, so there is nothing to drain and no Function to deploy. The Studio is the only runtime: it calls the engine when someone selects an action. That makes this the shortest recipe to stand up. The AI pipeline and Coordinated release recipes add handlers and Functions on top of this same base.
Define the workflow
The whole workflow is one defineWorkflow call, with the four stages and the fields that fill in as it runs:
import {
defineWorkflow,
defineField,
defineStage,
defineActivity,
defineAction,
defineTransition,
} from '@sanity/workflows/define'
export const editorialReview = defineWorkflow({
name: 'editorial-review',
title: 'Editorial review',
initialStage: 'assignment',
fields: [
defineField({type: 'subject', name: 'subject', initialValue: {type: 'input'}, required: true}),
defineField({type: 'actor', name: 'writer'}),
defineField({type: 'actor', name: 'reviewer'}),
defineField({type: 'actor', name: 'approval'}),
defineField({type: 'string', name: 'rejectionReason'}),
],
stages: [
defineStage({
name: 'assignment',
title: 'Assignment',
activities: [
defineActivity({
name: 'assign',
title: 'Assign a writer',
actions: [
defineAction({
name: 'take',
title: 'Take this assignment',
filter: '!defined($fields.writer)', // open until a writer takes it
status: 'done',
ops: [{type: 'field.set', target: {field: 'writer'}, value: {type: 'actor'}}],
}),
],
}),
],
transitions: [defineTransition({name: 'to-drafting', to: 'drafting', when: '$allActivitiesDone'})],
}),
defineStage({
name: 'drafting',
title: 'Drafting',
activities: [
defineActivity({
name: 'write',
title: 'Write the article',
actions: [
defineAction({
name: 'submit',
title: 'Submit for review',
filter: '$fields.writer.id == $actor.id', // only the assigned writer
status: 'done',
}),
],
}),
],
transitions: [defineTransition({name: 'to-review', to: 'review', when: '$allActivitiesDone'})],
}),
defineStage({
name: 'review',
title: 'Review',
activities: [
defineActivity({
name: 'review',
title: 'Review the article',
actions: [
defineAction({
name: 'clear-rejection',
title: 'Clear the previous rejection',
when: 'true', // fires on entry, so a resubmitted draft does not bounce straight back
ops: [{type: 'field.unset', target: {field: 'rejectionReason'}}],
}),
defineAction({
name: 'claim',
title: 'Take this review',
filter: '!defined($fields.reviewer)',
ops: [{type: 'field.set', target: {field: 'reviewer'}, value: {type: 'actor'}}],
}),
defineAction({
name: 'approve',
title: 'Approve',
filter: '$fields.reviewer.id == $actor.id', // only the editor who claimed it
status: 'done',
ops: [{type: 'field.set', target: {field: 'approval'}, value: {type: 'actor'}}],
}),
defineAction({
name: 'reject',
title: 'Reject with reason',
filter: '$fields.reviewer.id == $actor.id',
status: 'done',
params: [{type: 'string', name: 'reason', title: 'Reason', required: true}],
ops: [{type: 'field.set', target: {field: 'rejectionReason'}, value: {type: 'param', param: 'reason'}}],
}),
],
}),
],
transitions: [
defineTransition({name: 'to-published', to: 'published', when: 'defined($fields.approval)'}),
defineTransition({name: 'back-to-drafting', to: 'drafting', when: 'defined($fields.rejectionReason)'}),
],
}),
defineStage({name: 'published', title: 'Published'}),
],
})Take review records the caller in the workflow-level reviewer field. The same reviewer keeps the review when the workflow returns to this stage. This actor field does not create a task assignment; use Fields to add one.
What each piece does
- subject is the article: a required workflow input that makes the definition discoverable from that document. Its value is a global document reference, which preserves the article’s project and dataset identity. An editor commissions the piece, often as a fresh draft, and the other fields fill in as the workflow runs.
- Assignment: a writer takes the open assignment with
take, which records them inwriterand completes the activity. The!defined($fields.writer)filter keeps the assignment from being taken twice: once someone has it, the engine stops offering the action. (Editor-push assignment is the same shape withtakegated to an editor and the writer passed as a param.) - Drafting: the assigned writer does the actual writing on
subject, then firessubmit. It is gated on$fields.writer.id == $actor.id, so only the assigned writer can submit. - Review: an editor claims the review, then approves or rejects it. A rejection records the reason, and the engine moves the instance back to drafting. When the article comes back for another review, the engine fires the
clear-rejectionentry trigger, which removes the old reason. approvewritesapproval, and the engine then fires the transition topublished.publishedhas no outgoing transitions, so it is terminal.
Configure the engine
The engine needs a client with write access to the dataset that holds the instances:
The required subject makes this definition need reader model 10, the lowest stored-data model version an engine must support to read it. Follow Upgrade Workflows packages to update every runtime sharing the workflow resource before you set expectedMinReaderModel: 10.
import {createClient} from '@sanity/client'
import {createEngine, ENGINE_API_VERSION} from '@sanity/workflows'
import {editorialReview} from './editorial-review'
const workflowClient = createClient({
projectId: 'yourprojectid',
dataset: 'production', // instances + the articles share one dataset here
apiVersion: ENGINE_API_VERSION, // satisfies the client here; the engine pins its own traffic to ENGINE_API_VERSION regardless of this value
token: process.env.SANITY_AUTH_TOKEN, // needs write access
useCdn: false,
})
export const engine = createEngine({
client: workflowClient,
workflowResource: {type: 'dataset', id: 'yourprojectid.production'},
partition: 'prod',
})
// Deploy the definition once (a setup script or CI step).
await engine.deployDefinitions({
expectedMinReaderModel: 10,
definitions: [editorialReview],
})Same createEngine as the other recipes, minus effectHandlers: this workflow queues no effects.
Deploy the definition
Deploy the definition with the sanity-workflows CLI, configured by a sanity.workflow.ts in your working directory. (The engine.deployDefinitions call above is the programmatic equivalent for a script or CI step.)
// sanity.workflow.ts
import {defineWorkflowConfig} from '@sanity/workflows/define'
import {editorialReview} from './editorial-review'
export default defineWorkflowConfig({
deployments: [
{
name: 'production',
partition: 'prod', // matches the engine's partition
expectedMinReaderModel: 10,
workflowResource: {type: 'dataset', id: 'yourprojectid.production'},
definitions: [editorialReview],
},
],
})Log in once, then run the deploy:
sanity login # once; in CI, set SANITY_AUTH_TOKEN instead
sanity-workflows deploy # → editorial-review v1 createdThis deploys the definition. There are no effect handlers, so this recipe needs no Function. See Configure and deploy workflow definitions for deployment options.
Run it
Start an instance on an article, then fire each step’s action in turn:
import {refDataset} from '@sanity/workflows'
import {engine} from './engine'
// verbs return an OperationResult; the instance document is on .instance
const {instance: wf} = await engine.startInstance({
definition: 'editorial-review',
initialFields: [
{type: 'subject', name: 'subject', value: refDataset({projectId: 'yourprojectid', dataset: 'production', documentId: 'article-1', type: 'article'})},
],
})
await engine.fireAction({instanceId: wf._id, activity: 'assign', action: 'take'}) // a writer takes the assignment
// ...the writer drafts the article on `subject`...
await engine.fireAction({instanceId: wf._id, activity: 'write', action: 'submit'}) // writer submits → review
await engine.fireAction({instanceId: wf._id, activity: 'review', action: 'claim'}) // an editor takes the review
await engine.fireAction({instanceId: wf._id, activity: 'review', action: 'approve'}) // → publishedIn the approve call, the engine fires the transition to published, which is terminal. After a rejection, the engine would move the instance back to drafting instead.
In the Studio these are buttons, and the writing itself happens on the article document between take and submit. The clear-rejection trigger never renders as one, because the engine fires it. Nothing in the definition is tied to that UI.
Run the review in Studio with the Workflows plugin: start it from the article, then use the workflow actions to claim, submit, approve, or reject each step. See Add Workflows to Sanity Studio.
Adapting it
- Editor-assigned instead of writer-claimed: gate
taketo an editor role and pass the writer as a param, so the desk assigns the piece rather than writers picking it up. - Add a stage (copy edit, fact-check, legal) by repeating the review shape: a stage with a
claimand an approve/reject pair, gated on whoever owns that pass. Some of these stages are near-universal; others are organization-specific.
One active editorial review per article: add a single-subject start requirement. startInstance then refuses another unfinished instance of this definition for the same resource-qualified subject. See Conditions.
start: {
requirements: [
{
type: 'singleSubject',
name: 'one-open-review',
title: 'Review already in progress',
},
],
}Custom start surfaces: call evaluateStart to preview the verdict, then handle StartNotAllowedError from startInstance.
import {refDataset} from '@sanity/workflows'
import {engine} from './engine'
const subject = refDataset({
projectId: 'yourprojectid',
dataset: 'production',
documentId: 'article-1',
type: 'article',
})
const initialFields = [{type: 'subject' as const, name: 'subject', value: subject}]
const preflight = await engine.evaluateStart({
definition: 'editorial-review',
initialFields,
})
if (preflight.allowed) {
// startInstance checks the requirements again at the commit boundary.
await engine.startInstance({definition: 'editorial-review', initialFields})
}- Add a publishing hold: declare a guard on the stages where publishing should be blocked. The Content Lake doesn’t enforce guards; the engine and the Workflows surfaces check them. See Guards and enforcement.
Next steps
- Cookbook: the other examples and how to run them.
- Reference: the exact shapes of field operations, status, parameters, and field types.
- Quick start: run your first workflow: installing the engine and the shortest path to a running workflow.
- Workflows: the model behind stages, activities, and the reactive session.
- Test your workflows: cover the review loop’s approve and reject paths with the in-memory bench before deploying it.
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.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?