> ## 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.

# generation

> Create an authored Generation node using field objects in its entity settings.

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

declare function generation(
  name: string,
  settings: GenerationAuthoringSettings,
  options?: AuthoringIdOptions,
): AuthoredGenerationNode;
```

## Parameters

**name** `string` *required*

Name used to derive the node ID and, unless overridden, `settings.about.name`.

**settings** `GenerationAuthoringSettings` *required*

Configure the work using the [Generation node reference](https://docs.platform.toloka.ai/docs/data/reference/nodes/generation.md). The authoring form uses `Field` objects in place of field IDs.

**Authoring fields and defaults**

**publicName** `string` *required*

Display name for the work.

**entities** `object` *required*

Required `input` and `output` arrays with the [entity-binding shape](#entity-bindings) below. Entity relations also use `field` objects.

**Entity arrays**

**input** `readonly GenerationInputEntity[]` *required*

Entities supplied to the node.

**output** `readonly GenerationOutputEntity[]` *required*

Entities produced by the node.

**about** `object`

Optional name override, description, and project type.

**qualityCriteria** `array` (default: \[])

Each criterion's `targetEntity` is a `Field` object.

**instruction** `string` (default: empty string)

Expert instructions.

**ui** `GenerationNodeSettings['ui']`

Defaults to an empty interface with empty data and constants.

**onboarding** `GenerationNodeSettings['onboarding']`

Defaults to enabled onboarding with one text step and no quiz. Replace it with a complete course before applying an enabled course.

**exam** `object`

Uses a `Field` object for each graded entity's `targetEntity`.

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

Optional identity override.

**Options**

**id** `string`

Explicit graph node ID. Otherwise derived from the node type and name.

Audience, pricing, quality assurance, and platform checks retain the settings described in the [node reference](https://docs.platform.toloka.ai/docs/data/reference/nodes/generation.md).

## Entity bindings

Generation and [Quorum](https://docs.platform.toloka.ai/docs/sdk/reference/quorum.md) use the following properties for each input or output entity.

**field** `Field` *required*

Declared field object.

**entityType** `string` *required*

One of the supported values:

`JUDGEMENT`, `EXPLANATION`, `PROMPT`, `USER_PROMPT`, `RESPONSE`, `RESPONSE_EVALUATION`, `RUBRIC`, `RUBRICS_GROUP`, `DIALOG`, `DIALOG_STEP`, `DIALOG_EVALUATION`, `SHORT_ANSWER`, `FEEDBACK`, `CONTEXT`, `IMAGE`, `ANNOTATION`, `SINGLE_LABEL`, `MULTI_LABEL`, `VIDEO`, `DOCUMENT`, `GOLDEN_SET`, `LOGS`, `SOLUTION`, `CODE`, `METADATA`, `AUDIO`, `AGENT_TRAJECTORY`, `MCP_SERVER`, `CONTAINER`, or `CUSTOM`.

**optional** `boolean` (default: false)

Whether the entity binding is optional.

**jsonPath** `string` (default: \$)

Path used to extract the entity value. Dynamic entities require exactly one `[*]` wildcard; static entities cannot use that wildcard.

**description** `string` (default: empty string)

Entity description. Fill it before applying the node for labeling work.

**relations** `array` (default: \[])

Relations to other entities, using `field` and `rel_type`. For example, `{ field: prompt, rel_type: "references" }` relates an output to its prompt. See the [node reference](https://docs.platform.toloka.ai/docs/data/reference/nodes/generation.md) for relation behavior.

**allowedLabels** `\{ label: string; value: string \}[]`

Choices for label entities. Output entities with `entityType: "SINGLE_LABEL"` or `"MULTI_LABEL"` require at least two entries.

**Label fields**

**label** `string` *required*

Display text.

**value** `string` *required*

Stored value, using lowercase letters or digits separated by single underscores, such as `needs_review`.

**dynamic** `boolean` (default: false)

Whether this binding represents multiple entity values. A dynamic entity's field needs an array JSON schema.

**maxEntities** `number | null`

For `dynamic: true`, supply an integer from 1 to 50. The SDK type permits omission or `null`, but platform validation requires the bound. When `dynamic` is false or omitted, only `null` or omission is allowed.

**minDurationSeconds** `number`

Optional minimum media duration in seconds.

**maxDurationSeconds** `number`

Optional maximum media duration in seconds.

This binding example declares a single label and up to three explanations. A Quorum output field needs an additional outer array for the collected annotations; see [Quorum entity fields](https://docs.platform.toloka.ai/docs/sdk/reference/quorum.md#entity-fields).

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

const prompt = field("prompt", { type: "string" });
const decision = field("decision", {
  type: "string",
  enum: ["accept", "needs_review"],
});
const explanations = field("explanations", {
  type: "array",
  items: { type: "string" },
});

export const entities: GenerationAuthoringSettings["entities"] = {
  input: [{ field: prompt, entityType: "PROMPT", description: "Question to assess" }],
  output: [
    {
      field: decision,
      entityType: "SINGLE_LABEL",
      description: "Whether the question is ready to use",
      allowedLabels: [
        { label: "Accept", value: "accept" },
        { label: "Needs review", value: "needs_review" },
      ],
      relations: [{ field: prompt, rel_type: "evaluates" }],
    },
    {
      field: explanations,
      entityType: "EXPLANATION",
      description: "Reasons for the decision",
      dynamic: true,
      maxEntities: 3,
      jsonPath: "$.explanations[*]",
      relations: [{ field: decision, rel_type: "references" }],
    },
  ],
};
```

## Returns

**node** `AuthoredGenerationNode`

A Generation node with compiled entity references and constructor defaults.

**Node properties**

**id** `string`

Graph node ID.

**type** `'generation'`

Node type.

**settings** `GenerationNodeSettings`

Compiled node settings.

**input** `InputPort`

Port for incoming connections.

**output** `OutputPort`

Port for outgoing connections.

The constructor does not validate readiness for a run. Configure the node, add [local tests](https://docs.platform.toloka.ai/docs/sdk/testing.md), and use the [check and apply workflow](https://docs.platform.toloka.ai/docs/sdk/pipelines.md#check-plan-and-apply).

The interface displays the prompt above the answer control. Configure instructions, onboarding, and the work settings before applying it.

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

const prompt = field("prompt", { type: "string" });
const answer = field("answer", { type: "string" });

export const annotate = generation("annotate", {
  publicName: "Answer a question",
  entities: {
    input: [{ field: prompt, entityType: "PROMPT" }],
    output: [{ field: answer, entityType: "RESPONSE" }],
  },
  ui: {
    code: '<View.Flex vertical gap="1rem"><View.Text>{actions.get("prompt", "")}</View.Text><Field.Textarea path="answer" label="Answer" /></View.Flex>',
    data: '{"prompt":"What is two plus two?"}',
    preprocess: "return {};",
    postprocess: "return {};",
    constants: "{}",
  },
});
```


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