Schematex

Decision tree diagram

About decision trees

A decision tree is a branching diagram that represents a sequence of choices and their consequences as a rooted tree: each internal node is a question or decision, each edge is an answer or action, and each leaf is an outcome. The format appears across three quite different practices — troubleshooting flowcharts and clinical decision rules (taxonomy trees), risk and investment analysis using expected value (decision analysis), and machine learning model inspection (classifier trees). Despite surface differences all three share the same tree structure, which is why Schematex encodes them under one keyword with a mode selector.

Schematex decision trees cover: (1) taxonomy mode — the yes/no question flows used in medical triage (Turing 1937 lineage; now standard in clinical decision support), (2) decision analysis mode — the expected-value rollback method developed in management science (Raiffa & Schlaifer, 1961), and (3) ML mode — the CART split/leaf format used to visualize scikit-learn and similar trained classifiers (Breiman et al., 1984).

decisiontree·§
↘ preview
100%
Customer Support Triage Decision tree (taxonomy mode) with 9 nodes and 8 edges Customer Support Triage yes no yes no yes no yes no Is the service completely down? Outage confirmed on status page? Follow incident protocol — page Check monitoring — open severity-1 ticket Is the issue affecting billing? Escalate to billing team — SLA breach risk Can user reproduce consistently? Collect HAR trace — file bug report Ask for screenshot — watch for recurrence
UTF-8 · LF · 13 lines · 550 chars✓ parsed·4.9 ms·7.1 KB SVG

1. Your first decision tree

The smallest useful decision tree: a root question with two branches.

decisiontree·§
↘ preview
100%
Laptop troubleshoot Decision tree (taxonomy mode) with 5 nodes and 4 edges Laptop troubleshoot yes no yes no Does it power on? Check display — connect external Is the charger light on? Hold power button 10 s — try again Check outlet and charging cable
UTF-8 · LF · 8 lines · 266 chars✓ parsed·0.9 ms·4.8 KB SVG

Four rules cover 80% of usage:

  1. Start with decisiontree, optionally with :mode and a quoted title.
  2. Each question node uses question "text" (or shorthand q "text").
  3. Each answer/leaf uses answer "text" (or a "text" or leaf "text").
  4. Branch labels — yes:, no:, or a custom label "X": — prefix the child node on the same line.

Indentation controls nesting: each level adds 2 spaces. The parser computes parent-child relationships from indent depth.

Comments must start with # or // on their own line.


2. Modes

The mode is set in the header line:

HeaderModeUsed for
decisiontreetaxonomyYes/no question flows, troubleshooting guides, clinical decision support
decisiontree:decision (or decisiontree:da)decision analysisInvestment decisions, risk analysis, expected value calculation
decisiontree:influence (or mode: influence)influence diagramCompact DAG view of a decision problem — structure before unrolling to a tree
decisiontree:mlmachine learningVisualizing trained CART classifiers (scikit-learn, XGBoost, etc.)

Default direction is top-down for taxonomy and ML, left-right for decision analysis.


3. Taxonomy mode

Best for: troubleshooting guides, FAQs, clinical protocols, product recommendation flows.

Node keywords

KeywordAliasesMeaning
question "…"q "…"Internal node — a question with children
answer "…"a "…", leaf "…"Leaf node — a terminal outcome

Branch labels

SyntaxMeaning
yes: question "…"Branch labeled "yes"
no: answer "…"Branch labeled "no"
label "Custom text": answer "…"Branch with any custom label

Custom labels let you go beyond yes/no for multi-way decisions from one question.

