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

# field

> Declare a named field with a JSON Schema and mark optional bindings with optional().

```ts theme={null}
import type { AuthoringIdOptions, Field, JsonSchema, OptionalFieldBinding } from "@toloka-platform/sdk";

declare function field<const Name extends string>(
  name: Name,
  jsonSchema: JsonSchema,
  options?: AuthoringIdOptions,
): Field<Name>;

declare function optional(referencedField: Field): OptionalFieldBinding;
```

## Parameters

**name** `string` *required*

The field name. Its literal type is retained in `Field<Name>`.

**jsonSchema** `JsonSchema` *required*

The JSON Schema for field values. For example, `{ type: "string" }` or `{ type: "array", items: { type: "string" } }`.

**options** `AuthoringIdOptions` (default: \{})

Optional identity override.

**Options**

**id** `string`

Explicit graph field ID. Otherwise the ID is derived deterministically from the name.

## Returns

**field** `Field\<Name\>`

A field definition. Reuse this object in node settings and `definePipeline({ fields })`.

**Field properties**

**id** `string`

The graph field ID.

**name** `Name`

The supplied name.

**jsonSchema** `JsonSchema`

The supplied schema.

`field()` constructs a definition; it does not create a dataset field or validate the schema against the platform. Use [pipeline reconciliation](https://docs.platform.toloka.ai/docs/sdk/pipelines.md#check-plan-and-apply) to create it on the platform.

## Optional bindings

`optional(referencedField)` takes one required `Field` and returns `{ field: referencedField, optional: true }`. It changes the binding's optionality without changing the field's schema. Use it in a root's `started` or `completed` list, or a Code or Match node's field bindings.

For required Code and Match bindings, use `{ field, optional: false }`. Root lists also accept a bare field as a required binding. Generation and Quorum entities use an `optional` property on the entity object.

```ts theme={null}
import { field, optional, root } from "@toloka-platform/sdk";

const text = field("text", { type: "string" });
const note = field("note", { type: "string" }, { id: "note" });

const boundary = root({
  started: [text, optional(note)],
  completed: [text],
});

console.log(note.name, boundary.id);
```

The `note` field's data properties:

```json theme={null}
{
  "id": "note",
  "name": "note",
  "jsonSchema": { "type": "string" }
}
```


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