๐ฏ
Pure & Deterministic
Same input always produces the same output. No hidden state, no side effects, no surprises.
Universal, deterministic, and explainable decisions for business-critical systems
import { Engine, defineDecision } from "@criterionx/core";
import { z } from "zod";
const riskDecision = defineDecision({
id: "transaction-risk",
version: "1.0.0",
inputSchema: z.object({ amount: z.number() }),
outputSchema: z.object({ risk: z.enum(["HIGH", "MEDIUM", "LOW"]) }),
profileSchema: z.object({ threshold: z.number() }),
rules: [
{
id: "high-risk",
when: (input, profile) => input.amount > profile.threshold,
emit: () => ({ risk: "HIGH" }),
explain: (input, profile) =>
`Amount ${input.amount} exceeds threshold ${profile.threshold}`,
},
{
id: "low-risk",
when: () => true,
emit: () => ({ risk: "LOW" }),
explain: () => "Amount within acceptable range",
},
],
});
const engine = new Engine();
const result = engine.run(
riskDecision,
{ amount: 15000 },
{ profile: { threshold: 10000 } }
);
console.log(result.data); // { risk: "HIGH" }
console.log(result.meta.explanation); // "Amount 15000 exceeds threshold 10000"