decisiontree·§
↘ preview
100%
Triage — chest pain onset Decision tree (taxonomy mode) with 9 nodes and 8 edges Triage — chest pain onset yes no yes no yes no yes no Onset sudden? ECG changes present? ACS protocol — cardiology consult D-dimer elevated? PE workup — CT pulmonary angiography Aortic dissection — CT angiography Pain reproducible on palpation? Musculoskeletal — NSAIDs, follow-up PCP GI / anxiety — further history
UTF-8 · LF · 12 lines · 408 chars✓ parsed·0.9 ms·6.9 KB SVG
decisiontree·§
↘ preview
100%
Pain level triage Decision tree (taxonomy mode) with 5 nodes and 4 edges Pain level triage Severe (8-10) Moderate (4-7) Mild (1-3) None Reported pain level? Emergency — send to ER immediately Urgent care — within 2 hours Schedule next available — OTC care Monitor — patient may be post-medication
UTF-8 · LF · 8 lines · 331 chars✓ parsed·0.6 ms·4.8 KB SVG

4. Decision analysis mode

Best for: investment decisions, build-vs-buy analysis, risk-weighted strategy evaluation.

Node keywords

KeywordAliasesMeaning
decision "…"Decision node — the actor chooses a branch
chance "…"Chance node — an uncertain outcome
end "…"outcome "…"Terminal node — final payoff

Branch keywords

KeywordMeaning
choice "label"Names the incoming branch from a decision node
prob NSets the probability (0–1) on the incoming branch from a chance node

Payoff attribute

payoff=N on any node sets the payoff value. On end / outcome nodes it defines the terminal value. The parser runs expected-value rollback automatically: each chance node's EV is the probability-weighted sum of its children's EVs; each decision node's EV is the maximum child EV, and the optimal branch is flagged.

Constraint: probabilities on all direct children of a chance node must sum to 1.0 (±0.01). The parser throws a DTreeParseError if they do not.

decisiontree:decision·§
↘ preview
100%
Cloud vendor selection Decision tree (decision mode) with 8 nodes and 7 edges Cloud vendor selection Build in-house Managed SaaS vendor Hybrid approach p=60% p=40% p=50% p=50% Which vendor? EV=600,000 Project outcome EV=600,000 On-time delivery $900,000 Over budget / delayed $150,000 Predictable cost $500,000 Integration complexity EV=500,000 Smooth integration $700,000 Integration rework $300,000
UTF-8 · LF · 14 lines · 480 chars✓ parsed·1.9 ms·7.1 KB SVG

5. Influence diagram mode

Best for: framing a decision problem compactly before you unroll it. Where decision-analysis mode draws every branch of every outcome as an explicit tree, an influence diagram (Howard & Matheson, 1981) draws the same problem as a directed acyclic graph (DAG) of variables and the dependencies between them — one node per decision, uncertainty, and objective, no matter how many states each can take. It is the diagram decision analysts reach for first, because it shows the structure (what informs what, what affects the payoff) without the combinatorial blow-up of a tree.

This mode is structural, not computational. Unlike decision-analysis mode, it does not solve for expected value — the compact graph deliberately omits the probability and payoff tables that an EV rollback would need. Use it to communicate and validate the shape of the problem; use decision-analysis mode (section 4) when you want the numbers folded back.

Header forms

Two equivalent ways to select the mode:

decisiontree:influence "Oil Wildcatter"

or, as a directive on its own line after the header:

decisiontree "Market Entry"
  mode: influence

Node keywords

Each node is declared as kind Id "label" — an id (used to wire arcs) followed by a quoted display label.

KeywordShapeMeaning
decision Id "…"rectangleA choice the decision-maker controls
chance Id "…"ovalAn uncertain variable (a state of the world)
value Id "…"octagonThe objective / payoff being optimized

The shapes follow the standard influence-diagram convention: decisions are rectangles, uncertainties are ovals, and the value node is an octagon. Add utility=N to a value node to annotate the payoff it represents (value Profit "Net profit" utility=42).

Arcs and their semantics

Arcs are written Source -> Target on their own lines, by node id. An arc's meaning is read from its destination, exactly as in the published standard:

Arc into a…MeaningDrawn as
decisionInformational — this is known before the decision is madedashed line
chanceRelevance / conditioning — the source conditions this uncertaintysolid line
valueFunctional — the source is an argument of the payoff functionsolid line

The dashed informational arc is the one to watch: Seismic -> Drill means "the seismic test result is observed before choosing whether to drill," which is precisely what makes the decision worth modelling.

