Companion film
The input has a contract
Attempt an invalid write, keep the last valid state with an authored explanation, then correct the input and settle the model.
44 secGrid 0.61.0
Open film page →Canonical Grid model
Declared presentation on a guarded expense-entry sheet: VALIDATE write contracts, static assertions, FORMAT declarations, ## doc notes, and tag-driven rendering.
What this model gives you
20 min to study · Source reviewed 2026-08-25
Continue with guided practiceExpected checkpoint
At the authored inputs with AuditMode false, before attempting invalid writes.
Quantity, price, category, discount, and invoice reference keep their stored values when a write violates the authored contract.
Input intervals let the compiler prove Subtotal and BudgetShare stay inside their declared ranges.
AuditMode changes precision and rule overrides, then RESET reveals the declared tag policy again.
MODEL "Cell Metadata & Validation"
DESCRIPTION "Declared presentation on a guarded expense-entry sheet: VALIDATE write contracts, static assertions, FORMAT declarations, ## doc notes, and tag-driven rendering."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "canonical", "presentation", "validation", "metadata", "format"
# Tag policy: every percentage-tagged cell renders with one decimal place
# unless a stronger layer (per-cell clause, rule override) takes over.
FORMAT percentage "0.0%"
# Guarded inputs — a VALIDATE clause on an input is a write contract that
# gates every write surface (grid UI, API, connectors) and reports MESSAGE.
input Units = 3 VALIDATE 1..48 ## range sugar for BETWEEN 1 AND 48
## List price per unit from the vendor quote, before any discount.
input UnitPrice = 40
VALIDATE BETWEEN 0 AND 500 MESSAGE "Unit price must be between $0 and $500."
## Vendor-negotiated discount. Procurement caps it at 30%.
## Renders as 0.0% via the percentage tag policy above.
input DiscountRate IS percentage = 5pct
VALIDATE BETWEEN 0pct AND 30pct MESSAGE "Discount must be between 0% and 30%."
input Category = "travel"
VALIDATE IN ["travel", "software", "meals", "hardware"] MESSAGE "Pick an approved expense category."
input InvoiceRef = "INV-1042"
VALIDATE STARTS WITH "INV-" MESSAGE "Invoice references begin with INV-."
input AuditMode = FALSE FORMAT "switch" ## boolean renders as a toggle switch
# Computed cells — here VALIDATE is a static assertion. The write contracts
# on Units and UnitPrice seed interval analysis, so the compiler proves both
# assertions below at compile time and records them in module metadata.
Subtotal = Units * UnitPrice VALIDATE 0..24000
## Fraction of the $24,000 per-claim cap this entry consumes.
BudgetShare = Subtotal / 24000 VALIDATE 0..1
# Type-tag-driven presentation: the currency tag says what the value *is*;
# the FORMAT clause says exactly how it renders. The format operand is an
# expression, so it re-derives whenever AuditMode flips.
NetAmount IS currency = Subtotal * (1 - DiscountRate)
FORMAT IF(AuditMode, "$#,##0.0000", "$#,##0.00")
ApprovalStatus = NetAmount > 5000 THEN "needs-approval" ELSE "auto-approved"
# Rule-driven overrides sit above the declared layer: FORMAT actions write
# the override, RESET FORMAT clears it so the tag policy governs again.
WHEN AuditMode THEN
FORMAT DiscountRate "0.000%"
END
WHEN NOT AuditMode THEN
RESET FORMAT DiscountRate
END
END MODEL