Skip to main content
The Workers SDK includes three schema-related exports:

Schema builder

The j export from @notionhq/workers/schema-builder builds JSON Schemas for tool input and output. Use it instead of hand-writing JSON Schema so tool contracts stay compatible across a wide range of closed and open-source models. Builder methods return a SchemaBuilder<T>.

j.object()

Creates an object schema. All provided properties are included in required, and additionalProperties is set to false.

j.string()

Creates a string schema.

j.number()

Creates a number schema.

j.array()

Creates an array schema.

.describe()

Sets the JSON Schema description field and returns a new builder.

.nullable()

Wraps the schema in anyOf with { type: "null" } and returns a new builder. In object schemas, the property is still required, but its value may be null.

j.integer()

Creates an integer schema.

j.boolean()

Creates a boolean schema.

j.enum()

Creates an enum schema from string or number literal values.

j.datetime()

Creates a string schema with format: "date-time".

j.date()

Creates a string schema with format: "date".

j.time()

Creates a string schema with format: "time".

j.duration()

Creates a string schema with format: "duration".

j.email()

Creates a string schema with format: "email".

j.hostname()

Creates a string schema with format: "hostname".

j.ipv4()

Creates a string schema with format: "ipv4".

j.ipv6()

Creates a string schema with format: "ipv6".

j.uuid()

Creates a string schema with format: "uuid".

j.anyOf()

Creates an anyOf schema from the provided schema builders.

j.ref()

Creates a reference schema with $ref set to path.

Database schema helpers

Use Schema helpers to define the properties of managed databases declared with worker.database().

Schema.title()

Creates a title property definition. This field becomes the title for all pages in the database. A database must have exactly one title property.
Returns:

Schema.richText()

Creates a rich text property definition.
Returns:

Schema.url()

Creates a URL property definition.
Returns:

Schema.email()

Creates an email property definition.
Returns:

Schema.phoneNumber()

Creates a phone number property definition.
Returns:

Schema.checkbox()

Creates a checkbox property definition.
Returns:

Schema.file()

Creates a file property definition.
Returns:

Schema.number()

Creates a number property definition. If format is provided, it is included in the returned configuration.
Returns:

Schema.date()

Creates a date property definition. If dateFormat is provided, it is emitted as date_format.
Returns:

Schema.select()

Creates a select property definition with predefined options.
Returns:

Schema.multiSelect()

Creates a multi-select property definition with predefined options.
Returns:

Schema.status()

Creates a status property definition with status groups.
Returns:

Schema.people()

Creates a people property definition.
Returns:

Schema.place()

Creates a place property definition for geographic locations.
Returns:

Schema.relation()

Creates a relation property definition that references another database declared in the same worker. relatedDatabaseKey must match the key passed to worker.database() for the related database. If config is omitted, the relation is one-way.
Returns:

Property value builders

Use Builder helpers to construct property values returned by sync changes. These properties must match the types defined in the database schema.

Builder.richText()

Creates a plain rich text value. Builder.richText() does not accept formatting options; it returns a single text token with no annotations.
Returns:

Builder.url()

Creates a URL value.
Returns:

Builder.title()

Creates a title value.
Returns:

Builder.text()

Creates a text value.
Returns:

Builder.email()

Creates an email value.
Returns:

Builder.phoneNumber()

Creates a phone number value.
Returns:

Builder.checkbox()

Creates a checkbox value. true returns Yes; false returns No.
Returns:

Builder.file()

Creates a file URL value. If fileName is omitted, the URL is also used as the display text.
Returns:

Builder.number()

Creates a number value by converting value to a string. If value is NaN, returns an empty value.
Returns:

Builder.date()

Creates a date value from a YYYY-MM-DD date string. Throws if the input does not match that format or cannot be parsed by JavaScript Date.
Returns a date mention token:

Builder.dateTime()

Creates a datetime value from an ISO 8601 datetime string that starts with YYYY-MM-DDTHH:mm. The builder stores the first 10 characters as start_date and characters 11 through 16 as start_time. If timeZone is provided, it is included as time_zone.
Returns a date mention token:

Builder.dateRange()

Creates a date range value from two YYYY-MM-DD date strings. Throws if either input does not match that format or cannot be parsed by JavaScript Date. The builder does not validate that startDate is before endDate.
Returns a date mention token:

Builder.dateTimeRange()

Creates a datetime range value from two ISO 8601 datetime strings that start with YYYY-MM-DDTHH:mm. If timeZone is provided, it is included as time_zone. The builder does not validate that startDateTime is before endDateTime.
Returns a date mention token:
Creates a text value with a link annotation.
Returns:

Builder.select()

Creates a select value from a single option name.
Returns:

Builder.multiSelect()

Creates a multi-select value from option names. Values are joined with commas. If no values are provided, returns an empty value.
Returns:

Builder.status()

Creates a status value from a status option name.
Returns:

Builder.people()

Creates a people value from email addresses.
Returns:

Builder.place()

Creates a place value. The value must include numeric lat and lon; otherwise the function throws.
Returns the provided place value.

Builder.relation()

Creates a relation reference from the primary key of a related record. Relation property values use arrays of relation references. Single relation:
Multiple relations:
Returns:

Builder.emojiIcon()

Creates an emoji icon.
Returns:

Builder.notionIcon()

Creates an icon using Notion’s native icon set. If color is omitted, it defaults to "gray".
Returns:

Builder.imageIcon()

Creates an image icon from an external URL.
Returns:

Builder.imageCover()

Creates an image cover from an external URL. position controls the vertical image position from 0 (top) to 1 (bottom). If omitted, position defaults to 0.5.
Returns: