LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
  • RemoteGraph
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDKRemoteGraph
Language
Theme
PythonlangsmithclientClientbatch_ingest_runs
Method●Since v0.0

batch_ingest_runs

Copy
batch_ingest_runs(
  self,
  create: Optional[Sequence[Union[ls_schemas.Run, ls_schemas.
View source on GitHub
RunLikeDict
,
dict
]
]
]
=
None
,
update
:
Optional
[
Sequence
[
Union
[
ls_schemas
.
Run
,
ls_schemas
.
RunLikeDict
,
dict
]
]
]
=
None
,
*
,
pre_sampled
:
bool
=
False
)
->
None

Parameters

NameTypeDescription
createOptional[Sequence[Union[Run, RunLikeDict]]]
Default:None

A sequence of Run objects or equivalent dictionaries representing runs to be created / posted.

updateOptional[Sequence[Union[Run, RunLikeDict]]]
Default:None
pre_sampledbool, default=False
Default:False

Batch ingest/upsert multiple runs in the Langsmith system.

The run objects MUST contain the dotted_order and trace_id fields to be accepted by the API.

Example:

from langsmith import Client
import datetime
from uuid import uuid4

client = Client()
_session = "__test_batch_ingest_runs"
trace_id = uuid4()
trace_id_2 = uuid4()
run_id_2 = uuid4()
current_time = datetime.datetime.now(datetime.timezone.utc).strftime(
    "%Y%m%dT%H%M%S%fZ"
)
later_time = (
    datetime.datetime.now(datetime.timezone.utc) + timedelta(seconds=1)
).strftime("%Y%m%dT%H%M%S%fZ")

runs_to_create = [
    {
        "id": str(trace_id),
        "session_name": _session,
        "name": "run 1",
        "run_type": "chain",
        "dotted_order": f"{current_time}{str(trace_id)}",
        "trace_id": str(trace_id),
        "inputs": {"input1": 1, "input2": 2},
        "outputs": {"output1": 3, "output2": 4},
    },
    {
        "id": str(trace_id_2),
        "session_name": _session,
        "name": "run 3",
        "run_type": "chain",
        "dotted_order": f"{current_time}{str(trace_id_2)}",
        "trace_id": str(trace_id_2),
        "inputs": {"input1": 1, "input2": 2},
        "error": "error",
    },
    {
        "id": str(run_id_2),
        "session_name": _session,
        "name": "run 2",
        "run_type": "chain",
        "dotted_order": f"{current_time}{str(trace_id)}."
        f"{later_time}{str(run_id_2)}",
        "trace_id": str(trace_id),
        "parent_run_id": str(trace_id),
        "inputs": {"input1": 5, "input2": 6},
    },
]
runs_to_update = [
    {
        "id": str(run_id_2),
        "dotted_order": f"{current_time}{str(trace_id)}."
        f"{later_time}{str(run_id_2)}",
        "trace_id": str(trace_id),
        "parent_run_id": str(trace_id),
        "outputs": {"output1": 4, "output2": 5},
    },
]

client.batch_ingest_runs(create=runs_to_create, update=runs_to_update)

A sequence of Run objects or equivalent dictionaries representing runs that have already been created and should be updated / patched.

Whether the runs have already been subject to sampling, and therefore should not be sampled again.