Docs menuFlow schema
Flow schema
The complete JSON schema for conversation flows — every node, field, and validator, taken from the live Zod definitions.
A flow is a JSON document validated against the Zod schema in backend/src/engine/v2/schema.ts. This page is the canonical wire reference. Field names are exactly what the engine accepts.
Root document
{
"name": "Real Estate Qualifier",
"description": "Five-question lead qualification for real estate buyers.",
"goal": "Capture city, budget, property type, and timeline; score the lead.",
"rootNodeId": "greet",
"attempts_default": 3,
"stack_max_depth": 5,
"systemPrompt": "You are calling on behalf of Acme Realty. Be warm, professional, direct.",
"data_collection": [ /* see below */ ],
"interrupts": [ /* see below */ ],
"nodes": { /* see below */ },
"on_call_end": { /* optional */ },
"positions": { /* editor-only */ }
}
| Field | Required | Notes |
|---|---|---|
name | yes | Human-facing flow name. |
goal | yes | One-line description of what the call should accomplish. |
rootNodeId | yes | The id of the first node to execute. Must exist in nodes. |
interrupts | yes | Array (can be empty) of flow-level interrupt handlers. |
nodes | yes | An object keyed by node id (not an array). Each value is a node. |
description | no | Free-form notes for authors; ignored at runtime. |
attempts_default | no | Default attempts_max for goal nodes that don’t override. 1–10. |
stack_max_depth | no | Maximum interrupt stack depth before the call is force-ended. 1–10. |
systemPrompt | no | Flow-level persona, appended verbatim to every LLM call after role-specific prompts. |
data_collection | no | The flow’s data dictionary — informational + UI-driving. |
on_call_end | no | Single fetch fired when the engine reaches an end node. |
positions | no | Editor canvas positions, keyed by node id. The runtime ignores it. |
nodesis an object, not an array. Every node’s id is a key, and the value’sidfield must equal that key — the validator rejects mismatches.
Speech specification
Every place that “speaks” (goal prompt, speak speech, validation repair_prompt, return bridge) takes a speech spec — a discriminated union on mode:
{ "mode": "literal", "text": "Hi {{slots.contact_name}}, got a minute?" }
{ "mode": "instruction", "instruction": "Politely ask the caller about their budget; reference {{slots.city}} if it's set." }
literal is rendered verbatim with template substitution. instruction is sent to the speech-generator LLM with the engine state, which produces the line at runtime.
Templating in literal text and instructions:
| Token | Resolves to |
|---|---|
{{slots.x}} | Captured slot value, or empty string. |
{{slots.x|default}} | Slot value, or the literal default if unset. |
Node types
The engine has six node types: goal, speak, decide, tool, end, return.
Legacy flows with
"type": "fetch"are silently rewritten to"tool"at parse time. New flows should write"tool".
Goal node
The centerpiece. Speaks a prompt, listens, classifies the caller’s reply against intents, extracts slots, transitions.
"ask_budget": {
"type": "goal",
"id": "ask_budget",
"goal": "Capture the caller's budget in Rupees.",
"prompt": { "mode": "literal", "text": "Got it — {{slots.city}}. What's your budget?" },
"intents": [
{
"id": "states_budget",
"intent": "Caller states a budget number",
"extracts": { "slot": "budget_paise", "format": "currency_inr" },
"target": "ask_property_type"
},
{
"id": "wants_to_skip",
"intent": "Caller is unwilling to share a number",
"target": "polite_close"
}
],
"completion": { "kind": "slot_filled", "slot": "budget_paise" },
"validate": {
"expr": "slots.budget_paise >= 1000000",
"repair_prompt": { "mode": "literal", "text": "Just to confirm — what's your full budget?" },
"max_repair_attempts": 2
},
"on_complete": "ask_property_type",
"on_exhausted": "polite_close",
"on_ambiguous": "clarify_budget",
"attempts_max": 3,
"clarify_after": 2
}
| Field | Required | Notes |
|---|---|---|
id, type | yes | type: "goal". |
goal | yes | One-sentence description of what this node should accomplish. Used by the dispatcher. |
prompt | yes | Speech spec. |
intents | yes | Array of intent edges (≥ 1). |
on_exhausted | yes | Node id to jump to if attempts_max is exceeded without completion. |
completion | no | When to consider the node done. See Completion checks below. If omitted, defaults are inferred. |
validate | no | Node-level validation, runs after per-intent validation. |
on_complete | no | Node id to jump to once completion fires. If omitted, the engine transitions on the matched intent’s own target. |
on_ambiguous | no | Node id to jump to on low-confidence dispatch. |
attempts_max | no | Override attempts_default. 1–10. |
clarify_after | no | Insert a clarification turn after this many ambiguous attempts. |
Intent edges
Intents live inside a goal node’s intents array. Each entry is:
{
"id": "states_city",
"intent": "Caller names a city or area",
"examples": ["Bangalore please", "Whitefield", "near Indiranagar"],
"extracts": { "slot": "city", "format": "string", "normalize": "title_case" },
"validate": { "expr": "slots.city != ''", "repair_prompt": { "mode": "literal", "text": "Sorry, which city?" } },
"target": "ask_budget",
"min_confidence": 0.6
}
| Field | Required | Notes |
|---|---|---|
id | yes | Unique within the node. |
intent | yes | Natural-language description. The dispatcher uses this. |
target | yes | Node id to jump to when this intent matches. |
extracts | no | Singular extract spec (one slot per intent). |
validate | no | Per-intent validation. |
examples | no | Few-shot examples to bias the dispatcher. |
min_confidence | no | Reject the match below this. 0–1. |
Extract spec
{ "slot": "budget_paise", "format": "currency_inr", "normalize": "digits_only" }
| Field | Notes |
|---|---|
slot | Slot name. Should appear in data_collection. |
format | One of string, number, enum, phone, date, currency_inr. |
enum | Required when format: "enum". List of allowed string values. |
normalize | Optional post-processing: trim, title_case, digits_only, lowercase. |
Completion checks
{ "kind": "slot_filled", "slot": "city" }
{ "kind": "slots_filled", "slots": ["city", "budget_paise"] }
{ "kind": "any_intent_matched" }
{ "kind": "expression", "expr": "slots.city != '' && slots.budget_paise > 0" }
The four kinds are exhaustive — no others parse.
Validation spec
Used at both goalNode.validate and intentEdge.validate. The engine evaluates expr against the engine state; if it returns false, it speaks repair_prompt and re-asks.
{
"expr": "slots.budget_paise >= 1000000",
"repair_prompt": { "mode": "literal", "text": "Could you share your full budget?" },
"max_repair_attempts": 2
}
repair_prompt is a speech spec (literal or instruction), not a string. max_repair_attempts defaults to 1.
Speak node
Speaks one line and chains forward. No listening.
"thanks": {
"type": "speak",
"id": "thanks",
"speech": { "mode": "literal", "text": "Thanks {{slots.contact_name}} — we'll be in touch." },
"next": "end_call",
"writes": [
{ "op": "inc", "slot": "calls_completed_count" }
]
}
Note the field is speech, not prompt. Optional writes[] mutate slots as the node chains; supported ops:
{ "op": "set", "slot": "lead_score", "value": "warm" }
{ "op": "inc", "slot": "page_index" }
{ "op": "dec", "slot": "retries_left" }
For non-trivial computation, prefer a tool node — writes exists for the cases where an HTTP round trip per tick is absurd (paging an in-memory list).
Decide node
Deterministic routing. No LLM. No caller input. First branch whose expr evaluates true wins.
"score": {
"type": "decide",
"id": "score",
"description": "Lead-score routing.",
"branches": [
{ "id": "hot", "expr": "slots.timeline === 'immediate' && slots.budget_paise >= 50000000", "target": "hot_close" },
{ "id": "warm", "expr": "slots.timeline === '3_months'", "target": "warm_close" },
{ "id": "cold", "expr": "true", "target": "cold_close" }
]
}
Use a final expr: "true" branch as the default. A decide with no matching branch is a flow bug — the validator does not insert one for you.
Tool node
Calls an external HTTP endpoint, optionally coerces the body via LLM, captures slots from the response, routes by outcome.
"fetch_inventory": {
"type": "tool",
"id": "fetch_inventory",
"call": {
"method": "GET",
"url": "https://crm.example.com/inventory?city={{slots.city}}",
"headers": { "Authorization": "Bearer your-crm-token" },
"timeout_ms": 4000
},
"input_schema": {
"city": { "type": "string", "description": "Indian city name in English title case." }
},
"writes": [
{ "slot": "matching_units", "from": "$.results.length", "required": true,
"expect": { "expected_shape": "number" } }
],
"retry": { "max_attempts": 2, "backoff_ms": 500, "retry_on": ["network", "timeout", "5xx"] },
"on_success": "speak_inventory_count",
"on_error": {
"default": "polite_close",
"timeout": "polite_close",
"client_4xx": "polite_close",
"server_5xx": "retry_or_close"
}
}
| Field | Required | Notes |
|---|---|---|
call | yes | method (GET/POST), url, optional headers, body, timeout_ms (100–30000). URL and headers are templated. |
on_success | yes | Node id when the call succeeds and writes apply cleanly. |
on_error | yes | Object with a required default plus optional per-class targets: network, timeout, client_4xx, server_5xx, schema. |
input_schema | no | Per-parameter LLM coercion before sending the body. Adds one LLM call per fetch (~300–500ms). |
writes | no | JSONPath-driven slot writes from the response. Each accepts an optional expect.expected_shape. |
retry | no | max_attempts (0–5), backoff_ms (0–10000), retry_on subset of network/timeout/5xx. |
dry_run | no | Editor-only; let the test panel synthesize a response without hitting the network. |
End node
Terminates the call.
"end_call": { "type": "end", "id": "end_call", "reason": "qualified" }
reason is optional and free-form — surfaced in call analytics, not in caller-facing audio.
Return node
Pops one frame from the interrupt stack and resumes the previously paused node. Optionally speaks a bridge first (“Where were we — you were saying…”).
"return_to_flow": {
"type": "return",
"id": "return_to_flow",
"bridge": { "mode": "literal", "text": "Right, where were we — you were telling me about your budget." }
}
Return nodes are only valid inside an interrupt handler subtree. The validator will reject a return that isn’t reachable from any interrupt handler.
Interrupts
Flow-level intents that override the current node. Each entry produces a handler that the dispatcher checks on every turn before the active node’s intents.
"interrupts": [
{
"id": "wants_human",
"intent": "Caller asks to speak to a human",
"examples": ["transfer me", "I want a person"],
"handler": "transfer_close",
"kind": "context",
"resume_mode": "re_ask",
"max_per_node": 2,
"min_confidence": 0.7
},
{
"id": "dnc",
"intent": "Caller asks to be removed from the list",
"handler": "dnc_close",
"kind": "safety"
}
]
| Field | Required | Notes |
|---|---|---|
id, intent, handler | yes | handler is the node id to jump to. |
kind | yes | context (push a frame, return resumes) or safety (terminal — must end via an end node). |
resume_mode | no | re_ask re-runs the paused node’s prompt; continue resumes silently. Only valid for context kind. |
max_per_node | no | Cap how many times this handler can fire on the same paused node. 1–10. |
reset_count_on_new_slot | no | Reset the per-node counter when the paused node has captured a slot since the last fire. |
isolate_slot_ids | no | Slots to clear when this handler fires. |
min_confidence | no | Minimum dispatcher confidence to trigger. 0–1. |
examples | no | Few-shot examples. |
safetyinterrupts cannot useresume_mode. They must terminate via anendnode — the validator rejects safety handlers that reach areturn.
Data dictionary (data_collection)
The flow’s intended data shape. Informational + UI-driving — the engine does not enforce extraction at runtime from this dictionary; that still happens via intent.extracts at goal nodes. The validator does flag declared-but-never-extracted slots and undeclared-but-extracted ones.
"data_collection": [
{
"name": "city",
"type": "string",
"description": "Indian city or area the caller wants to buy in.",
"required": true,
"target_field": "contacts.preferred_city"
},
{ "name": "budget_paise", "type": "integer", "description": "Budget in paise." },
{ "name": "property_type", "type": "string", "description": "apartment | villa | plot." }
]
| Field | Notes |
|---|---|
name | Slot name. Same string used in extracts.slot, slots.x, completion checks. |
type | string, integer, number, boolean, array, object. |
description | Required. Used by post-call save actions and the LLM coercion layer. |
required | Optional. Surfaces incomplete fills in analytics. |
target_field | Optional. Where to write this slot when on_call_end.fetch runs. |
On call end (on_call_end)
A single optional fetch fired when the engine reaches a terminal end node. Same shape as the tool node’s call block, but with no routing — the call is hanging up regardless. Failures are logged and don’t block the hangup.
"on_call_end": {
"fetch": {
"method": "POST",
"url": "https://crm.example.com/webhook/leads",
"headers": { "Authorization": "Bearer secret" },
"body": {
"city": "{{slots.city}}",
"budget_paise": "{{slots.budget_paise}}",
"property_type": "{{slots.property_type}}",
"timeline": "{{slots.timeline}}",
"lead_score": "{{slots.lead_score}}"
},
"timeout_ms": 4000
}
}
This is the primary integration point for syncing captured data to your stack — see Webhooks for the full pattern.
Validation summary
The validator (parseFlow) runs Zod parse first, then a list of cross-node refinements:
rootNodeIdmust exist innodes.- Every node’s
idfield must equal its key in thenodesobject. - Every transition target (
on_complete,on_exhausted,on_ambiguous, intenttarget, decide branchtarget, toolon_success, toolon_error.*, speaknext, interrupthandler) must reference an existing node id. - Every
returnnode must be reachable from at least one interrupt handler. - Safety interrupts must not be able to reach a
returnnode — onlyend. - Goal nodes must have unique intent ids within their
intentsarray.
Errors are returned as a list of { path, message } records; an empty list means the flow is valid.