Validation rules

  • The graph must be acyclic — a cycle (e.g. A -> B and B -> A) is rejected.
  • At least one value node is required; an influence diagram with no objective is not a decision problem.
  • Arcs reference node ids that must be declared.

Examples

The Oil Wildcatter — the canonical teaching problem. The seismic test result is observed before the drill decision (dashed informational arc Seismic -> Drill), the test is relevant to whether oil is actually present (Seismic -> Oil), and both the oil state and the drill choice feed the profit (Oil -> Profit, Drill -> Profit).

decisiontree:influence·§
↘ preview
100%
Oil Wildcatter Influence diagram with 4 nodes and 4 arcs Oil Wildcatter Seismic test Drill? Oil present Net profit U=42
UTF-8 · LF · 10 lines · 234 chars✓ parsed·2.6 ms·3.1 KB SVG

A market-entry decision using the mode: influence directive form. Demand is observed before entering (Demand -> Enter, informational/dashed) and also drives profit directly, while the competitor's response feeds only the payoff.

decisiontree·§
↘ preview
100%
Market Entry Influence diagram with 4 nodes and 4 arcs Market Entry Market demand Competitor response Enter market? Profit U=120
UTF-8 · LF · 11 lines · 249 chars✓ parsed·0.7 ms·3.1 KB SVG

6. Machine learning mode

Best for: explaining trained CART classifiers, model transparency reports, feature importance analysis.

Node keywords

KeywordMeaning
split "…"Internal split node — contains a feature test
leaf "…"Leaf node — class or regression value

Branch prefixes

true and false prefix child nodes to mark which branch each child represents.

Properties (key=value, no colon, no quotes around values)

PropertyApplies toMeaning
feature=namesplitFeature name used at the split
op="<="splitComparison operator (quote if contains special chars)
threshold=5.9splitSplit threshold value
samples=150split, leafSample count at this node
gini=0.5split, leafGini impurity
entropy=0.5split, leafEntropy impurity
mse=0.3split, leafMean squared error (regression)
gain=0.2split, leafInformation gain
class=nameleafPredicted class name
value=50leafSample count; use value=[50,30,20] for class distribution
decisiontree:ml·§
↘ preview
100%
Iris classification (CART) Decision tree (ml mode) with 5 nodes and 4 edges Iris classification (CART) True False True False petal_length 2.45 gini = 0.67 samples = 150 Setosa gini = 0 value = 50 class = Iris-setosa petal_width 1.75 gini = 0.50 samples = 100 Versicolor gini = 0 value = 50 class = Iris-versicolor Virginica gini = 0 value = 50 class = Iris-virginica
UTF-8 · LF · 10 lines · 465 chars✓ parsed·1.4 ms·5.9 KB SVG

7. Config options

Config lines appear between the header and the first node. Each is key: value (colon, no config keyword).

Shared config (all modes)

KeyValuesDefaultEffect
direction:top-down, left-righttop-down (taxonomy/ML), left-right (decision)Layout direction
edgeStyle: (or edge-style:)diagonal, orthogonal, bracketmode-dependentEdge drawing style

Taxonomy config

KeyValuesDefaultEffect
branchLabels: (or branch-labels:)boolean, relationbooleanBranch label style

Decision analysis config

KeyValuesDefaultEffect
branchLength: (or branch-length:)probabilityoffScale branch length proportional to probability

ML config

KeyValuesDefaultEffect
impurity:gini, entropy, mse, gainginiImpurity metric shown on nodes
classes:comma-separated listClass label names for display
decisiontree:ml "Loan classifier"
direction: top-down
impurity: gini
classes: Approved, Denied, Review

8. Labels & comments

  • Diagram title: decisiontree "Title" — the quoted string after the header keyword.
  • Node label: the quoted string immediately after the node keyword — question "Is the fee waived?".
  • Branch label: yes:, no:, or label "Custom": before the child node — on the same line as the child.
  • Payoff: payoff=250000 at the end of a decision/end node line.
  • ML properties: key=value tokens after the node's label string (no […] brackets, no colons).
  • Comments: # or // at the start of a line (after optional leading whitespace). Only full-line comments are supported — inline trailing comments are not.

