Skip to main content
Version: 1.0.0

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.

ElementPurpose
length 1..40Inclusive bounds, in Unicode code points or list items
min, maxNumeric bounds
format "digits"ASCII digits in a Text field
defaultValue supplied by a source constructor when the field is omitted
copyNew 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.

FieldTypeContent
decisionTextapproved, rejected or expired, according to the branch
subject_refOptional of TextAttested signer, when present
attested_rolesList of TextRoles verified by the host
request_id, run_idTextCorrelation identifiers
accepted_atTextUTC ISO timestamp
commentOptional of TextDecision 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.