RunTree#

class langsmith.run_trees.RunTree[source]#

Bases: RunBase

Run Schema with back-references for posting runs.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param attachments: Attachments [Optional]#

Attachments associated with the run. Each entry is a tuple of (mime_type, bytes).

param child_runs: List[RunTree] [Optional]#
param dotted_order: str = ''#

The order of the run in the tree.

param end_time: datetime | None = None#

End time of the run, if applicable.

param error: str | None = None#

Error message, if the run encountered any issues.

param events: List[Dict] [Optional]#

List of events associated with the run, like start and end events.

param extra: Dict [Optional]#

Additional metadata or settings related to the run.

param id: UUID [Optional]#

Unique identifier for the run.

param inputs: dict [Optional]#

Inputs used for the run.

param ls_client: Any | None = None#
param name: str [Required]#

Human-readable name for the run.

param outputs: dict | None = None#

Outputs generated by the run, if any.

param parent_run: RunTree | None = None#
param parent_run_id: UUID | None = None#

Identifier for a parent run, if this run is a sub-run.

param reference_example_id: UUID | None = None#

Reference to an example that this run may be based on.

param run_type: str = 'chain'#

The type of run, such as tool, chain, llm, retriever, embedding, prompt, parser.

param serialized: dict | None = None#

Serialized object that executed the run for potential reuse.

param session_id: UUID | None = None (alias 'project_id')#
param session_name: str [Optional] (alias 'project_name')#
param start_time: datetime [Optional]#

Start time of the run.

param tags: List[str] | None [Optional]#

Tags for categorizing or annotating the run.

param trace_id: UUID = ''#

The trace id of the run.

add_event(events: RunEvent | Sequence[RunEvent] | Sequence[dict] | dict | str) None[source]#

Add an event to the list of events.

Parameters:
  • (Union[ls_schemas.RunEvent (events) – Sequence[dict], dict, str]): The event(s) to be added. It can be a single event, a sequence of events, a sequence of dictionaries, a dictionary, or a string.

  • Sequence[ls_schemas.RunEvent] – Sequence[dict], dict, str]): The event(s) to be added. It can be a single event, a sequence of events, a sequence of dictionaries, a dictionary, or a string.

  • events (RunEvent | Sequence[RunEvent] | Sequence[dict] | dict | str) –

Return type:

None

:paramSequence[dict], dict, str]):

The event(s) to be added. It can be a single event, a sequence of events, a sequence of dictionaries, a dictionary, or a string.

Returns:

None

Parameters:

events (RunEvent | Sequence[RunEvent] | Sequence[dict] | dict | str) –

Return type:

None

add_metadata(metadata: Dict[str, Any]) None[source]#

Add metadata to the run.

Parameters:

metadata (Dict[str, Any]) –

Return type:

None

add_outputs(outputs: Dict[str, Any]) None[source]#

Upsert the given outputs into the run.

Parameters:

outputs (Dict[str, Any]) – A dictionary containing the outputs to be added.

Returns:

None

Return type:

None

add_tags(tags: Sequence[str] | str) None[source]#

Add tags to the run.

Parameters:

tags (Sequence[str] | str) –

Return type:

None

create_child(name: str, run_type: Literal['tool', 'chain', 'llm', 'retriever', 'embedding', 'prompt', 'parser'] = 'chain', *, run_id: UUID | str | None = None, serialized: Dict | None = None, inputs: Dict | None = None, outputs: Dict | None = None, error: str | None = None, reference_example_id: UUID | None = None, start_time: datetime | None = None, end_time: datetime | None = None, tags: List[str] | None = None, extra: Dict | None = None, attachments: Dict[str, Tuple[str, bytes] | Attachment] | None = None) RunTree[source]#

Add a child run to the run tree.

Parameters:
  • name (str) –

  • run_type (Literal['tool', 'chain', 'llm', 'retriever', 'embedding', 'prompt', 'parser']) –

  • run_id (UUID | str | None) –

  • serialized (Dict | None) –

  • inputs (Dict | None) –

  • outputs (Dict | None) –

  • error (str | None) –

  • reference_example_id (UUID | None) –

  • start_time (datetime | None) –

  • end_time (datetime | None) –

  • tags (List[str] | None) –

  • extra (Dict | None) –

  • attachments (Dict[str, Tuple[str, bytes] | Attachment] | None) –

Return type:

RunTree

end(*, outputs: Dict | None = None, error: str | None = None, end_time: datetime | None = None, events: Sequence[RunEvent] | None = None, metadata: Dict[str, Any] | None = None) None[source]#

Set the end time of the run and all child runs.

Parameters:
  • outputs (Dict | None) –

  • error (str | None) –

  • end_time (datetime | None) –

  • events (Sequence[RunEvent] | None) –

  • metadata (Dict[str, Any] | None) –

Return type:

None

classmethod from_dotted_order(dotted_order: str, **kwargs: Any) RunTree[source]#

Create a new β€˜child’ span from the provided dotted order.

Returns:

The new span.

Return type:

RunTree

Parameters:
  • dotted_order (str) –

  • kwargs (Any) –

classmethod from_headers(headers: Mapping[str | bytes, str | bytes], **kwargs: Any) RunTree | None[source]#

Create a new β€˜parent’ span from the provided headers.

Extracts parent span information from the headers and creates a new span. Metadata and tags are extracted from the baggage header. The dotted order and trace id are extracted from the trace header.

Returns:

The new span or None if

no parent span information is found.

Return type:

Optional[RunTree]

Parameters:
  • headers (Mapping[str | bytes, str | bytes]) –

  • kwargs (Any) –

classmethod from_runnable_config(config: dict | None, **kwargs: Any) RunTree | None[source]#

Create a new β€˜child’ span from the provided runnable config.

Requires langchain to be installed.

Returns:

The new span or None if

no parent span information is found.

Return type:

Optional[RunTree]

Parameters:
  • config (dict | None) –

  • kwargs (Any) –

get_url() str[source]#

Return the URL of the run.

Return type:

str

patch() None[source]#

Patch the run tree to the API in a background thread.

Return type:

None

post(exclude_child_runs: bool = True) None[source]#

Post the run tree to the API asynchronously.

Parameters:

exclude_child_runs (bool) –

Return type:

None

to_headers() Dict[str, str][source]#

Return the RunTree as a dictionary of headers.

Return type:

Dict[str, str]

wait() None[source]#

Wait for all _futures to complete.

Return type:

None

property client: Client#

Return the client.

property metadata: dict[str, Any]#

Retrieve the metadata (if any).

property revision_id: UUID | None#

Retrieve the revision ID (if any).