AI for Small Business
Aware · M40 · lesson 40 of 93 · queued
Preview — browse every lesson free. Enroll to mark lessons complete, open partner links and save your progress. Login & enroll →
📖
in this lesson

Conditional Logic and Decision Trees

10 min

The workflows that create business value don't execute the same path every time. When processing a customer support ticket, if the AI detects a safety concern, you route to human review immediately. If it's a routine product question, you auto-respond. If the intent is unclear, you ask for clarification. Different inputs, different paths.

This is where conditional logic and decision trees become essential. They're the mechanism that lets workflows respond intelligently to AI analysis results, turning analysis into action.

By the end of this lecture, you'll understand how to design decision points that keep logic maintainable, how to avoid common pitfalls in conditional routing, and how to structure complex decision trees that scale as business rules evolve.

The Fundamental Pattern: Analysis, Decision, Action

The architecture is deceptively simple and worth memorizing: workflow step -> AI analysis (generates decision data) -> decision point (routes based on that data) -> different execution paths -> outcome.

The key insight: separation of concerns. The AI step's job is pure analysis: "What is the sentiment? What entity did the customer mention? What is the intent?" The decision point's job is pure routing: "If sentiment is negative, do X. If positive, do Y." Action steps implement what comes next.

This separation makes workflows maintainable. If business rules change ("We now escalate anything with confidence below 75%"), you update the decision point. The AI step doesn't change. If the AI model improves and returns more accurate sentiment, decision routing still works the same way.

Golden Rule

Don't implement business logic in decision points. Implement analysis in AI steps, and pure routing in decision points. If you find yourself writing complex conditional logic in a decision point, move it to an AI step instead.

Designing Decision Points: Simple Rules

A decision point should answer exactly one question and produce 2-4 possible outcomes. Here are common patterns.

Binary Decisions (Yes/No)

Example: "Is the user requesting a refund?" Yes -> escalate. No -> continue processing.

These are the simplest decision points. A single condition determines the path. The AI step before the decision point needs to provide a clear yes/no (or confidence score above/below threshold), and the decision point checks that value.

Binary decisions are low risk because there's no ambiguity. You're not splitting users across multiple paths based on a complex rule. Either they meet the criteria or they don't.

Multi-Way Decisions (3-4 Outcomes)

Example: Sentiment analysis returns negative, neutral, or positive. Route to escalation, queue for review, or auto-respond respectively.

These are common and acceptable. The AI step returns a discrete classification, and the decision point routes based on it. Three to four outcomes is reasonable. Beyond that, you're creating too many paths to test and maintain.

Threshold Decisions

Example: AI returns a confidence score from 0-100. If confidence greater than 80%, proceed. If confidence less than 50%, escalate to human. If confidence between 50-80%, queue for review.

These decisions use numeric ranges. They're useful but require careful threshold selection. If your thresholds change frequently based on new data, embed the threshold values in configuration files, not hardcoded in the workflow. This lets you adjust thresholds without redeploying code.

Structuring Complex Decision Trees

As workflows become sophisticated, you might have multiple sequential decision points. "First, check sentiment. If negative, check whether it's safety-related. If safety-related, check urgency level."

Each decision should be at a decision point, not nested in the AI step. Why? Because each decision might need its own retry logic, each might log its outcome, each might be configurable. Separating them keeps the workflow readable.

However, avoid decision trees that branch too aggressively. Two decision points with 2 outcomes each = 4 paths. Three decision points = 8 paths. Four decision points = 16 paths. You need to test all these paths. Beyond 3-4 decision points in sequence, the test matrix becomes unwieldy.

Decision Tree Complexity

If you have more than 3-4 sequential decision points, you have two options: (1) Merge decisions into a single AI step that returns a more nuanced classification, or (2) Consider whether you're trying to solve too much in one workflow. Sometimes it's better to have separate workflows for different use cases.

Decision Points: Context and State

A decision point doesn't just examine the output of the previous step. It can examine any state in the workflow: user preferences, business rules, configuration values, even historical data about this specific user or request.

Example: "If sentiment is negative AND this customer has VIP status AND they've complained fewer than 3 times this month, route to premium support. Otherwise, route to standard queue."

This is valid, but ensure all required context is loaded into workflow state before the decision point. Don't have the decision point make database queries to fetch user preferences. Load that data in an earlier setup step. This keeps decision points fast and reduces external dependencies.

User Preferences and Personalization

Many workflows should behave differently for different users. Store user preferences in workflow state from the start: "This user prefers email updates, not SMS. This user is in the EU so follows GDPR." Decision points can check these preferences and route accordingly.

A/B Testing and Experimentation

Decision points are perfect hooks for A/B tests. Instead of: "If sentiment is negative, escalate," use: "If sentiment is negative, assign to escalation path A (old process) or path B (new process) based on user's experiment assignment."

This lets you test workflow changes safely: keep the old workflow for some users while a subset tries the new approach. Compare outcomes and decide whether to roll out the change.

Managing Maintenance as Rules Evolve

Business rules change. Thresholds shift. New conditions emerge. Your workflow decision logic needs to evolve with them without requiring constant code changes.

Configuration-Driven Routing

Instead of hardcoding decision logic, store it in configuration files or databases. A rules engine reads config at runtime and makes decisions. This is more complex to set up initially but pays dividends when rules change frequently.

Example: Instead of decision code like "if confidence > 0.8," store rules as: {"confidence_threshold": 0.8, "if_below": "escalate", "if_above": "proceed"}. Update the JSON, redeploy config, rules change immediately without code changes.

