Skip to main content

Expression and I/O Rules — Accessing Diagram Fields from Every Node

LLM4B provides four complementary ways for a node to read fields from your workflow diagram's state, depending on what the node does: **template interpolatio...

Workflow Authoring

Expression and I/O Rules — Accessing Diagram Fields from Every Node

LLM4B provides four complementary ways for a node to read fields from your workflow diagram's state, depending on what the node does: template interpolation, JMESPath expressions, direct state-key selectors, and Python / Sub-Workflow context mappings. This guide documents the exact syntax, runtime boundaries, and a complete node-by-node I/O matrix.


1. Template Interpolation ({{key}} and {key})

String templates are rendered using a deterministic placeholder matcher that recognizes both double-brace {{key}} (recommended) and single-brace {key} syntax:

  • Allowed key characters: [A-Za-z0-9_]+ (letters, digits, and underscores).
  • Missing keys: If a referenced key is absent from the node's scoped state, it resolves cleanly to an empty string "" rather than throwing.
  • JSON safety: Prefer double braces {{key}} inside JSON payloads (such as HTTP Request bodies or Webhook Callback templates) so literal JSON braces { ... } remain intact while {{key}} is substituted.
  • Top-level key scope: Template placeholders read top-level keys from the node's scoped state (state[key]). They do not evaluate nested dot-paths like {{order.customer.email}}. To interpolate a nested property inside a template, extract it first with a Python Script or Regex Operation node, or map the specific field cleanly with an explicit Data Wire.

Where template interpolation is supported:


2. JMESPath Expressions (path)

Branching and fan-out nodes evaluate full JMESPath queries against the node's resolved state dictionary—giving you deep access into nested JSON objects, arrays, and computed projections:

Pattern Example path What It Reads
Top-level key score state["score"]
Nested object field classification.confidence state["classification"]["confidence"]
Array element orders[0].total First order's total field
Array projection orders[*].sku List of all SKUs across orders
Filtered list items[?price > \100`]| Items withpriceabove100`
Built-in function length(dataset_files) Count of elements in dataset_files

Where JMESPath is supported:

  • Condition — evaluates path, then compares against value using <, <=, >, >=, ==, or != to pick true or false.
  • Router — evaluates path, converts the result to string, and routes to the matching branch in cases or falls back to default.
  • Parallel Fan-out — evaluates path to extract the list/array to iterate over concurrently.

3. Direct State-Key Selectors & Payload Modes

Several nodes read a complete structured value (string, JSON object, list, or FileRef) directly by state key name without stringification:

  • input_key: Used by LLM Inference (prompt_source: "state_key"), AI Agent (prompt_source: "state_key"), Python Script, Regex Operation, and Dataset Write.
  • file_input_keys: List of state keys holding FileRef handles attached multimodally to LLM Inference.
  • payload_source / payload_key / payload_template: Shared across Webhook Callback, Workflow Output, and Finish:
    • entire_state — emits all non-internal (non-_) keys from the node's state.
    • specific_key (or state_key) — emits the exact value stored at payload_key.
    • custom_template — renders payload_template via {{key}} interpolation (and auto-parses as JSON when content_type is application/json).

4. Python Sandbox & Sub-Workflow Contexts

  • Python Script: Your script receives an inputs dictionary containing inputs["input"] (resolved from input_key) plus every other non-internal scoped state key (e.g., inputs.get("customer_tier")). Any FileRef values are staged on local sandbox disk automatically. Assign return fields into outputs[...] and the node writes outputs to state under output_key.
  • Sub-Workflow: Maps each declared key in Inputs into the child workflow's initial state and merges child outputs back into parent state.

5. Explicit DataWires Syntax

Prefer explicit DataWires inside each WorkflowWireSpec entry in Wires (or AddWires in a WorkflowGraphPatch) whenever renaming keys, disambiguating branches, or consuming secondary output keys:

Code
{
  "FromNode": "fetch_1",
  "FromPort": 1,
  "ToNode": "llm_1",
  "ToPort": 0,
  "DataWires": [
    { "FromKey": "http_response", "ToKey": "rendered_prompt" }
  ]
}

Each WorkflowDataWireSpec object uses { "FromKey": "<upstream_output_key>", "ToKey": "<downstream_input_key>" } (never put from_node/to_node inside DataWires—those belong to WorkflowWireSpec.FromNode and WorkflowWireSpec.ToNode).

  • Avoid duplicate output_key names across active branches unless intentionally overwriting a shared state key.
  • Internal _-prefixed keys are always stripped from entire_state payloads and user script inputs.

6. Node-by-Node Field Access & Output Key Matrix

Node How It Reads Diagram Fields State Keys Written (Primary & Secondary)
Workflow Input Run payload / test_payload JSON All top-level payload keys (__initial__)
HTTP Webhook Inbound POST JSON body All top-level body keys (__initial__)
Cron Schedule Recurring cron schedule (crons, timezone, overlap, pause_on_failure, catchup_window_minutes) Passes initial state through (__initial__)
Periodic Interval Fixed-minute interval schedule (interval_minutes, jitter_seconds, overlap, pause_on_failure, catchup_window_minutes) Passes initial state through (__initial__)
Signal Trigger External signal JSON payload All signal payload keys merged into state
Condition JMESPath path + op + value None (passthrough; activates true or false branch)
Router JMESPath path matched against cases None (passthrough; activates matching case or default)
Parallel Fan-out JMESPath path (array) {output_key} (ordered array of child final states)
Sub-Workflow Declared Inputs port keys Declared child Outputs merged into parent state
Wait / Timer None (passthrough) None (preserves upstream state)
Regex Operation input_key (string) {output_key} (string, bool, or list)
Prompt Template {{key}} / {key} in prompt asset {output_key} (default rendered_prompt)
LLM Inference input_key or prompt_template ({{key}}) + file_input_keys (FileRef) {output_key}, {output_key}_metadata
AI Agent input_key or prompt_template ({{key}}) {output_key}, {output_key}_raw, {output_key}_turns, {output_key}_tool_calls
HTTP Request {{key}} in url, query_params, headers, body_template, output_filename {output_key}, {output_key}_status, {output_key}_headers
Python Script inputs["input"] (input_key) + all scoped non-_ keys {output_key} (default python_result)
Approval Gate Scoped review context + reviewer decision {output_key} (default approval_result)
Dataset Read {{key}} in partition_filter {output_key}, {output_key}_files, {output_key}_count
Dataset Write input_key (rows or FileRef) + {{key}} in partition_path, filename_template {output_key}, {output_key}_rows_written, {output_key}_schema, {output_key}_stats
Webhook Callback {{key}} in url + payload_source (entire_state, payload_key, payload_template) {response_state_key}, {response_state_key}_status
Workflow Output payload_source (entire_state, payload_key, payload_template) _workflow_output
Finish Static message or source_from_input payload _finish_message, _workflow_output

7. Validation Modes

  • AuthoringDraft: Allows incomplete draft fields (such as an unconfigured webhook secret or missing BYOK credential) as Warning diagnostics while blocking structural, unknown-type, cycle, or quota errors.
  • StrictRunReady: Enforces full node readiness (NODE_NOT_READY, SECRET_REFERENCE_NOT_FOUND, SKILL_NOT_FOUND, DATASET_GOVERNANCE_ERROR) as Error diagnostics before execution.