Run Trees
run_trees
¶
Schemas for the LangSmith API.
RunTree
¶
Bases: RunBase
Run Schema with back-references for posting runs.
| METHOD | DESCRIPTION |
|---|---|
infer_defaults |
Assign name to the run. |
ensure_dotted_order |
Ensure the dotted order of the run. |
__setattr__ |
Set the |
set |
Set the inputs, outputs, tags, and metadata of the run. |
add_tags |
Add tags to the run. |
add_metadata |
Add metadata to the run. |
add_outputs |
Upsert the given outputs into the run. |
add_inputs |
Upsert the given inputs into the run. |
add_event |
Add an event to the list of events. |
end |
Set the end time of the run and all child runs. |
create_child |
Add a child run to the run tree. |
post |
Post the run tree to the API asynchronously. |
patch |
Patch the run tree to the API in a background thread. |
wait |
Wait for all |
get_url |
Return the URL of the run. |
from_dotted_order |
Create a new 'child' span from the provided dotted order. |
from_runnable_config |
Create a new 'child' span from the provided runnable config. |
from_headers |
Create a new 'parent' span from the provided headers. |
to_headers |
Return the |
__repr__ |
Return a string representation of the |
id
class-attribute
instance-attribute
¶
Unique identifier for the run.
run_type
class-attribute
instance-attribute
¶
The type of run, such as tool, chain, llm, retriever, embedding, prompt, parser.
start_time
class-attribute
instance-attribute
¶
Start time of the run.
extra
class-attribute
instance-attribute
¶
Additional metadata or settings related to the run.
tags
class-attribute
instance-attribute
¶
Tags for categorizing or annotating the run.
events
class-attribute
instance-attribute
¶
List of events associated with the run, like start and end events.
end_time
class-attribute
instance-attribute
¶
end_time: datetime | None = None
End time of the run, if applicable.
error
class-attribute
instance-attribute
¶
error: str | None = None
Error message, if the run encountered any issues.
serialized
class-attribute
instance-attribute
¶
serialized: dict | None = None
Serialized object that executed the run for potential reuse.
inputs
class-attribute
instance-attribute
¶
Inputs used for the run.
outputs
class-attribute
instance-attribute
¶
outputs: dict | None = None
Outputs generated by the run, if any.
reference_example_id
class-attribute
instance-attribute
¶
reference_example_id: UUID | None = None
Reference to an example that this run may be based on.
parent_run_id
class-attribute
instance-attribute
¶
parent_run_id: UUID | None = None
Identifier for a parent run, if this run is a sub-run.
attachments
class-attribute
instance-attribute
¶
attachments: Attachments | dict[str, AttachmentInfo] = Field(default_factory=dict)
Attachments associated with the run.
Each entry is a tuple of (mime_type, bytes).
Config
¶
Pydantic model configuration.
set
¶
set(
*,
inputs: Mapping[str, Any] | None = NOT_PROVIDED,
outputs: Mapping[str, Any] | None = NOT_PROVIDED,
tags: Sequence[str] | None = NOT_PROVIDED,
metadata: Mapping[str, Any] | None = NOT_PROVIDED,
usage_metadata: ExtractedUsageMetadata | None = NOT_PROVIDED,
) -> None
Set the inputs, outputs, tags, and metadata of the run.
If performed, this will override the default behavior of the end() method to ignore new outputs (that would otherwise be added) by the @traceable decorator.
If your LangChain or LangGraph versions are sufficiently up-to-date,
this will also override the default behavior of LangChainTracer.
| PARAMETER | DESCRIPTION |
|---|---|
inputs
|
The inputs to set. |
outputs
|
The outputs to set. |
tags
|
The tags to set. |
metadata
|
The metadata to set. |
usage_metadata
|
Usage information to set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
add_outputs
¶
add_inputs
¶
add_event
¶
end
¶
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
Set the end time of the run and all child runs.
create_child
¶
create_child(
name: str,
run_type: RUN_TYPE_T = "chain",
*,
run_id: ID_TYPE | 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: Attachments | None = None,
) -> RunTree
Add a child run to the run tree.
patch
¶
patch(*, exclude_inputs: bool = False) -> None
Patch the run tree to the API in a background thread.
| PARAMETER | DESCRIPTION |
|---|---|
exclude_inputs
|
Whether to exclude inputs from the patch request.
TYPE:
|
from_dotted_order
classmethod
¶
Create a new 'child' span from the provided dotted order.
| RETURNS | DESCRIPTION |
|---|---|
RunTree
|
The new span.
TYPE:
|
from_runnable_config
classmethod
¶
Create a new 'child' span from the provided runnable config.
Requires langchain to be installed.
| RETURNS | DESCRIPTION |
|---|---|
RunTree | None
|
The new span or |
from_headers
classmethod
¶
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 | DESCRIPTION |
|---|---|
RunTree | None
|
The new span or |
configure
¶
configure(
client: Client | None = _SENTINEL,
enabled: bool | None = _SENTINEL,
project_name: str | None = _SENTINEL,
tags: list[str] | None = _SENTINEL,
metadata: dict[str, Any] | None = _SENTINEL,
)
Configure global LangSmith tracing context.
This function allows you to set global configuration options for LangSmith tracing that will be applied to all subsequent traced operations. It modifies context variables that control tracing behavior across your application.
Do this once at startup to configure the global settings in code.
If, instead, you wish to only configure tracing for a single invocation,
use the tracing_context context manager instead.
| PARAMETER | DESCRIPTION |
|---|---|
client
|
A LangSmith Client instance to use for all tracing operations. If provided, this client will be used instead of creating new clients. Pass
TYPE:
|
enabled
|
Whether tracing is enabled. Can be:
TYPE:
|
project_name
|
The LangSmith project name where traces will be sent. This determines which project dashboard will display your traces. Pass
TYPE:
|
tags
|
A list of tags to be applied to all traced runs. Tags are useful for filtering and organizing runs in the LangSmith UI. Pass |
metadata
|
A dictionary of metadata to attach to all traced runs. Metadata can store any additional context about your runs. Pass |
Examples:
Basic configuration:
>>> import langsmith as ls
>>> # Enable tracing with a specific project
>>> ls.configure(enabled=True, project_name="my-project")
Set global trace masking:
>>> def hide_keys(data):
... if not data:
... return {}
... return {k: v for k, v in data.items() if k not in ["key1", "key2"]}
>>> ls.configure(
... client=ls.Client(
... hide_inputs=hide_keys,
... hide_outputs=hide_keys,
... )
... )
Adding global tags and metadata:
>>> ls.configure(
... tags=["production", "v1.0"],
... metadata={"environment": "prod", "version": "1.0.0"},
... )
Disabling tracing:
validate_extracted_usage_metadata
¶
validate_extracted_usage_metadata(
data: ExtractedUsageMetadata,
) -> ExtractedUsageMetadata
Validate that the dict only contains allowed keys.