Decision Point Versioning

Sometimes you need to update decision logic but existing workflows are in-flight with the old logic. Versioning prevents issues. Store the decision logic version with each workflow execution. If you change thresholds, only new executions use the new thresholds. In-flight executions complete with old logic.

Audit and Transparency

Log every decision point result. "User X reached decision point Y. State was Z. Decision: route to path W. Timestamp." This creates an audit trail of why executions went particular directions. When something surprising happens, you can trace back and see the decisions that caused it.

Decision Pattern Complexity Use Case Maintenance Burden Testing Difficulty
Binary (Yes/No) Very Low Simple gates: escalate or proceed, approve or reject Minimal 2 paths to test
Multi-Category (3-4 options) Low Classification: sentiment (negative/neutral/positive), intent categories Low 3-4 paths to test
Threshold-Based Low-Medium Confidence scores, priority levels, numeric metrics Medium (threshold tuning) Multiple paths per threshold
Multi-Condition Logic Medium Several criteria must be checked (sentiment AND urgency AND status) Medium Combinatorial explosion
Sequential Decision Tree (3+ points) High Complex routing with many paths; specialized business logic High (many paths to maintain) Difficult (exponential paths)

Common Decision-Making Mistakes

Treating Confidence Scores as Certainty

Mistake: AI returns confidence=0.92 for a classification, so you treat it as certain. But 92% confidence means 8% chance of being wrong. If your decision has high stakes, that's risky. Solution: acknowledge uncertainty in your routing. "If confidence > 95%, auto-proceed. If 75-95%, queue for review. If < 75%, escalate."

Decision Points with Too Many Branches

Mistake: A single decision point with 10+ possible outcomes. Testing all paths becomes impossible. Solution: If you have that many outcomes, you probably need multiple sequential decision points or a more sophisticated AI step that combines factors into a single classification.

Unmaintainable if-else Chains

Mistake: Decision logic that looks like:

if user.status == premium and sentiment == negative and urgency == high and not user.on_vacation and request.category in [refund, billing] and confidence > 0.9 then route X else if...

This is unmaintainable. Solution: Separate this into logical decision points, or use a rules engine where business rules are expressed declaratively.

Silent Failures When Conditions Don't Match

Mistake: A decision point checks three conditions. Two are met, but the third is null/missing. The decision point silently treats missing as false, routing incorrectly. Solution: Validate state before decision points. If a required field is missing, explicitly handle it as an error case, not as false.

Testing Decision Points

Create synthetic test data for each branch. For a sentiment decision, test negative, neutral, and positive inputs. For a threshold decision, test values just below threshold, at threshold, and well above. Test edge cases: missing data, boundary values, unusual combinations. Document which test cases cover which decision paths.

Context-Aware Routing: Personalization at Scale

The most powerful workflows make decisions based not just on current analysis, but on accumulated context: user history, preferences, business rules specific to that user, seasonal factors, A/B test assignments.

Example: Same sentiment analysis input (negative), but routing differs based on: user tier (VIP -> premium support), open issues count (3+ open -> offer self-service resources), recent contact history (contacted us 5 times today -> escalate immediately), contract type (enterprise -> dedicated rep, SMB -> chatbot).

This requires rich state. Load relevant context early: user profile, account status, interaction history, preferences. Then decision points can be sophisticated without adding complexity to the decision point code itself.

Key Takeaway

Conditional logic is the intelligence mechanism that transforms AI analysis into action. Design decision points with a single purpose, 2-4 outcomes maximum, and pure routing logic (no business logic inside the decision point). Separate analysis (in AI steps) from routing (in decision points) from action (in downstream steps). Keep decision trees shallow (3-4 sequential points max) and manageable (test all paths). Use configuration and rules engines to manage evolving business logic without code changes. Context-aware routing that leverages accumulated state creates personalized workflows at scale.

What You'll Learn Next

Now that you understand how to route workflows intelligently, the next lecture focuses on multi-agent systems where different AI models work together. In , you'll learn how to orchestrate multiple specialized agents, manage inter-agent communication, and handle distributed decision-making across AI models.

Frequently Asked Questions

What's the difference between decision points and business logic?

Business logic (rules and algorithms) belongs in AI steps—have your AI tool analyze sentiment, extract entities, or classify content. Decision points simply route based on business logic results. A decision point checks: "Is sentiment negative?" If yes, route to step A. If no, route to step B. The decision point itself contains no complexity, just routing.

How do you prevent workflow routing logic from becoming unmaintainable?

Keep decision logic simple. A single decision point should evaluate one piece of state and produce 2-4 outcomes maximum. For complex logic, implement it in the AI step before the decision point. Use rule engines or configuration files for business rules that change frequently. Version control all routing logic and review changes carefully.

What's the best way to handle dynamic routing based on user preferences?

Store user preferences in your state context at workflow start. Decision points can access these preferences and route accordingly. For frequently-changing preferences, load them from a configuration service. Document the preference schema clearly so everyone knows what values trigger what behaviors.

How do you test conditional logic in workflows?

Test each decision point independently with synthetic test data. Create test cases for each branch: what happens when a negative sentiment is detected, when a high-confidence classification occurs, when edge cases appear (missing data, ambiguous results). Use workflow simulation tools to run executions without calling production AI APIs.

Can workflows have multiple decision points creating complex paths?

Yes, but with caution. Multiple decision points create exponentially more execution paths. For example, two decision points with 2 branches each create 4 possible paths; three decision points create 8 paths. Test all paths. Document the logic with flowcharts. Consider simplifying if the number of paths becomes unmanageable.