9. Reserved words & escaping

Reserved node keywords: decision, chance, end, outcome, choice, prob, split, leaf, question, q, answer, a.

Reserved branch prefixes: yes:, no:, true, false, label.

Reserved header forms: decisiontree, decisiontree:decision, decisiontree:da, decisiontree:ml.

Strings with spaces must be double-quoted: question "Annual revenue > $1M?". Node labels, branch labels from label "…": syntax, and the diagram title all require double quotes.

Reserved tokenContextNotes
yes: / no:Line start in taxonomyCannot be used as a label — use label "yes": if you need literal text "yes"
true / falseLine start in ML modeCannot be a node label
choiceLine start in decision modeActs as branch wrapper, not a node
probLine start in decision modeMust be followed by a number

10. Common mistakes

You wroteParser saysFix
yes: "Approve" (no node keyword)DTreeParseError: Missing taxonomy node kindyes: answer "Approve"
Probabilities on chance children summing to 0.8DTreeParseError: probabilities do not sum to 1.0Adjust so all prob values sum to exactly 1.0 (±0.01)
question "text" with a child at the same indent levelChild not parsed as a child — becomes a siblingIndent children by 2 more spaces than the parent
config direction = top-down (using config keyword)config is a fishbone keyword — not recognized hereUse direction: top-down (no config prefix)
feature = petal_length (spaces around =)Parsed as separate tokens; property not recognizedNo spaces: feature=petal_length
[payoff: 500000] bracket syntaxNot recognized — parser ignores brackets for payoffUse payoff=500000 (no brackets, no spaces around =)
decisiontree:taxonomyDTreeParseError: Invalid headerUse decisiontree (no mode suffix for taxonomy)

11. Grammar (EBNF)

document       = header ( config-line )* node

header         = "decisiontree" ( ":" mode )? ( WS quoted-string )? NEWLINE
mode           = "decision" | "da" | "ml"
                 // omitted → taxonomy

config-line    = config-key ":" WS config-value NEWLINE
config-key     = "direction" | "edgeStyle" | "edge-style"
               | "branchLabels" | "branch-labels"
               | "branchLength" | "branch-length"
               | "impurity" | "classes"

// ── Taxonomy mode ──────────────────────────────
node           = ( branch-prefix WS )? tax-node ( WS "[" tax-attrs "]" )? NEWLINE
                   INDENT child-node*
tax-node       = ( "question" | "q" ) WS quoted-string
               | ( "answer" | "a" | "leaf" ) WS quoted-string
branch-prefix  = "yes:" | "no:" | "label" WS quoted-string ":"

// ── Decision-analysis mode ─────────────────────
da-node        = "decision" WS quoted-string NEWLINE INDENT da-child+
               | "chance" WS quoted-string NEWLINE INDENT da-prob-child+
               | ( "end" | "outcome" ) WS quoted-string ( WS "payoff=" number )? NEWLINE
da-child       = "choice" WS quoted-string NEWLINE INDENT da-node
da-prob-child  = "prob" WS number WS da-node    // prob, value, and child all on one line

// ── ML mode ───────────────────────────────────
ml-node        = ( "true" | "false" )? ml-kind WS quoted-string ml-prop* NEWLINE
                   INDENT ml-child*
                 // "true"/"false" and ml-kind must be on the same line
ml-kind        = "split" | "leaf"
ml-prop        = WS key "=" value     // no spaces around "="

comment        = ( "#" | "//" ) any NEWLINE
quoted-string  = '"' any-char-but-quote* '"'

Authoritative source: src/diagrams/decisiontree/parser.ts. If this diverges from the parser, the parser wins — please open an issue.


12. Standard compliance

Schematex decision trees cover four established conventions:

Taxonomy mode follows the question/answer flowchart conventions common in clinical decision support systems (Arden Syntax lineage) and ISO 9001 troubleshooting procedures.

