Flow schema
Reference

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 */ }
}
FieldRequiredNotes
nameyesHuman-facing flow name.
goalyesOne-line description of what the call should accomplish.
rootNodeIdyesThe id of the first node to execute. Must exist in nodes.
interruptsyesArray (can be empty) of flow-level interrupt handlers.
nodesyesAn object keyed by node id (not an array). Each value is a node.
descriptionnoFree-form notes for authors; ignored at runtime.
attempts_defaultnoDefault attempts_max for goal nodes that don’t override. 1–10.
stack_max_depthnoMaximum interrupt stack depth before the call is force-ended. 1–10.
systemPromptnoFlow-level persona, appended verbatim to every LLM call after role-specific prompts.
data_collectionnoThe flow’s data dictionary — informational + UI-driving.
on_call_endnoSingle fetch fired when the engine reaches an end node.
positionsnoEditor canvas positions, keyed by node id. The runtime ignores it.

nodes is an object, not an array. Every node’s id is a key, and the value’s id field 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:

TokenResolves 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
}
FieldRequiredNotes
id, typeyestype: "goal".
goalyesOne-sentence description of what this node should accomplish. Used by the dispatcher.
promptyesSpeech spec.
intentsyesArray of intent edges (≥ 1).
on_exhaustedyesNode id to jump to if attempts_max is exceeded without completion.
completionnoWhen to consider the node done. See Completion checks below. If omitted, defaults are inferred.
validatenoNode-level validation, runs after per-intent validation.
on_completenoNode id to jump to once completion fires. If omitted, the engine transitions on the matched intent’s own target.
on_ambiguousnoNode id to jump to on low-confidence dispatch.
attempts_maxnoOverride attempts_default. 1–10.
clarify_afternoInsert 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
}
FieldRequiredNotes
idyesUnique within the node.
intentyesNatural-language description. The dispatcher uses this.
targetyesNode id to jump to when this intent matches.
extractsnoSingular extract spec (one slot per intent).
validatenoPer-intent validation.
examplesnoFew-shot examples to bias the dispatcher.
min_confidencenoReject the match below this. 0–1.

Extract spec

{ "slot": "budget_paise", "format": "currency_inr", "normalize": "digits_only" }
FieldNotes
slotSlot name. Should appear in data_collection.
formatOne of string, number, enum, phone, date, currency_inr.
enumRequired when format: "enum". List of allowed string values.
normalizeOptional 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"
  }
}
FieldRequiredNotes
callyesmethod (GET/POST), url, optional headers, body, timeout_ms (100–30000). URL and headers are templated.
on_successyesNode id when the call succeeds and writes apply cleanly.
on_erroryesObject with a required default plus optional per-class targets: network, timeout, client_4xx, server_5xx, schema.
input_schemanoPer-parameter LLM coercion before sending the body. Adds one LLM call per fetch (~300–500ms).
writesnoJSONPath-driven slot writes from the response. Each accepts an optional expect.expected_shape.
retrynomax_attempts (0–5), backoff_ms (0–10000), retry_on subset of network/timeout/5xx.
dry_runnoEditor-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"
  }
]
FieldRequiredNotes
id, intent, handleryeshandler is the node id to jump to.
kindyescontext (push a frame, return resumes) or safety (terminal — must end via an end node).
resume_modenore_ask re-runs the paused node’s prompt; continue resumes silently. Only valid for context kind.
max_per_nodenoCap how many times this handler can fire on the same paused node. 1–10.
reset_count_on_new_slotnoReset the per-node counter when the paused node has captured a slot since the last fire.
isolate_slot_idsnoSlots to clear when this handler fires.
min_confidencenoMinimum dispatcher confidence to trigger. 0–1.
examplesnoFew-shot examples.

safety interrupts cannot use resume_mode. They must terminate via an end node — the validator rejects safety handlers that reach a return.

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." }
]
FieldNotes
nameSlot name. Same string used in extracts.slot, slots.x, completion checks.
typestring, integer, number, boolean, array, object.
descriptionRequired. Used by post-call save actions and the LLM coercion layer.
requiredOptional. Surfaces incomplete fills in analytics.
target_fieldOptional. 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:

  • rootNodeId must exist in nodes.
  • Every node’s id field must equal its key in the nodes object.
  • Every transition target (on_complete, on_exhausted, on_ambiguous, intent target, decide branch target, tool on_success, tool on_error.*, speak next, interrupt handler) must reference an existing node id.
  • Every return node must be reachable from at least one interrupt handler.
  • Safety interrupts must not be able to reach a return node — only end.
  • Goal nodes must have unique intent ids within their intents array.

Errors are returned as a list of { path, message } records; an empty list means the flow is valid.