> For the complete documentation index, see [llms.txt](https://docs.fortifiedid.se/pipes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fortifiedid.se/pipes/subpipes.md).

# Subpipes

Reusable named valve sequences that run in the calling pipe's context.

A subpipe is a named, reusable sequence of valves defined at module level. When a pipe includes a subpipe using the [Pipe Include](/pipes/valves/flow/pipe-include.md) valve, the subpipe's valves execute inside the calling pipe's context. They share the same request, session, state, and items — no new context is created.

This is useful when several pipes share a common set of steps, such as enriching request data, validating a token, or building a set of items, and you want to maintain that logic in one place.

{% hint style="info" %}
Subpipes are similar to [Pipe Exec](/pipes/valves/flow/pipe-exec.md) in that they run within the current context. The key difference is that subpipes are not deployed as independent pipes and cannot be called externally — they exist solely to be reused by other pipes within the same module.
{% endhint %}

## Defining subpipes

Subpipes are defined in the module configuration. The preferred approach is to use the top-level `subpipes` attribute alongside the `pipes` array.

{% tabs %}
{% tab title="Properties" %}

<table><thead><tr><th>Name</th><th>Description</th><th>Default</th><th data-type="checkbox">Mandatory</th></tr></thead><tbody><tr><td><code>id</code></td><td>Unique identifier of the subpipe. Used when referencing the subpipe from the <a href="/pipes/valves/flow/pipe-include.md">Pipe Include</a> valve.</td><td></td><td>true</td></tr><tr><td><code>enabled</code></td><td>Flag to enable or disable the subpipe.</td><td><code>true</code></td><td>false</td></tr><tr><td><code>display_name</code></td><td>Optional display name used in logs. If omitted, the <code>id</code> is used.</td><td><code>id</code></td><td>false</td></tr><tr><td><code>config.valves</code></td><td>Ordered list of valves forming the subpipe.</td><td><code>[]</code></td><td>false</td></tr></tbody></table>
{% endtab %}

{% tab title="Example" %}

```json
{
  "name": "Pipes",
  "config": {
    "subpipes": [
      {
        "id": "shared-auth",
        "enabled": true,
        "display_name": "Shared auth logic",
        "config": {
          "valves": [
            {
              "name": "SessionPut",
              "enabled": true,
              "config": {
                "name": "authenticated",
                "value": "true"
              }
            }
          ]
        }
      }
    ],
    "pipes": [
      {
        "id": "pipe01",
        "config": {
          "valves": [
            {
              "name": "PipeInclude",
              "config": {
                "subpipe": "shared-auth"
              }
            }
          ]
        }
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

## Using a subpipe

A subpipe is included in a pipe using the [Pipe Include](/pipes/valves/flow/pipe-include.md) valve. The `subpipe` property references the subpipe by its `id`.

```json
{
  "name": "PipeInclude",
  "config": {
    "subpipe": "shared-auth"
  }
}
```

The `exec_if_expr` property can be used on a `PipeInclude` valve to conditionally include the subpipe, the same as with any other valve.

## Restrictions

The following valves are not allowed inside a subpipe and will cause an error at startup:

* `PipeInclude` — subpipes cannot include other subpipes
* `PipeExec` — subpipes cannot execute other pipes
* `PipeCall` — subpipes cannot call other pipes

## Logging

When a subpipe executes, each valve logs with context identifying both the calling pipe and the subpipe:

```
pipe=<pipe-id> subpipe=<subpipe-display-name> valve=<valve-name>[<index>]
```

This makes it possible to trace execution across pipes and subpipes in the same log stream.
