Guide: Build a decision workflow

In this walkthrough you go from an empty tenant to a running approve/decline decision tree:
income above 50,000 approves, anything else declines. It is the shortest complete path through
authoring, and every larger workflow is this shape repeated.

You drive it in natural language. The prompts below are what you type; the tool calls noted
underneath are what your assistant runs, so you can follow along and check its work.

Before you start

  • A connection to the environment you want to build in. Sandbox is the safe place for a first build;
    derived variables are created in Live only.
  • Skim the workflow ground rules — steps 5 and 7 below are
    where those rules bite.

You can also paste the whole thing as one prompt and let the assistant work through it. Going
step by step is better the first time, because you see where each ID comes from.


Step 1 — Check what variable types you can use

Show me the variable types LendAPI supports for workflow authoring, and the naming rules for
variable codes.

Tool: variables_get_supported_types (answered locally, no call to LendAPI)

You get the four supported types — numeric, string, boolean, list — and the engine_name rules.
Names are lowercase, letters/numbers/underscore, no leading digit, no reserved words, 60
characters max, unique per tenant.

Step 2 — Create the input variable

Create a numeric variable called "Annual Income" with the code annual_income, described as
"Applicant's stated annual income".

Tool: variables_create_simple with name, engine_name, type=1, description

The response carries the new variable's ID. If the code is rejected, it is almost always casing,
a leading digit, or a reserved word — fix it and retry.

List my variables and confirm annual_income is there.

Tool: variables_list

Step 3 — Create the outcomes

An action node needs an outcome to point at, so create those before you build the tree. This
workflow has two endings, so create two.

Create two outcomes: "Income Approve" as an Approve outcome, and "Income Decline" as a Decline
outcome.

Tool: outcomes_create twice — outcome_type=1 for Approve, outcome_type=2 for Decline

Note both returned IDs. You need them in step 6.

List my outcomes so I can see both IDs.

Tool: outcomes_list

Valid outcome types are 1 Approve, 2 Decline, 3 Review, 5 Request Docs. Nothing else.

Step 4 — Create the tree

Create a decision tree called "Income Screen" with the description "Approve above 50k income".

Tool: decision_trees_create

Two things come back and both matter:

ValueWhat it is
Session UUIDThe workflow's ID. Every later call uses it
Initial node IDThe tree's root, an unconfigured rule node

List my decision trees and confirm "Income Screen" is there.

Tool: decision_trees_list

Step 5 — Add the two action nodes

The root rule node already exists. What it lacks is somewhere to branch to. A rule node must
have exactly two children, and every leaf must be an action node.

Add two action nodes to that tree: one titled "Approve", one titled "Decline".

Tool: decision_trees_add_node twice, with node_type="2"

Node titles are capped at 30 characters. Note both node IDs.

Step 6 — Connect them

Connect the root node to the Approve node on the yes branch, and to the Decline node on the no
branch.

Tool: decision_trees_connect_nodes twice — child_direction="2" for yes, "1" for no

DirectionMeaning
"2"Right / Yes — the rule evaluated true
"1"Left / No — the rule evaluated false

Step 7 — Configure the rule node

Configure the root node as a rule: annual_income greater than 50000. Title it "Income Check".

Tool: decision_trees_update_rule_node

The expression the assistant sends:

{
  "combinator": "and",
  "rules": [
    {"field": "annual_income", "operator": ">", "value": 50000}
  ]
}

An expression must contain at least one rule. If you compare one variable against another
variable rather than a constant, both variables must be numeric.

Step 8 — Configure the action nodes

This is the step with the two-field rule. Each action node needs a status change and an
outcome
, not one or the other.

Configure the Approve node with the Approve status change and the "Income Approve" outcome, and
the Decline node with the Decline status change and the "Income Decline" outcome.

Tool: decision_trees_update_action_node twice — action_id=1 with the approve outcome as
assignment_id, action_id=2 with the decline outcome as assignment_id

Miss either field and the workflow will not publish, with the error appearing later at submit
time rather than here.

Show me the current draft so I can check the structure.

Tool: decision_trees_get

Confirm: one rule node with two children, both children are action nodes, and each action node
has a status change and an outcome.

Step 9 — Save the workflow metadata

Save the workflow metadata with the title "Income Screen".

Tool: decision_trees_save_metadata

This is also where you attach a product (assigned_product_id), a pricing engine
(pricing_engine_id), or turn on run_all_nodes if you want every path evaluated instead of
stopping at the first match. It does not create a version.

Step 10 — Submit a version

Submit this draft as a new version, described as "v1 — income screen".

Tool: decision_trees_submit_version

The version is created with status Pending Approval. If you get "Workflow is not publishable
yet", walk the checklist: every rule node configured, every action node with both fields, every
leaf an action node, every rule node with two children.

If you get "No New changes Detected", the draft is identical to the current version — nothing to
do.

List the versions of this tree.

Tool: decision_trees_list_versions

Step 11 — Promote it

Set that version as the default.

Tool: decision_trees_set_default_version

The default version is what runs when no version is specified.

Step 12 — Find out what a run needs

What input parameters does this version need in order to run?

Tool: decision_trees_get_required_params

You should see annual_income. Always do this before running — a run missing a required param
fails.

Step 13 — Run it

Run the tree with annual_income of 75000, then again with 30000, and tell me the outcome each
time.

Tool: decision_trees_run twice

Expected: 75000 approves, 30000 declines. If a run reports a decision-engine error, the workflow
is fine — the engine was unreachable. Retry.


What you have now

  • A variable, two outcomes, and a published decision tree with a default version.
  • A tree that can be attached to a product so it runs on real applications.

Where to go next

Add a second condition. Rule nodes combine conditions with and / or:

Add a FICO score check to the income rule: annual_income above 50000 and fico_score at
least 640.

Then submit and promote a new version — versions are how changes ship.

Go deeper than one level. Replace an action node with a rule node to create a second decision
layer, remembering that every rule node needs two children and every leaf must be an action node.

Chain to another workflow. An action node can point at another published decision tree
instead of an outcome, using chain_decision_id.

Route by product. decision_trees_save_metadata takes an assigned_product_id. Use
products_list to find the ID, and products_get to see which trees a product already runs.

If something goes wrong

SymptomLook at
Variable code rejectedVariable naming
"Assignment not found"Create the outcome before configuring the node
"Workflow is not publishable yet"Publishability
Run fails on missing paramsCall decision_trees_get_required_params first
variables_create_derived fails on sandboxDerived variables are Live-only; pass environment: "live" or use a Live connection
A tool says the connection has no key for that environmentA header connection reaches one environment per token; sign in (OAuth) to get both

Full list: workflow ground rules and
troubleshooting.


Did this page help you?