# Workflows: Concepts & Architecture

> Typed JSON schemas, safe variable interpolation, single-pass Shield guardrails, version pinning, zero payload retention and pricing.

- **Source:** https://www.noirdoc.de/en/docs/concepts/workflows/
- **API base URL:** `https://api.noirdoc.de/v1`

**Noirdoc Workflows** executes linear multi-model pipelines synchronously in a single HTTP request:

```text
JSON Input → Shield Guardrail → Step 1 → … → Step N → JSON Output
```

Every step inherits your organisation's standard gateway routing: cheapest-first EU selection, Bring Your Own Key (BYOK), provider failover, [§ 203 StGB enforcement](/en/docs/routing/#berufsgeheimnistraeger), and key and [tag budgets](/en/docs/keys-billing/#budgets).

> **Beta status & limits:** Noirdoc Workflows is in Beta, enabled by default for every active organisation, and runs 1 to 10 linear steps synchronously as a JSON response (no SSE streaming, at most 300 s total wall-clock timeout and 15 MB request body).

## What happens on a `/run` call?

Every request to `POST /v1/workflows/{slug}/run` or `/v{n}/run` runs through five fixed stages:

1. **Auth, body limit (15 MB) & `input_schema`:** Checks the `px-` key and active organisation (401 `invalid_api_key` on an invalid/disabled key or inactive organisation), size caps (15 MB total JSON body, 10 MB decoded per file; 413 `payload_too_large`) and JSON Schema Draft 2020-12 (422 `invalid_workflow_input`). Rejections here (401, 413, 422) incur €0 workflow fee.
2. **Single-pass Shield inspection at ingress:** Under `block` or `redact`, [Noirdoc Shield](/en/docs/shield/) inspects every non-empty string field and inline UTF-8 text file once before Step 1 (billed separately like a direct Shield call). Binary PDFs and images trigger 422 `shield_uninspectable_content` (€0) under `enforced` Shield. If 403 `shield_violation` triggers, model cost is €0.00 while Shield inspection and the single €0.002 workflow run fee are settled normally (fail-closed 503 `shield_unavailable` incurs €0).
3. **Sequential steps 1..N:** Runs prompt steps (optionally with file attachments via `attachments`) with single-pass interpolation and your standard organisation routing. Every executed run settles the single €0.002 orchestration fee once.
4. **Local `output_schema` check + max. 1× auto-repair:** Validates the final JSON against Draft 2020-12 and runs at most one repair call on the final step (502 `workflow_output_invalid` if repair still fails).
5. **Synchronous JSON & zero payload retention:** Returns the validated `output` object with per-step and EUR cost metadata – only metadata is recorded in the run log.

## Typed schemas & 1× auto-repair

Each workflow defines an `input_schema` and an `output_schema` using **JSON Schema Draft 2020-12**:

#### Input validation (`input_schema`)

*€0 on rejection*

Before Shield and Step 1, the engine validates the JSON request body against `input_schema`. Invalid payloads fail immediately with 422 `invalid_workflow_input` (listing field paths without logging raw values) at €0 workflow fee.
  #### Provider normalisation (`strict: true`)

*OpenAI & Anthropic*

When dispatching to OpenAI or Anthropic models, the engine normalises a provider copy of the schema for `strict: true` (adding `additionalProperties: false` on objects and stripping provider-unsupported keywords such as `format`) while keeping full Draft 2020-12 validation locally. If a provider still rejects the schema with HTTP 400, the step falls back once to prompt-instructed JSON.
  #### Automatic repair (`meta.repair_attempted`)

*Max. 1× on final step*

If the final step's output fails JSON parsing or `output_schema` validation, the engine executes at most one repair call to the final step's model with the schema and exact validation errors (`meta.repair_attempted: true`). If it still fails, the API returns 502 `workflow_output_invalid`.

## Safe variable interpolation

Prompt templates access inputs and earlier steps via dot paths:

- `{{input.<path>}}` reads fields from the (possibly redacted) input JSON.
- `{{steps.<key>}}` inserts the full output of a previous step (objects serialised as compact JSON).
- `{{steps.<key>.<path>}}` reads a nested field from a JSON step output.

```text
Channel: {{input.channel}}
Message: {{input.message}}
Category from step 1: {{steps.classify.category}}
```

Substitution runs strictly in a **single pass** with no Jinja or code evaluation. If untrusted input literally contains `{{steps.classify}}`, that string stays untouched and is never re-expanded.

## File & Vision inputs

Alongside text fields, workflows accept PDFs, images and text files directly for Vision-capable catalogue models (such as `gemini-3.8-flash`, `claude-sonnet-5-5` or `gpt-5.4-mini`):

#### Schema declaration (`format: data-url`)

*Base64 data URL*

Declare file inputs in `input_schema` as string fields with `"format": "data-url"` and send them as base64 data URLs (`data:<mime>;base64,...`) inside the JSON body.
  #### Step binding (`attachments`)

*Multimodal block*

A prompt step references file inputs via `"attachments": ["input.receipt_file"]`. The engine attaches the payload as a native multimodal file or image block and never dumps raw base64 into the prompt text.
  #### Allowed MIME types & caps

