Configure Dataset schemas via API

Last updated: February 20, 2026

Prerequisites

Plans: Any

Deployments: Any

Use case: Datasets with JSON schema validation

Use case

In order to add schemas to your Datasets, with the API.

Features used

The /v1/dataset endpoint.

Steps

Create dataset with schema

const options = {
  method: "POST",
  headers: {
    Authorization: "Bearer <your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    project_id: "<project-id>",
    name: "<dataset-name>",
    metadata: {
      __schemas: {
        input: {
          type: "object",
          properties: {
            postal: { type: "number" },
          },
          additionalProperties: false,
          enforce: true
        },
      },
    },
  }),
};

fetch("https://api.braintrust.dev/v1/dataset/<dataset-id>", options)
  .then((res) => res.json())
  .then((res) => console.log(res));

Update existing dataset schema

const options = {
  method: "PATCH",
  headers: {
    Authorization: "Bearer <your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    metadata: {
      __schemas: {
        input: {
          type: "object",
          properties: {
            postal: { type: "number" },
          },
          additionalProperties: false,
          enforce: true
        },
      },
    },
  }),
};

fetch("https://api.braintrust.dev/v1/dataset/<dataset-id>", options)
  .then((res) => res.json())
  .then((res) => console.log(res));

Retrieve existing schema

const options = {
  method: "GET",
  headers: {
    Authorization: "Bearer <your-api-key>",
  },
};

fetch("https://api.braintrust.dev/v1/dataset/<dataset-id>", options)
  .then((res) => res.json())
  .then((res) => console.log(res.metadata.__schemas));

If you need an example of what the structure of the schemas should look like you can leverage the UI through the Field schemas button in the top right of a Dataset as a testing ground.