Skip to content

Examples

Real-world business rules written in Flow. Each example is a complete, runnable .flow file — the rule and the executable are the same artifact.

Available examples

Transaction Fraud

Real-time fraud decisioning that combines AI risk scoring, rule-based screening, velocity checks, and human escalation into a single workflow.

txt
step DecisionEngine:
    set ai-score to ai-confidence times 100 rounded to 0
    set combined-score to rule-score plus ai-score divided by 2 rounded to 0

    if combined-score is above 75:
        set decision to "block"
    otherwise if combined-score is above 40:
        set decision to "review"
    otherwise:
        set decision to "approve"

Payment Reconciliation

Compares ledger records against payment processor settlements. Loops through settlements to calculate running totals, detects mismatches, and uses AI to analyze discrepancies.

txt
step CalculateTotals:
    set settlement-total to 0
    set settlement-count to 0

    for each settlement in settlements:
        set settlement-total to settlement-total plus settlement.amount
        set settlement-count to settlement-count plus 1

step CompareResults:
    set total-difference to ledger-total minus settlement-total
    if total-difference is not 0:
        set has-mismatch to true

Chargeback Dispute

Gathers evidence from multiple sources, asks AI for a dispute recommendation, then uses string matching to decide whether to contest or accept.

txt
step BuildResponse:
    ask CaseBuilder to "analyze this chargeback dispute..."
        save the result as recommendation
        save the confidence as recommendation-confidence

    if recommendation-confidence is below 0.5:
        set action to "escalate"
    otherwise if recommendation contains "contest":
        set action to "contest"
    otherwise:
        set action to "accept"

Email Verification

Validates an email address submitted through a form. Demonstrates service calls, conditionals, and completion/rejection.

txt
verify email using EmailVerifier with address email

if email is not empty:
    complete with status "verified"
otherwise:
    reject with "The email address could not be verified"

Try in Playground

Order Processing

Processes a new order: checks inventory, calculates totals with tax, charges payment with retry logic, and generates an AI confirmation message.

txt
step CalculateTotal:
    set subtotal to order.subtotal
    set tax to subtotal times 0.08
    set total to subtotal plus tax

Try in Playground

GitHub Scout

Fetches a GitHub user profile from the public API and evaluates their popularity and activity level. Works with real data — no API key needed.

txt
get profile using GitHub at "/users/{request.username}"
    save the result as profile
set followers to profile.followers

if followers is above 1000:
    set popularity to "star"

Try in Playground

Stripe Checkout

Processes a payment through Stripe's API with authenticated headers, status checking, retry logic, and Slack notification.

txt
services:
    Stripe is an API at "https://api.stripe.com/v1"
        with headers:
            Authorization: "Bearer {env.STRIPE_SECRET_KEY}"

step CreateCharge:
    create charge using Stripe with amount amount and currency currency
        save the result as charge
        save the status as status-code
        on failure:
            retry 3 times waiting 5 seconds

Try in Playground

Slack Notification

Sends a formatted deployment notification to Slack with conditional message building based on deploy status.

txt
step BuildMessage:
    if deploy-status is "success":
        set message to "Deployed {service-name} v{version} successfully"
    otherwise if deploy-status is "rollback":
        set message to "Rolled back {service-name} to v{version}"
    otherwise:
        set message to "Deployment of {service-name} v{version} failed"

Try in Playground

SendGrid Email

Sends a transactional email through SendGrid with authentication, input validation, and delivery status verification.

txt
services:
    SendGrid is an API at "https://api.sendgrid.com/v3"
        with headers:
            Authorization: "Bearer {env.SENDGRID_API_KEY}"
            Content-Type: "application/json"

step SendEmail:
    send email using SendGrid at "/mail/send" with to recipient and subject subject
        save the status as status-code

Try in Playground

Inventory Lookup

Queries a SQLite database to check product stock levels using the database connector. Demonstrates table-mode queries, empty checks, and conditional logic.

txt
services:
    DB is a database at "./inventory.sqlite"

step CheckProduct:
    get product using DB at "products" with id request.product-id
        save the result as product

    if product is empty:
        reject with "Product not found"

Customer Database

Queries a PostgreSQL database to look up a customer, aggregates their order history, and classifies them into a loyalty tier based on total spending.

txt
services:
    DB is a database at "postgresql://localhost:5432/customers"

step GetOrderHistory:
    list orders using DB at "orders" with customer_id customer-id
        save the result as orders

    set total-spent to 0
    for each order in orders:
        set total-spent to total-spent plus order.amount

Daily Sales Report

Aggregates daily sales from a database, calculates revenue metrics, evaluates performance against targets, and sends a summary to Slack. Designed to run on a schedule.

txt
step CalculateMetrics:
    if order-count is above 0:
        set average-order to total-revenue divided by order-count

step EvaluatePerformance:
    if total-revenue is above 50000:
        set performance to "exceptional"
    otherwise if total-revenue is above 25000:
        set performance to "strong"
bash
flow schedule examples/daily-sales-report.flow --every "day at 18:00" --mock

SLA Monitor

Checks the health of critical services and alerts via PagerDuty when any are down. Designed to run every few minutes on a schedule.

txt
step CheckPaymentAPI:
    get health using PaymentAPI at "/health"
        save the status as payment-status
        on failure:
            retry 2 times waiting 3 seconds
            if still failing:
                set payment-status to 0

    if payment-status is not 200:
        set failed-services to failed-services plus 1
        log "ALERT: PaymentAPI is not responding"
bash
flow schedule examples/sla-monitor.flow --every "5 minutes" --mock --verbose

Running examples

With mock services

bash
flow test examples/email-verification.flow --dry-run --verbose

With real APIs

The GitHub Scout example works with real data:

bash
flow run examples/github-scout.flow --input '{"username": "torvalds"}'

As webhooks

Serve all examples as HTTP endpoints:

bash
flow serve examples/ --mock --port 3000

Then trigger any workflow:

bash
curl -X POST http://localhost:3000/github-scout \
  -H "Content-Type: application/json" \
  -d '{"username": "octocat"}'

Creating your own

Every Flow file follows the same structure:

txt
config:
    name: "My Workflow"
    version: 1

services:
    # Declare your services here

workflow:
    trigger: when something happens

    # Your logic here

    complete with result data

See the Getting Started guide to create your first workflow, or the Language Reference for the complete syntax.

Released under the MIT License.