Decision analysis mode follows the expected-value rollback method from management science: decision nodes (square, actor chooses), chance nodes (circle, probabilistic), terminal nodes with payoffs. EV is computed automatically via backward induction (Raiffa & Schlaifer, 1961).

Influence diagram mode follows the Howard & Matheson (1981) convention: decision (rectangle), chance (oval), and value (octagon) nodes wired as an acyclic graph, with arc meaning read from the destination (informational into decisions, drawn dashed; relevance into chance; functional into value). It is a structural diagram — it does not solve for EV.

ML mode follows the CART (Classification and Regression Trees) split/leaf notation (Breiman et al., 1984) compatible with scikit-learn's export_text and plot_tree output.

What is implemented today:

  • ✅ All four modes: taxonomy, decision analysis, influence diagram, ML
  • ✅ Taxonomy: question/q, answer/a/leaf, yes:, no:, label "X": branch labels
  • ✅ Decision: decision, chance, end/outcome, choice, prob, payoff=N, automatic EV rollback
  • ✅ Influence: decision/chance/value nodes, utility=N, Source -> Target arcs, destination-derived arc semantics, dashed informational arcs, acyclicity + value-node validation
  • ✅ ML: split, leaf, true/false branch prefixes, feature=, threshold=, gini=, entropy=, mse=, class=, value=
  • ✅ Config: direction:, edgeStyle:, impurity:, classes:, branchLabels:, branchLength:, mode:
  • ⏳ Probability-weighted branch length rendering (branchLength: probability parsed but not yet applied visually)
  • ⏳ Sensitivity analysis overlays (tornado chart-style annotations on decision trees)
  • ⏳ Forest / ensemble view — multiple trees side-by-side

References:

  • Raiffa, H. & Schlaifer, R. (1961). Applied Statistical Decision Theory. Harvard Business School.
  • Howard, R. A. & Matheson, J. E. (1981/2005). Influence Diagrams. Decision Analysis 2(3).
  • Breiman, L. et al. (1984). Classification and Regression Trees. Wadsworth.
  • Wikipedia — Decision tree · Influence diagram · Decision tree learning

13. Roadmap

Planned — not yet parseable. Do not use these in generated DSL today; the parser will reject or ignore them.

  • branchLength: probability visual rendering — the config key parses but the layout engine does not yet scale branch lengths by probability.
  • Sensitivity / tornado analysissensitivity: block annotating which prob values most affect the final EV.
  • Export annotations — structured table output (decision matrix) alongside the diagram SVG.
  • Forest viewforest keyword wrapping multiple decisiontree blocks in a side-by-side comparison layout.
  • Collapse/expand interactive markerscollapsed: true on a node to render a triangle placeholder for deep subtrees.

Track in the GitHub issues if you need any of these sooner.


Ready-to-use scenarios from the examples gallery:

decisiontree·§ Clinical/support decision flow
Customer Support Triage Decision tree (taxonomy mode) with 9 nodes and 8 edges Customer Support Triage yes no yes no yes no yes no Is the service completely down? Outage confirmed on status page? Follow incident protocol — page Check monitoring — open severity-1 ticket Is the issue affecting billing? Escalate to billing team — SLA breach risk Can user reproduce consistently? Collect HAR trace — file bug report Ask for screenshot — watch for recurrence
Support ticket triage
Taxonomy-mode decision tree for front-line support — routes an incoming ticket through outage, billing, and reproducibility gates to the right team.
saas
decisiontree·§ Raiffa & Schlaifer (1961)
Platform Vendor Choice Decision tree (decision mode) with 8 nodes and 7 edges Platform Vendor Choice Build in-house Managed SaaS vendor Hybrid approach p=60% p=40% p=50% p=50% Which vendor? EV=600,000 Project outcome EV=600,000 On-time delivery $900,000 Over budget / delayed $150,000 Predictable cost $500,000 Integration complexity EV=500,000 Smooth integration $700,000 Integration rework $300,000
Investment decision analysis
Decision-analysis tree evaluating build-vs-buy vs hybrid for a platform choice — chance nodes with probabilities, automatic expected-value rollback.
strategy