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

# Explain waiting conditions and field insights

Use condition insights and field insights on WorkflowEvaluation to explain blocked actions, waiting transitions, and missing references.

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



When a workflow waits, its evaluation can explain why. Each decision in a [WorkflowEvaluation](https://www.sanity.io/docs/workflows/engine) carries a condition insight that names the unmet parts of the condition and the field values that would change it.

This guide gives the quick start’s `article-review` workflow a field and a condition to wait on, then writes a script that explains why `to-approved` is waiting and which field value would let it fire.

You need:

- The finished [quick start](https://www.sanity.io/docs/workflows/getting-started): `article-review` deployed to the `dev` partition, and a published article.
- The `scripts/engine.ts` module from [Run the engine from your own code](https://www.sanity.io/docs/workflows/run-the-engine), and the API token it reads from `SANITY_AUTH_TOKEN`.

## Explain a waiting transition

In `article-review`, the engine fires `to-approved` in the call that marks `sign-off` done, so there is little to explain. Give it something to wait on: in `workflows/article-review.ts`, add a legal approval field to the workflow and make the transition require it:

**workflows/article-review.ts**

```typescript
export const articleReview = defineWorkflow({
  // ...
  fields: [
    defineField({
      type: 'subject',
      name: 'subject',
      // ...
    }),
    defineField({type: 'boolean', name: 'legalApproved', title: 'Legal approved', editable: true}),
  ],
  stages: [
    // drafting is unchanged
    defineStage({
      name: 'review',
      // ...
      transitions: [
        defineTransition({
          name: 'to-approved',
          title: 'Approve and finish',
          to: 'approved',
          when: '$allActivitiesDone && $fields.legalApproved == true',
        }),
      ],
    }),
    // approved is unchanged
  ],
})
```

`editable: true` lets a user set the field while the instance runs. A transition without `when` waits for `$allActivitiesDone`. This `when` keeps that check and adds the field. [Fields](https://www.sanity.io/docs/workflows/fields) and [Conditions](https://www.sanity.io/docs/workflows/conditions) cover both in depth.

Deploy the change, then start a new instance and submit it so it reaches review. Instances keep the definition version they started with, so the quick start’s instance doesn’t have the new field:

**npm**

```shell
npx sanity-workflows deploy
npx sanity-workflows start article-review \
  --field subject='{"id":"dataset:PROJECT_ID:DATASET_NAME:DOCUMENT_ID","type":"article"}'
npx sanity-workflows fire-action INSTANCE_ID --activity write --action submit
```

**pnpm**

```shell
pnpm dlx sanity-workflows deploy
pnpm dlx sanity-workflows start article-review \
  --field subject='{"id":"dataset:PROJECT_ID:DATASET_NAME:DOCUMENT_ID","type":"article"}'
pnpm dlx sanity-workflows fire-action INSTANCE_ID --activity write --action submit
```

**yarn**

```shell
yarn dlx sanity-workflows deploy
yarn dlx sanity-workflows start article-review \
  --field subject='{"id":"dataset:PROJECT_ID:DATASET_NAME:DOCUMENT_ID","type":"article"}'
yarn dlx sanity-workflows fire-action INSTANCE_ID --activity write --action submit
```

**bun**

```shell
bunx sanity-workflows deploy
bunx sanity-workflows start article-review \
  --field subject='{"id":"dataset:PROJECT_ID:DATASET_NAME:DOCUMENT_ID","type":"article"}'
bunx sanity-workflows fire-action INSTANCE_ID --activity write --action submit
```

Create `scripts/explain-transition.ts`. It takes a `WorkflowEvaluation` and reads both the transition’s condition insight and the field proposals:

**scripts/explain-transition.ts**

```typescript
import type {ConditionOutcome, WorkflowEvaluation} from '@sanity/workflows'

interface TransitionChange {
  field: string
  value: unknown
  before: ConditionOutcome
  after: ConditionOutcome
}

interface TransitionExplanation {
  outcome: ConditionOutcome
  blockedBy: string[]
  changes: TransitionChange[]
}

export function explainTransition(
  evaluation: WorkflowEvaluation,
  transitionName: string,
): TransitionExplanation {
  const evaluated = evaluation.currentStage.transitions.find(
    ({transition}) => transition.name === transitionName,
  )

  if (!evaluated) throw new Error(`Unknown transition: ${transitionName}`)

  const changes = evaluation.fieldInsights.flatMap((field) =>
    field.proposals.flatMap((proposal) =>
      proposal.consequences
        .filter(
          ({site}) => site.kind === 'transition' && site.transition === transitionName,
        )
        .map(({before, after}) => ({
          field: field.field,
          value: proposal.assign.value,
          before,
          after,
        })),
    ),
  )

  return {
    outcome: evaluated.insight.outcome,
    blockedBy: evaluated.insight.blockedBy.map(({atom}) => atom.groq),
    changes,
  }
}
```

Create `scripts/why-waiting.ts`. It imports `engine` from the module you made in the engine guide, evaluates the instance, and explains `to-approved`:

**scripts/why-waiting.ts**

```typescript
import {engine} from './engine'
import {explainTransition} from './explain-transition'

async function main() {
  const instanceId = process.argv[2]
  if (!instanceId) {
    throw new Error('Pass the instance _id: npx tsx scripts/why-waiting.ts INSTANCE_ID')
  }

  const evaluation = await engine.evaluate({instanceId})
  console.log(`Stage: ${evaluation.currentStage.stage.name}`)
  console.dir(explainTransition(evaluation, 'to-approved'), {depth: null})
}

main().catch((error) => {
  console.error(error)
  process.exit(1)
})
```

Run it with the instance id:

```sh
SANITY_AUTH_TOKEN=YOUR_TOKEN npx tsx scripts/why-waiting.ts INSTANCE_ID
```

Both parts of the condition are false, so both appear in `blockedBy`:

```text
Stage: review
{
  outcome: 'unsatisfied',
  blockedBy: [ '$allActivitiesDone', '$fields.legalApproved == true' ],
  changes: []
}
```

Each `blockedBy` entry is an atom: the smallest part of the condition, as GROQ, that currently blocks it. `changes` is empty because no single field value would satisfy the condition while `sign-off` is still open. Each `changes` entry names a proposed field value and the transition outcome before and after that value. These are verified condition consequences, not a prediction of document writes or external effects. A custom App SDK interface can pass `session.evaluation` to the same helper.

Resolve `sign-off` and run the script again:

**npm**

```shell
npx sanity-workflows fire-action INSTANCE_ID --activity sign-off --action approve
SANITY_AUTH_TOKEN=YOUR_TOKEN npx tsx scripts/why-waiting.ts INSTANCE_ID
```

**pnpm**

```shell
pnpm dlx sanity-workflows fire-action INSTANCE_ID --activity sign-off --action approve
SANITY_AUTH_TOKEN=YOUR_TOKEN npx tsx scripts/why-waiting.ts INSTANCE_ID
```

**yarn**

```shell
yarn dlx sanity-workflows fire-action INSTANCE_ID --activity sign-off --action approve
SANITY_AUTH_TOKEN=YOUR_TOKEN npx tsx scripts/why-waiting.ts INSTANCE_ID
```

**bun**

```shell
bunx sanity-workflows fire-action INSTANCE_ID --activity sign-off --action approve
SANITY_AUTH_TOKEN=YOUR_TOKEN npx tsx scripts/why-waiting.ts INSTANCE_ID
```

The instance stays in review. Only the field blocks the transition now, and the engine proposes the value that would satisfy it:

```text
Stage: review
{
  outcome: 'unsatisfied',
  blockedBy: [ '$fields.legalApproved == true' ],
  changes: [
    {
      field: 'legalApproved',
      value: true,
      before: 'unsatisfied',
      after: 'satisfied'
    }
  ]
}
```

`blockedBy` lists the unmet atoms in source order, and each atom also has a `pivotal` flag. `pivotal` is true when satisfying that atom alone, with the others unchanged, would satisfy the condition. In the first run neither atom was pivotal. Now `$fields.legalApproved == true` is, so an interface can tell the reviewer that this one value unblocks the transition.

Writing that value with `engine.editField({instanceId, target: {field: 'legalApproved'}, value: true})` fires `to-approved` in the same call. `npx sanity-workflows show INSTANCE_ID` then reports the instance in approved.

The outcome has three possible values:

- satisfied: the condition is true.
- unsatisfied: the condition is false.
- unevaluable: GROQ returned null because the condition could not be decided from the current values.

## Read field insights

WorkflowEvaluation.fieldInsights provides the field-centric view of the same current-stage conditions. Use it to show where a field matters and which concrete assignments the engine verified would change an outcome.

A field can take part in several conditions without producing a useful proposal. A proposal appears only when a blocking atom points to one concrete value, and re-evaluating with that value confirms it changes at least one of the sites involved.

Every insight location, missing-document evidence, and the exported insight types are listed in [Evaluation insights and diagnostic utilities](https://www.sanity.io/docs/workflows/engine).

## Next steps

Use [The reactive session](https://www.sanity.io/docs/workflows/reactive-session) to keep the evaluation current in a custom interface.

See [Build a workflow interface with the App SDK](https://www.sanity.io/docs/workflows/app-sdk) to render an evaluation in a custom interface.

See [Engine, effects, and insights reference](https://www.sanity.io/docs/workflows/engine) for the complete `WorkflowEvaluation` projection.

Read why insights and verdicts are advisory in [Advisory checks and Content Lake enforcement](https://www.sanity.io/docs/workflows/actors-and-enforcement).

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



