For the complete documentation index, see llms.txt. This page is also available as Markdown.

Open & Dynamic Schemas

Open and dynamic schemas — accepting extra fields with the * marker.

By default a schema is closed: a record may contain only the declared fields. Adding a * marker makes the schema open, allowing extra fields beyond those declared.

Closed by default

Extra values in a record are rejected unless the schema opts in with *:

~ $schema: { name: string, age: int }
---
~ John, 30                #
~ Alex, 25, extra1        # ✗ additional-values-not-allowed

Allowing extra fields with *

Place * after the declared fields to accept extras. Positional extras are keyed by index; keyed extras keep their names:

~ $schema: { name: string, age: int, * }
---
~ John, 30                       #
~ Alex, 25, Male, cool           # ✓ extras at index 2 and 3
~ { Mia, 28, role: dev }         # ✓ extra keyed field "role"

Typing the extra fields

*: <type> constrains every extra field; *: { <type>, …constraints } adds constraints:

Dynamic types with anyOf

When a single field must accept more than one type, use anyOf (see Any):

When to use curly braces

A top-level schema needs braces only when wrapping a nested object. A nested field with more than one member MUST be enclosed in { … }:

See Also

Last updated

Was this helpful?