Skip to content

Normalize a supplier number with a Reference Block

Use a Reference Block when multiple paths in the same workflow need the same transformation. This example trims whitespace from a supplier number received through chat or a webhook.

Workflow flow

flowchart TD
    Start([Chat or webhook request]) --> Trigger{"Does the request supply a webhook parameter?"}
    Trigger -->|Chat| Extract["LLM · Extract the supplier number"]
    Extract --> ChatRef["Reference · Pass the extracted number"]
    Trigger -->|Webhook| WebhookRef["Reference · Pass the webhook supplier number"]

    subgraph Shared["Normalize Supplier Number Reference Block"]
        Trim["Code · Trim whitespace"] --> BlockReturn["Return · Supply the trimmed number"]
    end

    ChatRef --> Trim
    WebhookRef --> Trim
    BlockReturn --> Result([Calling path returns the Reference output])

Configure the workflow

  1. Webhook. Define a String input named supplierNumber.
  2. Input routing. Add an If Condition with {{typeof $context.$triggers.REST.$input.supplierNumber === "string" && $context.$triggers.REST.$input.supplierNumber.length > 0}}. Use the true path for a nonempty webhook input and the false path for chat messages. Check the length before trimming so an input containing only spaces still reaches the shared block.
  3. Chat extraction. Add an LLM node with code EXTRACT_SUPPLIER. Pass {{$context.$system.$inputMessage}} in the User Prompt. Configure the output with a String field named supplierNumber and instruct the LLM to return an empty string when no supplier number can be identified.
  4. Reference Block. Add Normalize Supplier Number with a String parameter named rawSupplierNumber. Inside the block, add a Code node with code TRIM_SUPPLIER_NUMBER and Return Type set to String. Use Insert Expression to read the block parameter, then return its trimmed value. Add a Return node with value {{$context.$nodes.TRIM_SUPPLIER_NUMBER.$output.result}}.
  5. Chat Reference. Add a Reference node with code NORMALIZE_CHAT_SUPPLIER and select the block. Map rawSupplierNumber to {{$context.$nodes.EXTRACT_SUPPLIER.$output.supplierNumber}}.
  6. Webhook Reference. Add a Reference node with code NORMALIZE_WEBHOOK_SUPPLIER and select the same block. Map rawSupplierNumber to {{$context.$triggers.REST.$input.supplierNumber}}.
  7. Return. On each calling path, return that path's Reference output. Use {{$context.$nodes.NORMALIZE_CHAT_SUPPLIER.$output}} for chat and {{$context.$nodes.NORMALIZE_WEBHOOK_SUPPLIER.$output}} for webhook.

Leave Output Specification blank on the two Reference nodes to inherit the block's returned shape. Pass any data the block needs as parameters. The block cannot read variables declared in the enclosing workflow.

Run the example from chat or a webhook

In chat, ask “Normalize supplier number 8057.” For the webhook, publish the workflow and invoke it with the sample request below.

Sample webhook request

{
  "invocationMode": "END_USER",
  "message": "Normalize the supplier number.",
  "parameters": {
    "supplierNumber": " 8057 "
  }
}

Sample workflow output

"8057"

Expected behavior

Scenario Expected behavior
Chat contains a supplier number The chat Reference receives the extracted string and returns the normalized number.
Webhook sends " 8057 " The webhook Reference passes the padded string and returns "8057".
Webhook sends only spaces The block returns an empty string. If a caller uses the result for a lookup, validate it before calling the supplier API.

Related guides
Reference Block · Reference · Code · Workflow inputs and context