Skip to main content
PreviewAgent Builder is currently in preview and may change before general availability.

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
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).

Architecture

The pattern alternates between AI nodes and Script/Business Rule nodes in a pipeline:
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.

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

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.

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:
  1. Extracts financial parameters from each bank’s rule documents
  2. Computes eligibility using exact financial formulas (PMT, DTI)
  3. Filters the product catalog using AI-driven qualitative matching
  4. Ranks the remaining products with a deterministic scoring matrix
  5. 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.

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.
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.

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.

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
Last modified on July 8, 2026