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
Without this pattern, you face two bad options: pure AI (fast but opaque, hard to audit) or pure rules (auditable but unable to handle unstructured input).
The pattern alternates between AI nodes and Script/Business Rule nodes in a pipeline:
Documents / unstructured input | vAI EXTRACTION(extract structured data from documents) | vBUSINESS RULES(deterministic calculations, formulas) | vAI UNDERSTANDING(fuzzy matching, qualitative filtering) | vBUSINESS RULES(scoring, ranking, normalization) | vAI GENERATION(produce human-readable report) | vFinal output (structured data + report)
Each AI node produces structured JSON output that feeds directly into the next Script node. Each Script node produces deterministic, reproducible results that feed into the next AI node. This alternating structure means every decision point is either fully deterministic (and logged) or clearly marked as AI-assisted (with the prompt and response recorded).
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.
Configure a TEXT_EXTRACTION node to pull structured data from unstructured documents. The node receives bank-specific rule documents and extracts the parameters your business rules need.
Extract the following financial parameters from the provided bank rule document:- income_weights: object mapping income source types to their weight factors- debt_factors: object mapping debt types to their monthly burden factors- max_ltv: maximum loan-to-value ratio (as decimal)- min_income_threshold: minimum gross monthly income required- supported_currencies: array of accepted currency codes- special_conditions: any additional eligibility conditions described in the documentReturn a JSON object with these fields. Use null for any parameter not found in the document.
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.
Keep Script nodes focused on a single calculation domain (e.g., financial formulas in one node, scoring in another). This makes each node independently testable and easier to audit.
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.
You are a mortgage product filter. Given the client's preferences and a list of availableproducts, evaluate each product against the qualitative criteria.Client preferences:- Loan type preference: {{input.clientData.loanTypePreference}}- Values sustainability features: {{input.clientData.sustainabilityPreference}}- Risk tolerance: {{input.clientData.riskTolerance}}For each product, return:- product_id: the product identifier- qualitative_match_score: a number between 0 and 1- match_reasons: brief explanation of why it matches or does not match- disqualified: boolean, true if the product is fundamentally incompatibleOnly return products where disqualified is false.
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.
You are a professional mortgage consultant. Generate a concise recommendation reportfor the client based on the following analysis results.Client profile:- Weighted monthly income: {{input.calculationResults.weightedIncome}}- Debt-to-income ratio: {{input.calculationResults.dti}}- Maximum eligible loan: {{input.calculationResults.maxLoanAmount}}Top recommended products (ranked):{{input.rankedProducts}}Structure the report as:1. Executive summary (2-3 sentences)2. Eligibility assessment (income qualification, DTI status)3. Top 3 product recommendations with key differentiators4. Next steps for the clientUse professional financial language. Do not include disclaimers about being an AI.
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
The full pipeline processes 7 banks in parallel using a fan-out structure, then merges results for the final ranking.
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.
AI EXTRACTION --> [Human review gate] --> BUSINESS RULES --> AI UNDERSTANDING --> [Human review gate] --> BUSINESS RULES --> AI GENERATION
Implement the review gates using User Task nodes in the parent BPMN process. The reviewer sees the AI output and can correct it before the workflow continues.
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.
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.