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

# Create a Data Contract

> Create a new data contract for a data asset

# Create a Data Contract

Create a new data contract and attach it to a data asset. Only the `name` and `entity` reference are required — all other sections (schema, semantics, quality, SLA, security, terms of use) are optional.

## Body Parameters

**name** `string` *required*

Name of the data contract, 1 to 256 characters. The contract's fully qualified name is `<entityFQN>.dataContract_<name>`.

**entity** `object` *required*

Reference to the data asset this contract applies to. An entity can have only one contract.

**properties**

**id** `string` *required*

UUID of the entity.

**type** `string` *required*

Entity type. See [Supported Entity Types](https://docs.open-metadata.org/v2.1.x/api-reference/data-contracts.md#supported-entity-types).

The server stores the entity's own name and fully qualified name in the reference, so responses and change events carry them. Send `id` and `type`. A `name` or `fullyQualifiedName` that doesn't belong to the entity with that `id` returns `400`.

**displayName** `string`

Human-readable display name.

**description** `string`

Description in Markdown format.

**entityStatus** `string` (default: Draft)

Contract status: `Draft`, `In Review`, `Approved`, `Rejected`, `Deprecated`, or `Archived`.

**schema** `array`

Expected columns or fields. Supported for `table`, `topic`, `apiEndpoint`, and `dashboardDataModel` only. Each item follows the Column schema. Every name must exist on the entity, and no name can repeat.

**properties**

**name** `string` *required*

Column or field name.

**dataType** `string` *required*

Data type, for example `INT`, `VARCHAR`, or `TIMESTAMP`.

**dataLength** `integer`

Length for types such as `VARCHAR`.

**constraint** `string`

Constraint: `NULL`, `NOT_NULL`, `UNIQUE`, `PRIMARY_KEY`.

**description** `string`

Column description.

**semantics** `array`

Semantics rules evaluated against the entity's metadata when the contract is validated.

**properties**

**name** `string` *required*

Rule name.

**description** `string` *required*

Rule description. Reported as the failure reason when the rule fails.

**rule** `string` *required*

[JSON Logic](https://jsonlogic.com/) expression. The rule passes when it returns `true`.

**enabled** `boolean` (default: true)

Whether the rule is evaluated.

**entityType** `string`

Apply the rule only to this entity type.

**ignoredEntities** `array`

Entity types the rule skips.

**qualityExpectations** `array`

References to test cases that must pass. Supported for `table` only.

**properties**

**id** `string` *required*

UUID of the test case.

**type** `string` *required*

Must be `testCase`.

**sla** `object`

Service level agreement expectations. Stored and shown on the contract. Validation runs check it for tables, except retention.

**properties**

**refreshFrequency** `object`

`interval` (integer) and `unit`: `hour`, `day`, `week`, `month`, or `year`.

**maxLatency** `object`

`value` (integer) and `unit`: `minute`, `hour`, or `day`.

**availabilityTime** `string`

Time of day the data should be available, for example `09:00`.

**timezone** `string` (default: GMT+00:00 (Europe/London))

Timezone for `availabilityTime`, in the form `GMT+05:30 (Asia/Kolkata)`.

**retention** `object`

`period` (integer) and `unit`: `day`, `week`, `month`, or `year`.

**columnName** `string`

Column that holds the data's refresh time.

**termsOfUse** `string`

Terms of use in Markdown format. Describes allowed and disallowed uses and compliance requirements. Returned as `termsOfUse.content` on the contract.

**security** `object`

Security and access expectations. Stored and shown on the contract, but not enforced.

**properties**

**dataClassification** `string`

Classification of the data, for example `PII` or `Confidential`.

**policies** `array`

Access policies. Each has `accessPolicy` (policy name), `identities` (consumer groups or users), and `rowFilters` (a list of `columnName` and `values`).

**owners** `array`

Owner references (users or teams).

**reviewers** `array`

Reviewer references (users or teams). When set, only a reviewer can move the contract from `In Review` to `Approved` or `Rejected`.

**effectiveFrom** `string`

Date and time from which this contract is effective. Informational only.

**effectiveUntil** `string`

Date and time until which this contract is effective. Informational only.

**sourceUrl** `string`

Link to where the contract is maintained.

```python POST /v1/dataContracts theme={null}
from metadata.sdk import configure
from metadata.sdk.entities import DataContracts
from metadata.generated.schema.api.data.createDataContract import (
    CreateDataContractRequest,
)

configure(
    host="https://your-company.open-metadata.org/api",
    jwt_token="your-jwt-token"
)

request = CreateDataContractRequest.model_validate({
    "name": "sales-orders-contract",
    "entity": {"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "type": "table"},
    "description": "Data contract for the sales orders table",
    "entityStatus": "Approved",
    "schema": [
        {"name": "order_id", "dataType": "INT", "constraint": "PRIMARY_KEY"},
        {"name": "order_date", "dataType": "TIMESTAMP", "constraint": "NOT_NULL"},
    ],
    "semantics": [
        {
            "name": "Owners is set",
            "description": "The table must have an owner.",
            "rule": '{"and":[{"some":[{"var":"owners"},{"!=":[{"var":"fullyQualifiedName"},null]}]}]}',
            "enabled": True,
        }
    ],
    "sla": {"refreshFrequency": {"interval": 1, "unit": "day"}},
})
contract = DataContracts.create(request)
print(f"Created contract: {contract.fullyQualifiedName.root}")
```

```java POST /v1/dataContracts theme={null}
import static org.openmetadata.sdk.fluent.DataContracts.*;

DataContract contract = create()
    .name("sales-orders-contract")
    .forEntity(new EntityReference()
        .withId(tableId)
        .withType("table"))
    .withDescription("Data contract for the sales orders table")
    .withStatus(EntityStatus.APPROVED)
    .withSchema(List.of(
        new Column().withName("order_id").withDataType(ColumnDataType.INT),
        new Column().withName("order_date").withDataType(ColumnDataType.TIMESTAMP)
    ))
    .withSemanticRule(new SemanticsRule()
        .withName("Owners is set")
        .withDescription("The table must have an owner.")
        .withRule("{\"and\":[{\"some\":[{\"var\":\"owners\"},{\"!=\":[{\"var\":\"fullyQualifiedName\"},null]}]}]}"))
    .withSla(new ContractSLA()
        .withRefreshFrequency(new RefreshFrequency()
            .withInterval(1)
            .withUnit(RefreshFrequency.Unit.DAY)))
    .execute();
```

```bash POST /v1/dataContracts theme={null}
curl -X POST "{base_url}/api/v1/dataContracts" \
  -H "Authorization: Bearer {access_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "sales-orders-contract",
    "entity": {
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "type": "table"
    },
    "description": "Data contract for the sales orders table",
    "entityStatus": "Approved",
    "schema": [
      {"name": "order_id", "dataType": "INT", "constraint": "PRIMARY_KEY"},
      {"name": "order_date", "dataType": "TIMESTAMP", "constraint": "NOT_NULL"}
    ],
    "semantics": [
      {
        "name": "Owners is set",
        "description": "The table must have an owner.",
        "rule": "{\"and\":[{\"some\":[{\"var\":\"owners\"},{\"!=\":[{\"var\":\"fullyQualifiedName\"},null]}]}]}",
        "enabled": true
      }
    ],
    "sla": {
      "refreshFrequency": {"interval": 1, "unit": "day"}
    }
  }'
```

```json Response theme={null}
{
  "id": "f7a1b2c3-d4e5-6789-0abc-def123456789",
  "name": "sales-orders-contract",
  "fullyQualifiedName": "sample_data.ecommerce_db.shopify.sales_orders.dataContract_sales-orders-contract",
  "description": "Data contract for the sales orders table",
  "entityStatus": "Approved",
  "entity": {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "type": "table",
    "name": "sales_orders",
    "fullyQualifiedName": "sample_data.ecommerce_db.shopify.sales_orders"
  },
  "schema": [
    {"name": "order_id", "dataType": "INT", "constraint": "PRIMARY_KEY"},
    {"name": "order_date", "dataType": "TIMESTAMP", "constraint": "NOT_NULL"}
  ],
  "semantics": [
    {
      "name": "Owners is set",
      "description": "The table must have an owner.",
      "rule": "{\"and\":[{\"some\":[{\"var\":\"owners\"},{\"!=\":[{\"var\":\"fullyQualifiedName\"},null]}]}]}",
      "enabled": true
    }
  ],
  "sla": {
    "refreshFrequency": {"interval": 1, "unit": "day"}
  },
  "version": 0.1,
  "updatedAt": 1769982800000,
  "updatedBy": "admin"
}
```

***

## Upsert (Create or Update)

Use `PUT /v1/dataContracts` with the same body to create a new contract or update an existing one.

***

## Error Handling

| Code | Error Type | Description |
| - | - | - |
| `400` | `BAD_REQUEST` | Invalid request body, an entity type or section the entity doesn't support, schema columns the entity doesn't have, or an entity that already has a contract |
| `401` | `UNAUTHORIZED` | Invalid or missing authentication token |
| `403` | `FORBIDDEN` | User lacks permission to create data contracts |
| `404` | `NOT_FOUND` | The referenced entity doesn't exist |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.