*Max. 15 MB body · Max. 10 MB / file*

Supports PDF (`application/pdf`), images (`image/png`, `image/jpeg`, `image/webp`, `image/gif`) and UTF-8 text files (`text/plain`, `text/markdown`, `text/csv`, `application/json`, `application/xml`, `text/xml`). Total JSON request body is capped at 15 MB, with at most 10 MB decoded per file.
  #### Interaction with Noirdoc Shield (`enforced`)

*UTF-8 inspected · binary fail-closed*

Inline UTF-8 text files are decoded and inspected by Shield. Binary PDFs and images cannot be text-inspected: when your organisation's Shield policy is `enforced`, the run fails before Step 1 with 422 `shield_uninspectable_content` (€0.00); without `enforced`, Shield inspects all remaining text fields and forwards the binary attachment to the Vision model.

## Single-pass Shield at ingress

The engine inspects every non-empty string leaf of the input JSON exactly **once before Step 1** through [Noirdoc Shield](/en/docs/shield/) on German infrastructure:

#### Disabled (`off`)

*Blocked under enforced*

Skips Shield inspection; forbidden when the organisation policy is `enforced` (422 `shield_enforced_cannot_disable`).
  #### Block (`block`)

*403 shield_violation*

Overrides all enabled organisation rules to `block`; matching content halts before Step 1 with 403 `shield_violation`.
  #### Redact (`redact`)

*secrets & injection stay block* — `[PERSON]`, `[IBAN]`

`pii`, `ner` and `custom` redact in memory with fixed placeholders, while `secrets` and `injection` stay `block`.

> **Operational guarantees for regulated workloads**
>
> - **No double billing:** Once ingress inspection passes, downstream step calls carry a service-authenticated internal Shield-checked marker so Shield is charged once at ingress (€0.40 / 1M inspected input tokens), never repeated per step.
> - **Fail-closed:** If Shield is unreachable or times out while active, the run aborts with 503 `shield_unavailable`. Uninspected text never reaches a model.
> - **Runtime `enforced` override:** If an organisation enables `enforced` after publishing an older workflow with `pii_mode: "off"`, the runtime fails safe to active Shield `redact`.

## Versioning & permissions

Drafts (`draft_definition`) are mutable and can be tested in the browser at any time. Publishing records an immutable snapshot (`v1`, `v2`, …) with `sample_input` and `ui_layout` stripped:

- `POST /v1/workflows/{slug}/run` always runs the latest published version.
- `POST /v1/workflows/{slug}/v{n}/run` pins your application to version `n` – even after `v2` is published.

Role boundaries within an organisation: `admin` creates workflows, edits drafts, runs browser tests, publishes new versions and archives workflows; `member` has read-only access to workflows, versions and run metadata. Workflows is available to every active organisation without separate activation; requests with a missing, invalid or disabled API key or an inactive organisation fail before Step 1 with 401 `invalid_api_key` (€0.00).

## Zero payload retention & audit trail

The workflow engine **never stores** customer inputs, intermediate step outputs, final outputs or detected plaintext PII in databases, caches or logs:

- The run log stores metadata only: `run_id`, workflow ID, version, source (`api` or `browser_test`), HTTP status, error code, duration, step count, `pii_mode`, detected categories (such as `["PERSON", "IBAN"]`) and EUR cost breakdown.
- Browser test runs return intermediate step outputs live in the HTTP response only, require no `px-` key, and appear separately from production API runs in gateway audit logs.
- Organisation audit logs (**Activity**) record control-plane events (`workflow.created`, `workflow.updated`, `workflow.published`, `workflow.archived`, `workflow.test_run`) without payload data.

## Pricing & settlement

| Cost component             | Rate                    | When billed                                                                                                  |
| -------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------ |
| Workflow orchestration fee | €2.00 / 1,000 runs      | €0.002 once per executed run (including 403 `shield_violation`, managed models, BYOK and browser test runs). |
| Model tokens               | Catalogue rate per step | Standard gateway token pricing per step executed (BYOK settles model tokens directly with your provider).    |
| Noirdoc Shield (optional)  | €0.40 / 1M tokens       | Once at ingress when `block` or `redact` is active, billed separately just like `/v1/shield/inspect`.        |
| Base fee / subscription    | €0.00                   | No minimum spend, no fixed contract term.                                                                    |

> **Billing on rejections and partial runs:** Requests rejected before execution (401 `invalid_api_key`, 413 `payload_too_large`, 422 `invalid_workflow_input`, 422 `shield_uninspectable_content`, 503 `shield_unavailable`) incur **€0.00**. When 403 `shield_violation` halts a run at ingress, zero model tokens are billed while Shield inspection (€0.40 / 1M tokens) and the single €0.002 workflow run fee settle normally. If Step 2 fails after Step 1 succeeds, Step 1's tokens and the single €0.002 run fee remain debited normally.

## Related pages

- [**Workflows: 5-Minute Guide**](/en/docs/guides/workflows/) — From starter template to browser test run, immutable v1 publish and your first production API call.
- [**Workflows: API Reference**](/en/docs/reference/workflows/) — Endpoints, headers, response fields, Vision attachments, limits and all workflow error codes.
