> ## 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](/reference/language/overview) / `when`

## Meaning and placement

### task

LOCAL business condition · false skips the task · evaluated POST-gate over \{vars · env · with · item · index}. Referring to `tasks.*` is illegal here (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](/reference/language/words/after) · [agent](/reference/language/words/agent) · [exec](/reference/language/words/exec) · [extract](/reference/language/words/extract) · [for\_each](/reference/language/words/for_each) · [group](/reference/language/words/group) · [infer](/reference/language/words/infer) · [invoke](/reference/language/words/invoke) · [lift](/reference/language/words/lift) · [on\_error](/reference/language/words/on_error) · [retry](/reference/language/words/retry) · [returns](/reference/language/words/returns) · [timeout](/reference/language/words/timeout) · [with](/reference/language/words/with)

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

## In a source template

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

```yaml illustration theme={"system"}
  answer:
    with:
      hits: ${{ tasks.retrieve.output }}
    when: ${{ size(with.hits) > 0 }}
    infer:
      max_tokens: 500                # SLOT: answer spend ceiling
      prompt: |
        Answer from these passages only and cite their ids.
        Question: ${{ const.query }}
        Passages: ${{ with.hits }}
```

### Templates containing this field

| Template                               | Source                                                                                                                                         |
| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `templates/corpus-qa.nika.yaml`        | [Line 97](https://github.com/supernovae-st/nika-spec/blob/c5ebbb7b862b68bc6cf7235efba61173b844afc6/templates/corpus-qa.nika.yaml#L97)          |
| `templates/etl-state.nika.yaml`        | [Line 102](https://github.com/supernovae-st/nika-spec/blob/c5ebbb7b862b68bc6cf7235efba61173b844afc6/templates/etl-state.nika.yaml#L102)        |
| `templates/gate-and-act.nika.yaml`     | [Line 69](https://github.com/supernovae-st/nika-spec/blob/c5ebbb7b862b68bc6cf7235efba61173b844afc6/templates/gate-and-act.nika.yaml#L69)       |
| `templates/human-gated-ship.nika.yaml` | [Line 147](https://github.com/supernovae-st/nika-spec/blob/c5ebbb7b862b68bc6cf7235efba61173b844afc6/templates/human-gated-ship.nika.yaml#L147) |

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

## Contract and implementation

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

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

[How documentation stays connected](/reference/knowledge-system).
