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

# Functions

> Break graphs into reusable, testable functions with clear inputs and outputs.

Functions are reusable graph resources. They keep the main automation small and let you test one piece of behavior without running the entire graph.

## Choose A Function Scope

| Scope | Use it when |
| - | - |
| **Local** | The function belongs to one automation. It is available to that graph and its other local functions. |
| **Account** | The behavior should be reusable by different automations in your account. |

Account functions appear in the special **Account Functions** folder. Local and account functions can each use nested folders. Drag functions and folders to reorganize them within the same scope.

Choose the scope when creating or importing the function. Functions and folders can move within their current scope, but a local function cannot be moved into **Account Functions**, and an account function cannot be moved into a local graph. To change scope, create or import a separate function in the intended location and update callers deliberately.

## Choose Pure Or Impure

| Mode | Use it for | Examples |
| - | - | - |
| **Pure** | Deterministic data work with no execution rail or side effects. | Validate an address, select the first match, calculate a value, format a ticker. |
| **Impure** | Work that runs in sequence, depends on an external service, or may create side effects. | Draw ticker artwork, launch, buy, sell, record a trace notification, wait, call AI, or coordinate other impure functions. |

A pure function can be evaluated whenever another node needs its output. An impure function has execution connections that determine when it runs.

## Create A Function

<Steps>
  <Step title="Open Build">
    In the graph editor, select **Build**, then find **Functions**.
  </Step>

  <Step title="Choose the destination">
    Use the add menu at the function root or inside a folder. Choose a local or account function.
  </Step>

  <Step title="Describe the responsibility">
    Give the function a focused name and description. Choose **Pure** or **Impure**, and optionally assign a folder.
  </Step>

  <Step title="Define its boundary">
    Add named inputs and outputs in the function's **Build** tab. Set each value's type, structure, nullability, and input default where appropriate.
  </Step>

  <Step title="Build between Entry and Return">
    Connect input values from **Function Entry** through the function's nodes, then connect results to **Function Return**. Impure functions also connect the execution path.
  </Step>

  <Step title="Save and test">
    Save the function version, then use **Tests** to verify inputs, outputs, and any expected effects.
  </Step>
</Steps>

After saving, the function appears in the same resource selector as the main graph. Its **Build** tab holds the named boundary and its canvas holds the implementation, so callers only need to work with the declared inputs and outputs.

## Call A Function

From the main graph or another compatible function:

1. Find the function under **Build > Functions**.
2. Insert its call on the canvas.
3. Connect the required inputs and use its outputs.
4. For an impure function, also connect its execution input and **Then** output.

Function calls use the selected saved function version. Creating a newer function version does not silently change existing calls. Inspect a call before upgrading it, especially when inputs or outputs changed.

## Pass Values Into A Function

Local and account functions follow the same boundary rule: they do not automatically read variables from the root graph or calling function. Variables created inside a function belong to that function.

When a function needs a caller's variable:

1. Add a function input with the same type and structure.
2. Insert **Get Variable** in the calling graph.
3. Connect its `value` output to the matching function-call input.

An input is optional at a call only when it has an explicit default value. Marking an input as nullable allows `null`, but does not make the input optional. A nullable input with no default still needs a connection at every call site.

## Change A Function Safely

Changing an input, output, or mode can affect call sites and saved tests. The editor shows the expected impact before applying a breaking boundary change.

* Add explicit value defaults when callers may safely omit an input.
* Keep output meanings stable across versions.
* Create a new version before a major change.
* Run the function tests and every parent graph test after upgrading calls.
* Archive an obsolete function to remove it from new-call menus. Existing saved calls keep their pinned behavior.

<Warning>
  A function can be used by multiple graphs. Review call-site impact and create a new version instead of changing shared behavior in place.
</Warning>

## Test A Function

Pure function tests provide inputs and check selected output values. Impure function tests compare the complete expected-effect list exactly, including effect count and order. Blank output fields are ignored, which lets one test focus on only the outputs that matter.

Tests belong to an exact function version. Save changes before running them so results match the version under review.

See [Testing](/scrapist/testing) for graph tests and effect assertions.
