Field Types
Field Types
MashinTalk fields are typed. Types appear in accepts (input contract), responds with (output contract), returns (step output schema), and resource fields (store definitions). The type system is shared across all contexts, with some modifiers specific to stores (see Store Field Types).
When to use
Every field declaration needs a type. Choose the most specific type that matches your data: use integer over number when you know the value is always whole, use enum(...) when the value is one of a fixed set, use decimal for financial amounts where precision matters.
Syntax
<field_name> as <type>, <modifiers>Primitive types
| Type | Description | Example values |
|---|---|---|
text | Text value. The primary string type. | "hello", "[email protected]" |
string | Alias for text. Both compile identically. | "hello" |
number | Numeric value (integer or floating point). Use when you do not need to distinguish between them. | 42, 3.14 |
integer | Whole number only. | 0, 42, -7 |
decimal | Precise decimal. No floating-point rounding errors. Use for currency, measurements, scores. | 19.99, 0.001 |
boolean | True or false. | true, false |
uuid | UUID identifier string. Typically used for primary keys. | "550e8400-e29b-41d4-a716-446655440000" |
date | Calendar date without time. ISO 8601 format. | "2026-04-29" |
datetime | Date and time in UTC. ISO 8601 format. | "2026-04-29T14:30:00Z" |
Composite types
| Type | Description | Example |
|---|---|---|
list | List of any values. | [1, "two", true] |
list(<type>) | Typed list. All elements must match the inner type. | list(text), list(integer) |
map | Key-value map with string keys and any values. | {key: "value", count: 42} |
object | Alias for map. Both compile identically. | {name: "test"} |
object { ... } | Structured object with named, typed fields. Provides schema validation for nested data. | See examples below. |
enum("a", "b", "c") | One of a fixed set of string values. Values are validated on input. | "draft", "active", "archived" |
any | Any type. No type validation. Use sparingly. | Any value. |
File types
| Type | Description | Example |
|---|---|---|
file | Any file. Content-addressed reference. | Binary data reference |
file(image) | Image file (any image mime type). | PNG, JPEG, WebP |
file(image/png | image/jpeg) | Image restricted to specific formats. | PNG or JPEG only |
file(application/pdf) | PDF file. | PDF document |
file(text) | Plain text file. | TXT, CSV |
File-specific modifiers
| Modifier | Description | Example |
|---|---|---|
max_size: <size> | Maximum file size | max_size: 25mb |
max_pages: <n> | Maximum page count (PDFs) | max_pages: 100 |
max_dimensions: <w>x<h> | Maximum image dimensions | max_dimensions: 8000x8000 |
Special types
| Type | Description | Example |
|---|---|---|
machine_ref | Type-safe reference to another machine. Can include schema constraints. | See examples below. |
Field modifiers
| Modifier | Description | Example |
|---|---|---|
is required | Field must be provided. Cannot be nil. | name as text, is required |
default: <value> | Default value if the field is not provided. | count as integer, default: 0 |
Examples
Input contract with mixed types
machine data_processor
accepts query as text, is required limit as integer, default: 10 include_metadata as boolean, default: false categories as list(text) options as map
responds with results as list total as integer query_time as decimalEnum for fixed-value fields
accepts priority as enum("low", "medium", "high", "critical"), is required status as enum("open", "in_progress", "resolved"), default: "open"Enum values are validated at input. Passing a value not in the set produces a validation error.
Nested objects
accepts address as object { street as text, is required; city as text, is required; state as text; zip as text } contact as object { name as text, is required; email as text; phone as text }Nested objects define an inline schema for structured data. Each field inside the object follows the same name as type, modifiers syntax, separated by semicolons.
File inputs
accepts receipt as file(image), is required, max_size: 25mb report as file(application/pdf), max_pages: 100 attachment as fileFile fields are content-addressed references. The actual bytes are stored once and referenced everywhere. The behavioral ledger stores file metadata (id, content_hash, mime_type, size), never the raw bytes.
Machine references
accepts handler as machine_ref, is required processor as machine_ref, accepts { text: string }, returns { result: string }A machine_ref is a type-safe reference to another machine. You can optionally constrain the referenced machine’s input and output schemas. Machine references enable dynamic dispatch: passing different machines as arguments to achieve different behaviors.
Store resource fields
resource product id as uuid, is primary_key name as text, is required price as decimal, is required quantity as integer, default: 0 tags as list(text) metadata as map status as enum("draft", "active", "discontinued"), default: "draft" timestampsStore fields support the full type system plus store-specific modifiers like is primary_key, column:, and timestamps. See Store Field Types.
Type coercion
MashinTalk applies minimal type coercion at input boundaries:
- String
"42"is coerced to42forintegerandnumberfields - String
"true"/"false"is coerced totrue/falseforbooleanfields - ISO 8601 strings are parsed for
dateanddatetimefields
Inside compute step expressions, values are used as-is. No implicit coercion occurs within the expression language.
Governance
Types are structural declarations. They do not involve runtime governance. However, types are part of the machine’s contract and serve several governance purposes:
- Input types are validated before execution starts. Invalid inputs produce a validation error before any steps run.
- Output types are checked after execution. If the machine’s output does not match its declared schema, the execution fails.
- Type information is recorded in the behavioral ledger as part of the execution trace.
- File types track provenance (content hashes, mime types, sizes) in the ledger.
Translations
Types are not translated. They use the same names in all locales. The as keyword and the is modifier keyword are translated:
| Language | as | is required |
|---|---|---|
| English | as | is required |
| Spanish | como | es requerido |
| French | comme | est requis |
| German | als | ist erforderlich |
| Japanese | として | 必須 |
| Chinese | 作为 | 必填 |
| Korean | 으로 | 필수 |
See also
- accepts - Input contract declarations
- responds with - Output contract declarations
- Store Field Types - Store-specific field modifiers
- Expression language - How types are used in expressions