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¶
- Webhook. Define a String input named
supplierNumber. - 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. - 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 namedsupplierNumberand instruct the LLM to return an empty string when no supplier number can be identified. - Reference Block. Add Normalize Supplier Number with a String parameter named
rawSupplierNumber. Inside the block, add a Code node with codeTRIM_SUPPLIER_NUMBERand 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}}. - Chat Reference. Add a Reference node with code
NORMALIZE_CHAT_SUPPLIERand select the block. MaprawSupplierNumberto{{$context.$nodes.EXTRACT_SUPPLIER.$output.supplierNumber}}. - Webhook Reference. Add a Reference node with code
NORMALIZE_WEBHOOK_SUPPLIERand select the same block. MaprawSupplierNumberto{{$context.$triggers.REST.$input.supplierNumber}}. - 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
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