Typed data
Touba checks data at program boundaries: inputs, tool results and agent decisions. The compiler, runtime and model schemas use the same contracts.
Dates and lists
Date is an ISO calendar date without a time or timezone.
date("2026-10-21") constructs a valid date; date("2026-02-30") is refused.
Model results must already use the declared format.
Lists use [a, b]. An expected type allows an empty list, for example
bind items as List of Text = [].
Field contracts
module examples.typed_data
type Invoice
reference is Text length 1..40
issued_on is Date
currency is Text length 3 default "CAD"
total_cents is Int min 0
tags is List of Text length 0..8 default []
reason is Optional of Text default none(Text)
function Draft
gives Invoice
do
give record Invoice { reference as "INV-42", issued_on as date("2026-10-21"), total_cents as 12500 }
function Flag
takes invoice as Invoice
gives Invoice
do
give copy invoice { tags as ["review"], reason as some("Purchase order date needs review") }
Types describe accepted values. Business rules, such as comparing an invoice date with its purchase order date, belong in functions or strategies.
| Element | Purpose |
|---|---|
length 1..40 | Inclusive bounds, in Unicode code points or list items |
min, max | Numeric bounds |
format "digits" | ASCII digits in a Text field |
default | Value supplied by a source constructor when the field is omitted |
copy | New record with explicit field replacements |
Defaults do not repair external data. Handlers and models produce every field,
including the explicit {"present": false} representation of an absent optional.
Approval result
human.approve … into approval binds an Approval value.
| Field | Type | Content |
|---|---|---|
decision | Text | approved, rejected or expired, according to the branch |
subject_ref | Optional of Text | Attested signer, when present |
attested_roles | List of Text | Roles verified by the host |
request_id, run_id | Text | Correlation identifiers |
accepted_at | Text | UTC ISO timestamp |
comment | Optional of Text | Decision comment, up to 4,096 characters |
Unknown fields are reported at compilation. Use the result for notifications and business statuses. Approval authority remains in private runtime receipts and host attestation.
Continue with typed data and role-based approvals.
Constants and diagnostics
A fixed date can be declared at module level. Comments may follow declarations and statements:
module examples.fixed_date
define Closing as Date = date("2026-10-31") # End of period
function ReadClosing
gives Date
do
give Closing # Validated civil date
A constraint failure identifies its field, constraint and bound, for example
min requires 0. The rejected value stays out of the diagnostic.
The Approval result also exposes comment as Optional of Text. This optional
comment accompanies the decision; the host attests roles and signer identity.