Skip to content

Commit 7c5e6f1

Browse files
committed
add docs
1 parent 6660ac4 commit 7c5e6f1

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

py/src/braintrust/dataset_pipeline.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,70 @@
2525

2626

2727
class DatasetPipelineSource(TypedDict, total=False):
28+
"""Information about what spans or traces should be passed into the dataset pipeline."""
29+
2830
project_id: str
31+
"""Project ID to take spans or traces from. Takes precedence over project_name."""
2932
project_name: str
33+
"""Project name to take spans or traces from."""
3034
org_name: str
35+
"""Organization name to take spans or traces from."""
3136
filter: str
37+
"""Optional BTQL filter. When omitted, all spans or traces are eligible."""
3238
scope: DatasetPipelineScope
39+
"""Whether to pass spans or entire traces to the pipeline. Defaults to "span"."""
3340

3441

3542
class DatasetPipelineTarget(TypedDict):
43+
"""Information about the target dataset."""
44+
3645
dataset_name: str
46+
"""Dataset name. This can be an existing dataset name or a name to create."""
3747
project_id: NotRequired[str]
48+
"""Project ID where the dataset lives or should be created."""
3849
project_name: NotRequired[str]
50+
"""Project name where the dataset lives or should be created."""
3951
org_name: NotRequired[str]
52+
"""Organization name where the dataset lives or should be created."""
4053
description: NotRequired[str]
54+
"""Dataset description to use when creating the dataset."""
4155
metadata: NotRequired[Metadata]
56+
"""Dataset metadata to use when creating the dataset."""
4257

4358

4459
class DatasetPipelineRow(TypedDict, total=False):
60+
"""A row returned by a dataset pipeline transform."""
61+
4562
id: str
63+
"""Stable row ID for the target dataset. Defaults to the source span or trace ID."""
4664
input: Any | None
65+
"""Input value for the target dataset row."""
4766
expected: Any | None
67+
"""Expected value for the target dataset row."""
4868
tags: Sequence[str] | None
69+
"""Tags for the target dataset row."""
4970
metadata: Metadata | None
71+
"""Metadata for the target dataset row."""
5072

5173

5274
Row = TypeVar("Row", bound=DatasetPipelineRow, covariant=True)
5375

5476

5577
class DatasetPipelineTransformArgs(TypedDict, total=False):
78+
"""Arguments passed to a dataset pipeline transform."""
79+
5680
id: str
81+
"""Source span row ID for span-scoped transforms."""
5782
input: Any | None
83+
"""Source span input for span-scoped transforms."""
5884
output: Any | None
85+
"""Source span output for span-scoped transforms."""
5986
metadata: Metadata | None
87+
"""Source span metadata for span-scoped transforms."""
6088
expected: Any | None
89+
"""Source span expected value for span-scoped transforms."""
6190
trace: Trace
91+
"""Source trace. This is always available."""
6292

6393

6494
DatasetPipelineTransformResult: TypeAlias = Row | Sequence[Row] | None
@@ -78,6 +108,8 @@ def __call__(
78108

79109
@dataclass(frozen=True)
80110
class DatasetPipelineDefinition(Generic[Row]):
111+
"""A registered dataset pipeline definition consumed by the bt CLI."""
112+
81113
source: DatasetPipelineSource
82114
transform: DatasetPipelineTransform[Row]
83115
target: DatasetPipelineTarget
@@ -94,9 +126,25 @@ def DatasetPipeline(
94126
transform: DatasetPipelineTransform[DatasetPipelineRow],
95127
target: DatasetPipelineTarget,
96128
) -> DatasetPipelineDefinition[DatasetPipelineRow]:
129+
"""Create a runnable dataset pipeline.
130+
131+
Dataset pipelines take trace data stored in Braintrust, filter and transform it,
132+
and feed it back into a Braintrust dataset.
133+
134+
Run a dataset pipeline with the bt CLI:
135+
136+
bt datasets pipeline run path/to/pipeline.py --limit 100
137+
138+
The limit controls how many spans or traces, depending on source["scope"], are
139+
discovered for the pipeline.
140+
141+
This API is experimental and may change or be removed across non-major versions.
142+
"""
143+
stored_source = source.copy()
144+
stored_source["scope"] = stored_source.get("scope", "span")
97145
definition = DatasetPipelineDefinition(
98146
name=name,
99-
source=source.copy(),
147+
source=stored_source,
100148
transform=transform,
101149
target=target.copy(),
102150
)

0 commit comments

Comments
 (0)