Branch a workflow on an LLM result
What you get: A webhook workflow that asks a model, checks the answer with an If node, and returns either the answer or "No answer generated".
Needs: A model: local Ollama as shipped, or a provider key · Time: 10 minutes · Nodes: 5
A Webhook Input at POST /webhook/conditional-demo passes user_prompt, system_prompt and session_id from the request body to an LLM Call. The Check Answer If node tests {{answer}}: if the model said anything, the Success Output returns it; if not, the Error Output returns "No answer generated". Only one output runs. As shipped, the model is llama3.1 on a local Ollama server, and the webhook has no authentication.
Steps
Download conditional-flow.json, or take it from the samples folder on GitHub.
In the studio's workflow editor, import the file (see import and export).
Open the LLM Call node and point it at a model you have: pull
llama3.1into Ollama, or switch the provider. In Docker, usehttp://host.docker.internal:11434/v1for Ollama on the host (on Linux, addextra_hosts: ["host.docker.internal:host-gateway"]to theapiservice). Save. To check the branching first without a model, use echo: the Provider list has no echo entry, so set the node'sproviderIdtoechoin the JSON file and import it again.Send a request:
bashcurl -X POST http://localhost:4000/webhook/conditional-demo \ -H "Content-Type: application/json" \ -d '{"user_prompt": "Is order 1042 late?"}'Open the run and click Check Answer to see
evaluatedValueand which branch it took.
How it works
| Node | Type | Role |
|---|---|---|
| Webhook Input | webhook_input | Step in the run |
| LLM Call | llm_call | Step in the run |
| Check Answer | if_node | Step in the run |
| Success Output | output | Step in the run |
| Error Output | output | Step in the run |
4 node types. Each type links to its config fields in the node reference.
What a run does
We ran it on a fresh install with the echo model and with a local stand-in server:
- Echo. The webhook answered
{"output":{"result":"Echo: Is order 1042 late?"}}. Check Answer evaluated to that text, took thetruebranch, and the Error Output was marked skipped. - No
user_promptin the body. Echo still answers, with a hint: "Echo provider received no user message. Wire a Text Input or Prompt Template into this LLM Call to see the echo." The true branch ran. A real model would get an empty message instead. - An empty answer. With a stand-in model that returns an empty string, the run took the
falsebranch and returned{"output":{"result":"No answer generated"}}. - The model is down. With the model's server unreachable, the run failed at the LLM Call after 4 attempts, the If node never ran, and the caller got HTTP 400 with
{"output":null,"error":"openai_compatible request failed after 4 attempt(s): fetch failed"}. The message names the node's provider; our stand-in usedopenai_compatible.
So the false branch catches an empty answer, which is rare with a working model. A model error, a bad key or a timeout fails the run before the If node. Handle those with an error workflow (below).
Write a better condition
The If node renders its condition as a template and reads the result as text. It is false when the text is empty, false, 0, null or undefined, and true otherwise. That is why {{answer}} means "the model said something".
Keep the whole expression inside the braces. Text outside them is not evaluated: a condition such as {{answer}} === 'true' renders as text such as Yes === 'true', which is never empty, so it is always true.
A condition can also be a JavaScript expression, run in a sandbox. With {{ answer.toLowerCase().includes("late") }}, "Is order 1042 late?" took the true branch and "Where is order 1042?" the false one. Two habits make conditions sturdier:
- Ask the model for a label, not prose. Tell it to answer with one word, such as
refundorquestion, or parse JSON first with an Output Parser and test{{parsed.intent}}. See extract structured JSON. - Use a Switch node for more than two paths. It compares one value with a list of cases and routes to the first match, or to
default.
Handle failures with an error workflow
Build a second workflow that starts with an Error Trigger and import it. Then add "settings": { "errorWorkflowId": "<its id>" } to this workflow's JSON, inside workflow, and import it again; the editor has no field for this setting. When a run fails, L2M starts it with the failed run's details: source_workflow_id, source_workflow_name, execution_id, error, error_stack and timestamp.
We tested it with an error workflow whose HTTP Request step posts those fields to a local server. With the model down, it received {"wf":"Conditional Branching Flow","err":"openai_compatible request failed after 4 attempt(s): fetch failed","exec":"..."}. The caller of the webhook still gets the 400 error; the error workflow runs on the side, for alerts or clean-up.
Make it yours
- Write the system prompt on the LLM Call node instead of taking
system_promptfrom the request, so callers cannot rewrite the model's instructions. - Replace the two Output nodes with real work on each branch: a reply on one, a ticket or an approval on the other. End with a Merge / Join node if the branches should meet again.
Make it safer
These controls are optional; the recipe runs without them.
- Secure the webhook before anyone else can reach it: a bearer token or an HMAC signature, and idempotency for retried calls. See Secure webhooks.
- A model's answer is untrusted text. Branch on a fixed label, not on free text that a caller can steer.
- Cap what callers can spend with a budget.