PeaLang / Code Library / Blueprint
Production Blueprint · v3.1.36
FinTech risk decision rules
Domain: FinTech / Fraud & CompliancePeaLangPythonJava
Verified example. The code below was checked against the local PeaLang v3.1.36 parser, interpreter or async VM. It uses only syntax and built-ins present in that source tree.
Problem statement
A payment service needs one reviewable rule that is shared by a Python batch job and a Java API. A malformed transaction must never silently pass, and every rejection must carry a stable machine code plus minimal context for audit logs.
Complete code
const MAX_AMOUNT = 10000
const HIGH_RISK_COUNTRIES = ["XX", "YY"]
function evaluate(tx) {
if tx == null {
return error("ValueError", "missing transaction", "E_NULL")
}
if tx["amount"] == null {
return error("ValueError", "missing amount", "E_AMOUNT", null, {"field": "amount"})
}
if tx["amount"] > MAX_AMOUNT {
return error("ValueError", "amount above limit", "E_LIMIT", null,
{"amount": tx["amount"], "limit": MAX_AMOUNT})
}
if tx["country"] in HIGH_RISK_COUNTRIES {
return {"decision": "REVIEW", "score": 60, "reasons": ["country"]}
}
let score = std.math.clamp(tx["amount"] / 100, 0, 50)
return {"decision": "ALLOW", "score": score, "reasons": []}
}
let approved = evaluate({"amount": 250, "country": "IN"})
print std.json.stringify(approved)
let denied = evaluate({"amount": 25000, "country": "IN"})
print denied["code"]
Save as
fintech-risk-rules.peaRun & verify
pea fmt --check fintech-risk-rules.pea
pea check fintech-risk-rules.pea
pea run fintech-risk-rules.pea
Always run the formatter and static checker before execution:
pea fmt --check fintech-risk-rules.pea && pea check fintech-risk-rules.pea, then pea run fintech-risk-rules.pea (or the host command shown above for async modules).Why & How
- Input shape first. The rule accepts a plain map, so callers from Python or Java can pass JSON-derived data without host objects. No secret or live connection is embedded in the script.
- Total behaviour. Each invalid branch returns a structured
error(kind, message, code, cause, context)value instead of throwing. The stable codesE_NULL,E_AMOUNTandE_LIMITbecome log keys and test assertions. - Why five arguments. The fourth argument is the cause (omitted here with
null); the fifth is a small context map. Context carries only the offending amount and limit — never PII or tokens. - Decision logic.
inchecks the country against a constant allow-review list, andstd.math.clampbounds the numeric score. Both are ordinary v3.1.36 runtime features, so the function works identically in the interpreter and when embedded. - Cross-language use. Embed the function with
PeaRuntimefrom Python or expose it over the generated RPC client from Java. The rule itself remains the single source of truth; neither host reimplements the policy. - Verification. The printed output is a JSON decision map for the allowed case and
E_LIMITfor the blocked case, confirming both branches execute.