Mocks

vellum.workflows.nodes.mocks.MockNodeExecution

Mocks allow you to override node outputs during local execution, which is useful for testing specific scenarios without calling external services or APIs.

MockNodeExecution

The MockNodeExecution class provides fine-grained control over when and what outputs to mock.

Attributes

when_condition
BaseDescriptorRequired

A condition that determines when this mock should be applied. Supports expressions using workflow inputs and node execution counters.

Note: Currently, the only when_condition supported by the Vellum UI is the same node’s execution count greater than or equal to 0.

then_outputs
BaseOutputsRequired

The outputs to return when the condition is met. Must be an instance of the node’s Outputs class.

disabled
Optional[bool]

Set to True to disable this mock without removing it from the dataset.

Simple Mocks

For simple cases, you can pass a node’s Outputs instance directly to the mocks list:

1from vellum.workflows import DatasetRow
2
3from .inputs import Inputs
4from .nodes.my_prompt_node import MyPromptNode
5
6dataset = [
7 DatasetRow(
8 label="With simple mock",
9 inputs=Inputs(query="test"),
10 mocks=[
11 MyPromptNode.Outputs(text="Mocked response"),
12 ],
13 ),
14]

Conditional Mocks

For more complex scenarios, use MockNodeExecution with conditions:

1from vellum.workflows import DatasetRow, MockNodeExecution
2
3from .inputs import Inputs
4from .nodes.process_node import ProcessNode
5
6dataset = [
7 DatasetRow(
8 label="With conditional mocks",
9 inputs=Inputs(threshold=5),
10 mocks=[
11 MockNodeExecution(
12 when_condition=(
13 Inputs.threshold.equals(5) &
14 ProcessNode.Execution.count.equals(0)
15 ),
16 then_outputs=ProcessNode.Outputs(result="first_execution"),
17 ),
18 MockNodeExecution(
19 when_condition=(
20 Inputs.threshold.equals(5) &
21 ProcessNode.Execution.count.equals(1)
22 ),
23 then_outputs=ProcessNode.Outputs(result="second_execution"),
24 ),
25 ],
26 ),
27]

Condition Operators

The when_condition supports various comparison operators:

OperatorDescription
.equals(value)Equal to
.does_not_equal(value)Not equal to
.greater_than(value)Greater than
.greater_than_or_equal_to(value)Greater than or equal to
.less_than(value)Less than
.less_than_or_equal_to(value)Less than or equal to
&Logical AND
|Logical OR