
Boolean and Rule-Based Paths
Combining deterministic rules with AI.
Boolean and Rule-Based Paths
Not every decision needs an LLM.
Rule-Based Priority
Always check deterministic rules before calling an LLM.
def router_node(state):
user = state.get("user")
# 1. Deterministic Rule
if not user.is_authenticated:
return "login_flow"
# 2. Deterministic Check
if state["requests_count"] > 100:
return "rate_limit_error"
# 3. Only if rules pass, call LLM
return "ai_router"
Why?
- Cost:
if Truecosts $0.00. GPT-4 costs $0.03. - Security: You don't want an LLM to "hallucinate" that a user is logged in. Hardcode the check.