ObjectStackObjectStack

Field Validation Rules

Default validation behavior, required properties, and constraints for each ObjectStack field type

Field Validation Rules

Every ObjectStack field type has built-in validation behavior that runs automatically at the schema level. This reference documents the default constraints, required properties, and validation semantics for each field type.

Source: packages/spec/src/data/field.zod.ts
Import: import { FieldSchema, FieldType } from '@objectstack/spec/data'


Universal Field Constraints

These properties apply to all field types and are validated by the base FieldSchema:

PropertyTypeDefaultValidation Behavior
namestringMust match ^[a-z_][a-z0-9_]*$ (snake_case)
labelstringHuman-readable display name
typeFieldTypeMust be a member of the FieldType enum
requiredbooleanfalseRejects null/undefined at runtime when true
uniquebooleanfalseEnforces database-level uniqueness constraint
multiplebooleanfalseStores value as array (applicable for select, lookup, file, image)
hiddenbooleanfalseExcluded from default UI rendering
readonlybooleanfalseBlocks user edits in UI forms; server-enforced on update — a non-system write to the field is silently dropped from the payload (insert exempt)
sortablebooleantrueWhether field appears in list view sort options
indexbooleanfalseCreates standard database index
externalIdbooleanfalseMarks field as external ID for upsert operations
trackHistorybooleanRender this field's value changes as entries on the record activity timeline
visibleWhenstring | ExpressionCEL predicate; field is shown only when TRUE
readonlyWhenstring | ExpressionCEL predicate; field is read-only when TRUE
requiredWhenstring | ExpressionCEL predicate; field is required when TRUE
conditionalRequiredstring | ExpressionDeprecated alias of requiredWhen

Text Types

text

PropertyTypeDefaultValidation Behavior
maxLengthnumberRejects values exceeding character count
minLengthnumberRejects values below character count
formatstringValidates against format pattern (e.g., regex)

Default constraints: None. Unbounded text unless maxLength is set.

textarea

PropertyTypeDefaultValidation Behavior
maxLengthnumberRejects values exceeding character count
minLengthnumberRejects values below character count

Default constraints: None. Multi-line text with no length limit by default.

email

PropertyTypeDefaultValidation Behavior
formatstringemailValidates a basic local@domain shape

Default constraints: Must contain an @ and a domain with a dot — a lightweight pattern check, not full RFC 5322 validation.

url

PropertyTypeDefaultValidation Behavior
formatstringurlValidates URL format (protocol required)

Default constraints: Must be a valid URL with protocol prefix.

phone

PropertyTypeDefaultValidation Behavior
formatstringphoneValidates a permissive phone-number character set

Default constraints: Accepts digits, + ( ) - . and spaces (minimum 5 characters) — a lenient character-set check, not strict E.164 structural validation.

password

PropertyTypeDefaultValidation Behavior
maxLengthnumberMaximum password length
minLengthnumberMinimum password length

Default constraints: Validated the same as text (maxLength/minLength only) — the engine does not automatically hash or mask a password-typed field's value on read; even the platform's own credential column (sys_account.password) is declared as Field.text(), with hashing and verification owned entirely by the auth subsystem (better-auth), not driven by this field type. For a reversible encrypted-at-rest value on your own objects, use the secret type instead.


Rich Content Types

markdown

PropertyTypeDefaultValidation Behavior
maxLengthnumberCharacter limit on raw markdown source

Default constraints: Accepts valid Markdown syntax. No length limit by default.

html

PropertyTypeDefaultValidation Behavior
maxLengthnumberCharacter limit on raw HTML source

Default constraints: HTML content is sanitized to prevent XSS. No length limit by default.

richtext

PropertyTypeDefaultValidation Behavior
maxLengthnumberCharacter limit on serialized content

Default constraints: Stored as structured rich text (e.g., ProseMirror/Tiptap JSON). Sanitized on save.


Number Types

number

PropertyTypeDefaultValidation Behavior
minnumberRejects values below minimum
maxnumberRejects values above maximum
precisionnumberTotal number of digits allowed
scalenumberNumber of decimal places

Default constraints: Any valid number. No range or precision limits by default.

currency

PropertyTypeDefaultValidation Behavior
minnumberMinimum monetary value
maxnumberMaximum monetary value
currencyConfig.precisionnumber2Decimal places (0–10)
currencyConfig.currencyModeenumdynamicdynamic (user-selectable) or fixed (single currency)
currencyConfig.defaultCurrencystringCNY3-character currency code (ISO 4217 or crypto)

Default constraints: Stored as { value, currency } pair. Precision defaults to 2 decimal places.

percent

PropertyTypeDefaultValidation Behavior
minnumberMinimum percentage value
maxnumberMaximum percentage value
precisionnumberTotal digits
scalenumberDecimal places

