Specification · v1

µLang v1

µLang v1 is the open contract layer of µLang. A v1 contract names one kind of request (an entity with typed fields), the actions it governs, and the rules each action must satisfy. Given an action and the facts of one request, a contract returns a decision: a verdict, PERMIT or DENY, and the id of the clause that decided it.

Expense approvalexpense
// Expense approvals: who may approve, and up to how much.
CONTRACT ExpenseApproval {
  ENFORCEMENT_MODE: enforced
  CONTEXT {
    ENTITIES Expense {
      amount: float
      approver_is_submitter: bool
      approver_limit: float
      receipt_attached: bool
      category: string
    }
    CONSTANTS {
      receipt_threshold: float == 75.0 [SOURCE:FIN-POLICY-4.2]
      hard_cap: float == 10000.0 [SOURCE:FIN-POLICY-4.1]
    }
  }
  TRIGGER {
    approve_expense()
  }
  GUARANTEE {
    ENSURE approve_expense() WHEN Expense.receipt_attached == true OR Expense.amount < receipt_threshold [SOURCE:receipt_required]
  }
  PROHIBITION {
    FORBID approve_expense WHEN Expense.approver_is_submitter == true [SOURCE:no_self_approval]
    FORBID approve_expense WHEN Expense.amount > hard_cap [SOURCE:over_hard_cap]
    FORBID approve_expense WHEN Expense.amount > Expense.approver_limit [SOURCE:over_approver_limit]
    FORBID approve_expense WHEN Expense.category == "gift_card" [SOURCE:no_gift_cards]
  }
  OBSERVABILITY {
    LOG "expense approval decided" ON decision
  }
}

valid ExpenseApproval 5 clauses · sha256 5a6326d24470e02c54a4f175994a1b0c2c4a6efa08baec2c025b0af1fc78e7fd

Facts of the first request; each other request changes only the fields shown.

{
  "Expense": {
    "amount": 120,
    "approver_is_submitter": false,
    "approver_limit": 500,
    "receipt_attached": true,
    "category": "travel"
  }
}
RequestActionChangedVerdictClause
within limits, receipt attachedapprove_expenseas abovePERMITExpenseApproval.approve_expense.permit
approver submitted itapprove_expenseapprover_is_submitter: trueDENYExpenseApproval.no_self_approval
above the approver’s limitapprove_expenseamount: 800DENYExpenseApproval.over_approver_limit
no receipt above the thresholdapprove_expensereceipt_attached: falseDENYExpenseApproval.receipt_required
no receipt, under the thresholdapprove_expenseamount: 40 receipt_attached: falsePERMITExpenseApproval.approve_expense.permit
self-approval and no receipt: prohibitions are checked firstapprove_expenseapprover_is_submitter: true receipt_attached: falseDENYExpenseApproval.no_self_approval

Nothing else comes back: no score and no explanation text. A decision is the verdict plus the clause that produced it, and the contract is identified by the SHA-256 of its canonical text.

What v1 is for

v1 governs actions that must be decided before they happen: an agent claiming files, a push to a protected branch, a tool call, a token being minted. The µLang Git forge decides every governed effect with v1 contracts; its twelve production contracts are on the examples page.

Properties a v1 decision always has:

The reference implementation

ulang-lite is the reference implementation of v1. It is TypeScript with zero runtime dependencies, MIT licensed, and runs unchanged in Cloudflare Workers, Node.js 22.18 and later, and browsers. It is the same engine the playground runs in your browser.

This specification is written from ulang-lite as released at commit

61af4281ed. Where the two disagree, ulang-lite is

authoritative, and the disagreement is a bug in this document. Every contract, diagnostic, decision and digest on this site is produced by that release when the site is built, not typed by hand.

Two layers: what parses, and what executes

v1 has a grammar and an executable subset.

A source is accepted only when it parses, stays inside the subset and validates. Then, and only then, it can be evaluated and hashed.

Chapters

ChapterCovers
Syntaxcharacters, comments, names, literals, the full grammar, and the sharp edges
Executable subsetwhat a valid contract may contain
Validation and diagnosticsthe check order, and every diagnostic kind and code
Evaluationdecide, facts, and how comparisons work
Canonical formscanonical text, canonical JSON, and the contract digest
Limitsthe bounds scan and the resource limits
API and CLIusing ulang-lite from code and from the command line
Test vectorsevery case on this site, with its expected result, as JSON
Changelogversions of v1 and of this document