@aroha-sdk/policy
v1.3.0
Published
Aroha Policy-as-Code — deterministic JSON boundary enforcement before LLM agents see requests
Readme
@aroha-sdk/policy
Pre-LLM policy guardrails for Aroha agents — declarative rules that run before the model is called, complementing cryptographic mandate bounds.
Install
npm install @aroha-sdk/policyQuick example
import { PolicyEngine } from "@aroha-sdk/policy";
const policy = new PolicyEngine({
rules: [
// Block requests that exceed the mandate's allowed actions
{
name: "allowed-actions",
check: (req, mandate) =>
mandate.constraints.allowedActions.includes(req.action),
onViolation: "reject",
message: "Action not permitted by mandate",
},
// Rate-limit to protect the spending cap
{
name: "rate-limit",
check: (req, mandate) => rateLimiter.allow(mandate.granteeDID),
onViolation: "reject",
message: "Rate limit exceeded",
},
// Flag suspicious prompts for review before calling the LLM
{
name: "prompt-injection-guard",
check: (req) => !containsInjectionPattern(req.message),
onViolation: "flag",
},
],
});
serve({
name: "my-agent", did, privateKey,
onRequest: async (req) => {
const { allowed, reason } = await policy.evaluate(req, req.mandate);
if (!allowed) return { error: reason, status: 403 };
// ... call LLM
},
});Why this exists in the mandate chain
Cryptographic mandate bounds enforce what an agent is authorized to do. Policy rules enforce what it should do — prompt injection guards, rate limits, content filters, and action-allow-lists that run before the LLM ever sees the request.
API
PolicyEngine(opts)— create a policy engine with a list of named rules.engine.evaluate(req, mandate)— run all rules. Returns{ allowed, reason?, flagged? }.
PolicyRule—{ name, check(req, mandate): boolean | Promise<boolean>, onViolation: "reject" | "flag", message? }.buildDefaultPolicy()— sensible default ruleset: prompt injection guard, action allowlist, and spend-cap pre-check.
License
MIT