Default constraints: Stored as decimal (e.g., 0.85 for 85%). No range limit by default.


Date & Time Types

date

Required props: None.
Default constraints: Validates ISO 8601 date format (YYYY-MM-DD). No range restrictions.

datetime

Required props: None.
Default constraints: Validates ISO 8601 datetime format (YYYY-MM-DDTHH:mm:ssZ). Stored in UTC.

time

Required props: None.
Default constraints: Validates ISO 8601 time format (HH:mm:ss). 24-hour format.


Boolean Types

boolean

PropertyTypeDefaultValidation Behavior
defaultValuebooleanInitial value when field is empty

Default constraints: Only accepts true or false. Renders as checkbox.

toggle

PropertyTypeDefaultValidation Behavior
defaultValuebooleanInitial value when field is empty

Default constraints: Identical validation to boolean. Distinct UI — renders as toggle switch.


Selection Types

select

PropertyTypeDefaultValidation Behavior
optionsSelectOption[]Required. Static option list
defaultValuestringMust match an option value

Option validation: Each option value must be a lowercase system identifier — starts with a letter, then letters/digits/underscores/dots (^[a-z][a-z0-9_.]*$), minimum 2 characters.

multiselect

PropertyTypeDefaultValidation Behavior
optionsSelectOption[]Required. Static option list

Default constraints: Stores array of selected option values. Each value validated against options.

radio

PropertyTypeDefaultValidation Behavior
optionsSelectOption[]Required. Static option list

Default constraints: Single-value selection. Same validation as select with radio button UI.

checkboxes

PropertyTypeDefaultValidation Behavior
optionsSelectOption[]Required. Static option list

Default constraints: Multi-value selection. Same validation as multiselect with checkbox group UI.


Relational Types

lookup

PropertyTypeDefaultValidation Behavior
referencestringRequired. Target object name
referenceFiltersstring[]Legacy — schema-accepted but not read by the record-picker; use lookupFilters + dependsOn
deleteBehaviorenumset_nullset_null, cascade, or restrict
multiplebooleanfalseAllow multiple references

Default constraints: Validates that referenced record exists. Foreign key integrity enforced.

master_detail

PropertyTypeDefaultValidation Behavior
referencestringRequired. Parent object name
deleteBehaviorenumcascadeMaster-detail cascades at runtime unless set to restrict

Default constraints: Enforces parent-child ownership. Child records cascade-delete with the parent by default.

tree

PropertyTypeDefaultValidation Behavior
referencestringRequired. Self-referencing object name

Default constraints: Self-referencing lookup for hierarchical structures. Stored and expanded like a lookup; the engine does not run a cycle check on write, so a self-reference chain that loops back on itself is not automatically rejected.


Media Types

image

PropertyTypeDefaultValidation Behavior
fileAttachmentConfigobjectFile size, type, and image dimension rules
multiplebooleanfalseAllow multiple image uploads

Default constraints: Accepts common image MIME types. Optional dimension and thumbnail validation via fileAttachmentConfig.

file

PropertyTypeDefaultValidation Behavior
fileAttachmentConfigobjectFull file upload validation config
multiplebooleanfalseAllow multiple file uploads

Default constraints: Accepts any file type unless restricted. Supports virus scanning, size limits, and type restrictions.

// File field with validation
{
  name: 'contract_pdf',
  label: 'Contract',
  type: 'file',
  fileAttachmentConfig: {
    maxSize: 10485760,           // 10MB
    allowedTypes: ['.pdf', '.docx'],
    virusScan: true,
    virusScanProvider: 'clamav'
  }
}

avatar

Default constraints: Single image upload. Typically constrained to square aspect ratio and small file sizes.

video

PropertyTypeDefaultValidation Behavior
fileAttachmentConfigobjectFile size and type restrictions

Default constraints: Accepts common video MIME types. Size limits recommended via fileAttachmentConfig.

audio

PropertyTypeDefaultValidation Behavior
fileAttachmentConfigobjectFile size and type restrictions

Default constraints: Accepts common audio MIME types. Size limits recommended via fileAttachmentConfig.


Computed & System Types

formula

PropertyTypeDefaultValidation Behavior
expressionstringRequired. Formula expression
dependenciesstring[]Fields this formula depends on

Default constraints: Read-only. Value computed at runtime from expression. Not directly writable.

{
  name: 'full_name',
  label: 'Full Name',
  type: 'formula',
  expression: 'record.first_name + " " + record.last_name',
  dependencies: ['first_name', 'last_name']
}

summary

