When to use
Use this pattern when your workflow requires both AI capabilities (extracting data from unstructured documents, classifying items with fuzzy matching, generating natural language reports) and deterministic business logic (financial formulas, eligibility checks, compliance scoring). The key requirement is auditability β you need to trace exactly how a decision was reached, which means the AI handles what humans cannot codify as rules, and business rules handle everything else. Common scenarios:- Financial product eligibility where income data comes from scanned documents but calculations must follow exact regulatory formulas
- Insurance underwriting that extracts risk factors from free-text medical reports, then applies deterministic scoring tables
- Procurement workflows that classify vendor proposals with AI, then rank them using weighted scoring matrices
Architecture
The pattern alternates between AI nodes and Script/Business Rule nodes in a pipeline:The alternating AI-then-rules structure creates a natural audit trail. For any final decision, you can trace backwards: which AI extraction produced the input values, which formula computed the result, and which AI classification influenced the filtering. This is critical for regulated industries where decisions must be explainable.
Implementation
AI vs. business rule responsibilities
The core principle is a clean separation: AI handles what cannot be expressed as deterministic rules, and business rules handle everything that can.Step 1: AI extraction
Configure a DOCUMENT_EXTRACTION node to pull structured data from unstructured documents. The node receives bank-specific rule documents as files and extracts the parameters your business rules need. (For plain-text input, TEXT_EXTRACTION works the same way β the text nodes do not accept files.)Instructions
Response Schema
Step 2: Business rules (calculations)
Add a Script node immediately after the extraction. This node takes the AI-extracted parameters and applies deterministic financial formulas. Because this is a Script node, every calculation is reproducible and auditable.Example script
Step 3: AI understanding (qualitative filtering)
Add a TEXT_UNDERSTANDING node to filter or classify products based on criteria that do not reduce to simple boolean checks β loan type preferences, sustainability features, qualitative fit.Instructions
Response Schema
Step 4: Business rules (scoring and ranking)
Add a second Script node to normalize scores and produce a final ranked list. This node combines the deterministic calculation results from Step 2 with the AI qualitative scores from Step 3 into a single weighted ranking.Example script
Step 5: AI generation (report)
Add a TEXT_GENERATION node at the end to produce a professional consultant report summarizing the analysis and recommendations.Instructions
Pipeline summary
Real-world example
The Mortgage advisor chatbot tutorial implements this pattern in its product recommendation handler. When a user asks for mortgage product recommendations, the workflow:- Extracts financial parameters from each bankβs rule documents
- Computes eligibility using exact financial formulas (PMT, DTI)
- Filters the product catalog using AI-driven qualitative matching
- Ranks the remaining products with a deterministic scoring matrix
- Generates a personalized consultant report
Variations
Human-in-the-loop
Add approval gates after AI steps to let a human reviewer verify the AI output before it feeds into business rules. This is useful during initial deployment or in high-stakes decisions.Confidence-weighted rules
Instead of treating AI output as binary (pass/fail), feed the AI confidence score into the business rules as a weight. Low-confidence AI extractions trigger stricter thresholds or flag the result for manual review.Multi-source comparison
Extend the pattern to process documents from multiple banks or sources in parallel (using the Fan-out extraction pattern), then merge the results into a single comparison matrix before the scoring step. This is the approach used in the mortgage advisor for comparing products across 7 banks.Related resources
AI patterns overview
All available patterns and how to combine them
Fan-out extraction
Parallel document classification and extraction
Mortgage advisor tutorial
Full implementation of hybrid AI + business rules
AI node types
Reference for DOCUMENT_EXTRACTION, TEXT_UNDERSTANDING, and TEXT_GENERATION

