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

# definePipeline

> Build a pipeline definition from declared fields, nodes, and connections.

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

declare function definePipeline<const DatasetName extends string>(
  definition: PipelineDefinitionInput<DatasetName>,
): PipelineDefinition<DatasetName>;
```

## Parameters

**definition** `PipelineDefinitionInput` *required*

The authored pipeline.

**Definition fields**

**dataset** `string`

Dataset name to bind during reconciliation. When omitted, `toloka apply` creates a new pipeline without creating or attaching a dataset. If the pipeline already has a dataset on the platform, omitting this property makes apply fail: it refuses to remove the binding. An empty string is rejected by `definePipeline`.

**fields** `readonly Field[]` *required*

Every field object referenced by the nodes. Reuse the same objects returned by [`field()`](https://docs.platform.toloka.ai/docs/sdk/reference/field).

**nodes** `readonly PipelineNode[]` *required*

Nodes built with [`root`](https://docs.platform.toloka.ai/docs/sdk/reference/root), [`code`](https://docs.platform.toloka.ai/docs/sdk/reference/code), [`generation`](https://docs.platform.toloka.ai/docs/sdk/reference/generation), [`quorum`](https://docs.platform.toloka.ai/docs/sdk/reference/quorum), or [`match`](https://docs.platform.toloka.ai/docs/sdk/reference/match).

**connections** `readonly Connection[]` *required*

Connections returned by [`connect()`](https://docs.platform.toloka.ai/docs/sdk/reference/connect).

## Returns

**definition** `PipelineDefinition\<DatasetName\>`

A definition for source loading and local testing. Export it as the default value of a `pipeline.ts` file under `pipelines/` for the CLI.

**Definition properties**

**dataset** `DatasetName | undefined`

The supplied dataset name.

**graph** `UnboundPipelineGraphV1`

A version 1 graph with fields, nodes, and connections. The root has no dataset ID or item filter yet.

## Throws

Throws a local error for an empty dataset name, duplicate field IDs, duplicate node IDs, a node that references an undeclared field object, or a connection whose source or target node is undeclared.

Construction does not perform full graph validation. The CLI validates definitions while loading source; use [`validate()`](https://docs.platform.toloka.ai/docs/sdk/reference/validate) for the graph contract and [local checks](https://docs.platform.toloka.ai/docs/sdk/testing.md) before applying.

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

const text = field("text", { type: "string" });
const boundary = root({ started: [text], completed: [text] });

export default definePipeline({
  dataset: "example-items",
  fields: [text],
  nodes: [boundary],
  connections: [connect(boundary.started, boundary.completed)],
});
```


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