PropertyTypeDefaultValidation Behavior
summaryOperationsobjectRequired. Roll-up definition
summaryOperations.objectstringChild object to aggregate
summaryOperations.fieldstringField to aggregate
summaryOperations.functionenumcount, sum, min, max, or avg

Default constraints: Read-only. Value computed from child records. Only valid on master objects.

autonumber

PropertyTypeDefaultValidation Behavior
autonumberFormatstringDisplay format pattern (e.g., CASE-{0000})

Default constraints: Read-only. Auto-incremented. Cannot be manually set after creation.


Enhanced Types

location

Default constraints: Stored as { latitude, longitude, altitude?, accuracy? }. Latitude: -90 to 90. Longitude: -180 to 180. No per-type config properties.

address

Default constraints: Stored as structured object with street, city, state, postalCode, country, countryCode, formatted (all parts optional). No per-type config properties.

code

PropertyTypeDefaultValidation Behavior
languagestringProgramming language for syntax highlighting

Default constraints: Stored as plain text. Language used for UI syntax highlighting only.

json

Default constraints: Must be valid JSON. Parsed and validated on save.

color

Default constraints: Stores the color value as a string. No per-type config properties.

rating

PropertyTypeDefaultValidation Behavior
maxnumber5Maximum rating value (set by the Field.rating(max) factory)

Default constraints: Integer between 0 and max.

slider

PropertyTypeDefaultValidation Behavior
minnumberMinimum slider value
maxnumberMaximum slider value
stepnumber1Step increment

Default constraints: Numeric value between min and max in step increments.

signature

Default constraints: Stored as base64-encoded image data. Immutable after creation in most workflows.

qrcode

Default constraints: Stores the encoded value; rendered as a scannable code. No per-type config properties.

progress

PropertyTypeDefaultValidation Behavior
minnumberMinimum value (typically 0)
maxnumberMaximum value (typically 100)

Default constraints: Numeric value rendered as a progress bar. Usually 0–100.

tags

Default constraints: Stored as array of strings. A lone scalar value is coerced into a single-element array; the engine does not trim or deduplicate entries.


AI/ML Types

vector

PropertyTypeDefaultValidation Behavior
dimensionsnumberRequired. Vector size (1–10,000)

Default constraints: Must be a numeric array of exactly dimensions length. The nested vectorConfig object is retained for back-compat only and is a runtime no-op — set the flat dimensions property instead.

{
  name: 'content_embedding',
  label: 'Content Embedding',
  type: 'vector',
  dimensions: 1536
}

Security & Compliance Properties

For sensitive data, use the properties and types the platform actually enforces:

PropertyTypeDefaultDescription
requiredPermissionsstring[]Capabilities required to read/edit the field — masked on read, denied on write unless the caller holds all of them (ADR-0066 D3)
trackHistorybooleanRender the field's value changes as entries on the record activity timeline

For reversible encrypted-at-rest values (API keys, tokens, DB passwords), use the secret field type — it is the type with an enforced masking/encryption code path. password is validated like plain text and has no built-in hashing or read-masking (see the password section above). See the Field Type Gallery.


Quick Validation Summary

Field TypeRequired PropsKey Constraints
textmaxLength, minLength, format
textareamaxLength, minLength
emailBasic local@domain shape (not full RFC 5322)
urlValid URL with protocol
phonePermissive character set, not strict E.164
passwordValidated like text; no built-in hashing/masking
markdownmaxLength
htmlSanitized, maxLength
richtextSanitized, maxLength
numbermin, max, precision, scale
currencycurrencyConfig (precision, mode, code)
percentmin, max, stored as decimal
dateISO 8601 date
datetimeISO 8601 datetime, UTC
timeISO 8601 time, 24h
booleantrue / false only
toggletrue / false only
selectoptionsOption values must be lowercase system identifiers
multiselectoptionsArray of valid option values
radiooptionsSingle value from options
checkboxesoptionsArray of valid option values
lookupreferenceForeign key integrity
master_detailreferenceCascade delete, ownership
treereferenceSelf-referencing; no automatic cycle check
imagefileAttachmentConfig for dimensions
filefileAttachmentConfig for restrictions
avatarSingle image, typically square
videofileAttachmentConfig for size limits
audiofileAttachmentConfig for size limits
formulaexpressionRead-only, computed at runtime
summarysummaryOperationsRead-only, roll-up from children
autonumberRead-only, auto-incremented
locationLat: -90–90, Lng: -180–180
addressStructured object (street, city, …)
codePlain text, language for highlighting
jsonMust be valid JSON
colorStored as a string
rating0 to max (default 5)
slidermin to max in step increments
signatureBase64 image, typically immutable
qrcodeFormat-specific validation
progressNumeric, typically 0–100
tagsString array; no automatic trim/dedup
vectordimensionsNumeric array of exact dimensions length

On this page