---
title: "Schema and tag families"
description: "Define custom models, custom fields, tag families, and CI checks inside an extension and satisfy the invariants that every publication checks."
---

> Documentation Index
> Fetch the complete documentation index at: https://buildrforge.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Schema and tag families

An extension can package custom models, custom fields, tag families, tags, and CI checks so that every repo in the organization can install the same data structure and hold its data to the same rules.

## Extension-owned schema and tags

Ownership of a custom model or tag family is fixed when you create it. Standard creation endpoints (`POST .../custom-models` and `POST .../tag-families`) assign ownership to the repo itself. To assign a custom model or tag family to an extension instead, use the extension-scoped creation endpoints:

- **Create an extension custom model**: `POST /repos/:repo_id/branches/:branch/extensions/:extension_name/custom-models` (`forge custom-models create-extension-custom-model`).
- **Create an extension tag family**: `POST /repos/:repo_id/branches/:branch/extensions/:extension_name/tag-families` (`forge tags create-extension-tag-family`).
- **Create an extension CI check**: `POST /repos/:repo_id/branches/:branch/extensions/:extension_name/ci-checks` (`forge ci-checks create-extension-ci-check`). See [CI checks in an extension](#ci-checks-in-an-extension).

A `picklist` or `multi_picklist` custom field lists its choices as `options`, a non-empty array of unique strings. A record holds one of them as a `picklist` value, such as `"approved"`, and an array of them as a `multi_picklist` value. See [Schema and records](https://buildrforge.com/docs/introduction/schema-and-records/) for every field type.

Once the custom model or tag family exists, you add custom fields to the model and tags to the tag family using the standard custom field and tag endpoints:

```sh
# Create an extension
forge extensions create-extension --repo "$REPO" --branch main \
  --data '{"name":"procurement","description":"Standard order line items and cost centers"}'

# Create a custom model owned by procurement
forge custom-models create-extension-custom-model --repo "$REPO" --branch main --extension procurement --data '{
  "name": "Line item",
  "fields": [
    { "name": "Description", "type": "text", "required": true, "default_value": "TBD" },
    { "name": "Quantity", "type": "decimal", "default_value": 1 },
    { "name": "Unit cost", "type": "currency", "default_value": 0 },
    { "name": "Status", "type": "picklist", "options": ["draft", "approved"], "default_value": "draft" },
    { "name": "Amount", "formula": "Math.round(ctx.record.values.quantity * ctx.record.values.unit_cost)" }
  ]
}'

# Create a tag family owned by procurement and add a tag
FAMILY_ID=$(forge tags create-extension-tag-family --repo "$REPO" --branch main --extension procurement \
  --data '{"name":"Cost centers","kind":"tree"}' | jq -r .id)

forge tags create-tag --repo "$REPO" --branch main --family "$FAMILY_ID" \
  --data '{"name":"Engineering","code":"ENG","parent_id":null,"position":0}'
```

## CI checks in an extension

An extension can carry [CI checks](https://buildrforge.com/docs/introduction/ci-checks/), stdlib or custom, so that every repo that installs it holds its data to the same rules. Create one with the extension-scoped endpoint. It takes the same payload as `POST .../ci-checks`:

```sh
forge ci-checks create-extension-ci-check --repo "$REPO" --branch main --extension procurement --data '{
  "name": "Cost center codes nest",
  "description": "A cost center code extends its parent code.",
  "kind": "stdlib",
  "stdlib_function_key": "tag_code_prefix",
  "stdlib_config": { "family_id": "'"$FAMILY_ID"'" },
  "severity": "required"
}'
```

An extension CI check works like the repo's own CI checks:

- **The defining repo runs it**: The CI check runs on the defining repo's commits and gates its change requests, like any CI check of the repo's.
- **Every version carries it**: A commit that adds, edits, or deletes an extension CI check publishes a new version of the extension, as a change to its schema does.
- **Installing copies it**: Installing a version copies its CI checks into the installing repo, which runs them on its own commits. See [Installing and updating](https://buildrforge.com/docs/extensions/installing-and-updating/).

A stdlib CI check's `stdlib_config` names tag families, tags, and custom fields by ID. Installing copies them under IDs of the installing repo's own, so the copied CI check names the installing repo's copies instead. Name only the extension's own tag families, tags, and custom fields in an extension CI check: an ID outside the extension isn't copied, and the installing repo's runs report the record as missing. A custom CI check reads custom models by `apiName`, which an installed copy keeps.

## Namespaces and API names

Extension custom models and tag families follow distinct naming rules:

- **Extensions have qualified names**: Outside its own repo's source, an extension is named `<repo slug>.<name>`: the slug of the repo that defines it, a dot, and its name, so two repos can publish extensions with the same name. The `procurement` extension of the `acme-standards` repo publishes to the registry as `acme-standards.procurement`, and installations, policies, and peers name it that way, the defining repo's own policies included. The branch endpoints under `/repos/:repo_id/branches/:branch/extensions/:name` take the name alone, `procurement`.
- **Custom model API names are namespaced**: An extension model's `api_name` begins with the snake_case extension name, without the repo slug, followed by a double underscore, such as `procurement__line_item`. Whenever you address the model in API paths, record operations, reference `target_model` settings, or formulas, use that full `api_name` (for example, `ctx.state.models.procurement__line_item.records`).
- **Tag family, CI check, and agent skill names are unqualified**: Tag families, CI checks, and agent skills keep their plain `name` (such as `"Cost centers"`), which must be unique across all tag families, all CI checks, or all agent skills in the repo. Installing an extension whose CI check or agent skill shares a name with one of the installing repo's own is refused with `WriteRefused`.
- **Renames before the first release**: You can rename an extension with `PATCH /repos/:repo_id/branches/:branch/extensions/:name` until its repo releases it. Renaming the extension updates the `api_name` prefix of all custom models owned by that extension. Once released, the extension's name is permanent and renaming fails with `ExtensionReleased`.

## Schema invariants that every publication checks

Any repo in the organization can install an extension and later update that installation while holding business records. To keep every installation valid, each commit's publication of an extension checks three invariants before it admits a version to the registry. A publication that fails one is `failed` with the refusal as its `failure`, in `GET /repos/:repo_id/commits/:commit_id/extension-publications`, and the branch's tools and UI answer that refusal until a commit fixes it:

### 1. Required custom fields must have a default value

If an extension adds a `required` custom field in a higher version, updating an installation in a repo that already holds records must populate that custom field on stored rows. Therefore, every `required: true` custom field on an extension custom model must declare a non-null `default_value`.

If any required custom field in the extension lacks a `default_value`, the publication fails with `ExtensionRequiredFieldWithoutDefault` and lists the offending custom fields in `custom_fields`.

Because `reference`, `user`, and `formula` custom fields, as well as custom fields with `unique: true`, do not accept a `default_value`, they cannot be marked `required: true` on an extension model. Make them optional instead.

### 2. Schema must be self-contained

An extension is installed into other repos without copying the source repo's own models. If an extension custom model has a `reference` custom field or a `formula` custom field that references a custom model outside the extension (such as a repo-owned model or another extension's model), the publication fails with `ExtensionNotSelfContained` and lists the external dependencies in `dependencies`.

To fix `ExtensionNotSelfContained`, create the referenced target custom model inside the same extension and point the reference or formula at that extension model's `api_name`.

A model of a peer is the exception. When the extension's `package.json` declares another extension as a peer and the repo installs it, a `reference` or `formula` custom field may point at the installed peer's model. Each repo that installs both extensions points the custom field at its own installation of the peer. The installed peer must have that model: beside a release of the peer that lacks it, such as one from before the peer added it, installing or updating your extension fails with `ExtensionDependenciesUnmet`, naming the custom fields that reference the model, until the repo updates the peer. See [Installing and updating](https://buildrforge.com/docs/extensions/installing-and-updating/) for peers.

An extension's `reference` custom field can't point at another repo either. A custom field declaration on an extension model that sets `target_repo` fails as an invalid request when you create it, before any publication runs.

### 3. Name ownership

The registry keeps each qualified name for the repo that first published it, a prerelease included, and refuses another repo's publication under that name with `ExtensionNameTaken`. A qualified name starts with the defining repo's slug, so extensions of two repos can share a name without meeting this refusal.

## Releases and prereleases

A change to an extension's schema reaches other repos as any change to it does: a commit to `main` whose extension version is higher than the extension's latest release publishes that release, and every other commit publishes a prerelease that only the defining repo runs. [The authoring lifecycle](https://buildrforge.com/docs/extensions/authoring-overview/#the-authoring-lifecycle) shows how to raise the version and release it.

Source: https://buildrforge.com/docs/extensions/schema-and-tags/index.mdx
