﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head>---
url: https://docs.puppetflow.com/reference/flow-api/response.md
---
# Response & Output

Build the flow's return value. Every flow node must return a response object - these helpers produce the expected format.

## `$setOutput(keyOrObject, value?)` {#set-output}

Add data to the response output. Called before `$generateResponse*` to attach extra fields.

```js
$setOutput('invoiceCount', 5);
$setOutput('total', 1234.56);

// Bulk merge
$setOutput({ status: 'done', items: ['a', 'b', 'c'] });
```

All keys set via `$setOutput` are merged into the final response alongside `status` and `message`.

## `$generateResponse(status, message, data?)` {#generate-response}

Build a response object with a custom status string. This is the base function used by the success/error shorthands.

```js
return $generateResponse('success', 'Processed 3 invoices', {
  invoiceIds: [1, 2, 3],
});
```

**Returns:**

```js
{
  status: 'success',
  message: 'Processed 3 invoices',
  invoiceIds: [1, 2, 3],
  // ... any keys set via $setOutput()
  $context: { /* runtime context */ }
}
```

When **"Include input in output"** is enabled in the flow settings, the original input is attached under a `$input` key.

## `$generateResponseSuccess(message, data?)` {#generate-response-success}

Shorthand for `$generateResponse('success', ...)`.

```js
return $generateResponseSuccess('Done', { count: 5 });
```

## `$generateResponseError(message, data?)` {#generate-response-error}

Shorthand for `$generateResponse('error', ...)`. Logs the message to stderr.

```js
return $generateResponseError('Login failed - invalid credentials');
```

## `$stopSuccess(message, data?)` {#stop-success}

Immediately stop the current run and return a success response. This is useful inside nested helpers where returning from `run()` is not possible.

```js
function finishEarly(count) {
  if (count === 0) {
    $stopSuccess('Nothing to process', { count });
  }
}
```

## `$stopFail(message, data?)` {#stop-fail}

