> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# when

> Contract, placement, related fields and source examples for this Nika YAML field.

[Language reference](https://docs.nika.sh/reference/language/overview.md) / `when`

## Meaning and placement

### task

LOCAL business condition · false skips the task · evaluated after the gate and BEFORE any fan-out, over `inputs` · `const` · `with` only: the `for_each` locals `item` / `index` are not bound yet (NIKA-VAR-001), and a `tasks.*` reference is refused (NIKA-VAR-021 · hoist it into `with:`) · spec/03-dag.md §when.

| Property | Declaration |
| - | - |
| Requirement | Optional in this object |
| Schema location | `/$defs/task/properties/when` |

**In the same object:** [after](https://docs.nika.sh/reference/language/words/after.md) · [agent](https://docs.nika.sh/reference/language/words/agent.md) · [exec](https://docs.nika.sh/reference/language/words/exec.md) · [extract](https://docs.nika.sh/reference/language/words/extract.md) · [for\_each](https://docs.nika.sh/reference/language/words/for_each.md) · [group](https://docs.nika.sh/reference/language/words/group.md) · [infer](https://docs.nika.sh/reference/language/words/infer.md) · [invoke](https://docs.nika.sh/reference/language/words/invoke.md) · [lift](https://docs.nika.sh/reference/language/words/lift.md) · [on\_error](https://docs.nika.sh/reference/language/words/on_error.md) · [retry](https://docs.nika.sh/reference/language/words/retry.md) · [returns](https://docs.nika.sh/reference/language/words/returns.md) · [timeout](https://docs.nika.sh/reference/language/words/timeout.md) · [with](https://docs.nika.sh/reference/language/words/with.md)

[Schema source (use the pointer above)](https://github.com/supernovae-st/nika-spec/blob/5c40ba456c53a4ab663a949d44003078e161305d/schemas/workflow.schema.json)

## In a source template

Excerpt from `templates/corpus-qa.nika`, source lines 93–102. This is a fragment, not a runnable workflow.

```yaml illustration theme={"system"}
  answer:
    with:
      hits: ${{ tasks.retrieve.output }}
    when: ${{ size(with.hits) > 0 }}
    infer:
      # a reasoning model needs 16384 here, or a documented run.reasoning.effort: low
      max_tokens: 500                # SLOT: answer spend ceiling
      prompt: |
        Answer from these passages only and cite their ids.
        Question: ${{ const.query }}
```

### Templates containing this field

| Template | Source |
| - | - |
| `templates/corpus-qa.nika` | [Line 96](https://github.com/supernovae-st/nika-spec/blob/5c40ba456c53a4ab663a949d44003078e161305d/templates/corpus-qa.nika#L96) |
| `templates/etl-state.nika` | [Line 102](https://github.com/supernovae-st/nika-spec/blob/5c40ba456c53a4ab663a949d44003078e161305d/templates/etl-state.nika#L102) |
| `templates/gate-and-act.nika` | [Line 70](https://github.com/supernovae-st/nika-spec/blob/5c40ba456c53a4ab663a949d44003078e161305d/templates/gate-and-act.nika#L70) |
| `templates/human-gated-ship.nika` | [Line 147](https://github.com/supernovae-st/nika-spec/blob/5c40ba456c53a4ab663a949d44003078e161305d/templates/human-gated-ship.nika#L147) |

These are literal key occurrences in the source files, not an execution or conformance claim. [How to instantiate a template](https://docs.nika.sh/guides/templates.md).

## Contract and implementation

This page projects the named specification revision. Check [released engine status](https://docs.nika.sh/reference/status.md) and [the validation workflow](https://docs.nika.sh/guides/agent-authoring.md) before running a file. An optional field is not evidence that every engine supports every value.

Canonical identity: `language:word:when`. Spec revision: [`5c40ba456c53`](https://github.com/supernovae-st/nika-spec/tree/5c40ba456c53a4ab663a949d44003078e161305d).

[How documentation stays connected](https://docs.nika.sh/reference/knowledge-system.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.