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

# Configure dataset schemas via API

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = undefined

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

## Summary

**Goal:** Configure dataset schemas programmatically via API using the metadata.\_\_schemas field.

**Features:** Dataset API endpoints, metadata.\_\_schemas field, JSON Schema validation with enforce flag.

## Configuration Steps

### Step 1: Create dataset with schema

POST to /v1/dataset with \_\_schemas in metadata field.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
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", options)
  .then((res) => res.json())
  .then((res) => console.log(res));

```

### Step 2: Update existing dataset schema

PATCH to /v1/dataset/{dataset-id} with \_\_schemas in metadata field.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
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));

```

### Step 3: Retrieve existing schema

GET from /v1/dataset/{dataset-id} to view current schema configuration.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
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));

```

### Step 4: Copy schema structure from UI

Create schema in UI first, then GET the dataset to copy the \_\_schemas object structure for programmatic use.
