🌍 Global Mirror — Visit original CN site →

langsmith

Description

LangSmith Client SDK

Release Notes Python Downloads

This package contains the Python client for interacting with the LangSmith platform.

To install:

pip install -U langsmith
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY=ls_...
Copy

Then trace:

import openai
from langsmith.wrappers import wrap_openai
from langsmith import traceable

# Auto-trace LLM calls in-context
client = wrap_openai(openai.Client())

@traceable # Auto-trace this function
def pipeline(user_input: str):
    result = client.chat.completions.create(
        messages=[{"role": "user", "content": user_input}],
        model="gpt-3.5-turbo"
    )
    return result.choices[0].message.content

pipeline("Hello, world!")
Copy

See the resulting nested trace 🌐 here.

LangSmith helps you and your team develop and evaluate language models and intelligent agents. It is compatible with any LLM application.

Cookbook: For tutorials on how to get more value out of LangSmith, check out the Langsmith Cookbook repo.

A typical workflow looks like:

  1. Set up an account with LangSmith.
  2. Log traces while debugging and prototyping.
  3. Run benchmark evaluations and continuously improve with the collected data.

We'll walk through these steps in more detail below.

1. Connect to LangSmith

Sign up for LangSmith using your GitHub, Discord accounts, or an email address and password. If you sign up with an email, make sure to verify your email address before logging in.

Then, create a unique API key on the Settings Page, which is found in the menu at the top right corner of the page.

[!NOTE] Save the API Key in a secure location. It will not be shown again.

2. Log Traces

You can log traces natively using the LangSmith SDK or within your LangChain application.

Logging Traces with LangChain

LangSmith seamlessly integrates with the Python LangChain library to record traces from your LLM applications.

  1. Copy the environment variables from the Settings Page and add them to your application.

Tracing can be activated by setting the following environment variables or by manually specifying the LangChainTracer.

import os
os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_ENDPOINT"] = "https://api.smith.langchain.com"
# os.environ["LANGSMITH_ENDPOINT"] = "https://eu.api.smith.langchain.com" # If signed up in the EU region
os.environ["LANGSMITH_API_KEY"] = "<YOUR-LANGSMITH-API-KEY>"
# os.environ["LANGSMITH_PROJECT"] = "My Project Name" # Optional: "default" is used if not set
# os.environ["LANGSMITH_WORKSPACE_ID"] = "<YOUR-WORKSPACE-ID>" # Required for org-scoped API keys
Copy

Tip: Projects are groups of traces. All runs are logged to a project. If not specified, the project is set to default.

  1. Run an Agent, Chain, or Language Model in LangChain

If the environment variables are correctly set, your application will automatically connect to the LangSmith platform.

from langchain_core.runnables import chain

@chain
def add_val(x: dict) -> dict:
    return {"val": x["val"] + 1}

add_val({"val": 1})
Copy

Logging Traces Outside LangChain

You can still use the LangSmith development platform without depending on any LangChain code.

  1. Copy the environment variables from the Settings Page and add them to your application.
import os
os.environ["LANGSMITH_ENDPOINT"] = "https://api.smith.langchain.com"
os.environ["LANGSMITH_API_KEY"] = "<YOUR-LANGSMITH-API-KEY>"
# os.environ["LANGSMITH_PROJECT"] = "My Project Name" # Optional: "default" is used if not set
Copy
  1. Log traces

The easiest way to log traces using the SDK is via the @traceable decorator. Below is an example.

from datetime import datetime
from typing import List, Optional, Tuple

import openai
from langsmith import traceable
from langsmith.wrappers import wrap_openai

client = wrap_openai(openai.Client())

@traceable
def argument_generator(query: str, additional_description: str = "") -> str:
    return client.chat.completions.create(
        [
            {"role": "system", "content": "You are a debater making an argument on a topic."
             f"{additional_description}"
             f" The current time is {datetime.now()}"},
            {"role": "user", "content": f"The discussion topic is {query}"}
        ]
    ).choices[0].message.content

@traceable
def argument_chain(query: str, additional_description: str = "") -> str:
    argument = argument_generator(query, additional_description)
    # ... Do other processing or call other functions...
    return argument

argument_chain("Why is blue better than orange?")
Copy

Alternatively, you can manually log events using the Client directly or using a RunTree, which is what the traceable decorator is meant to manage for you!

A RunTree tracks your application. Each RunTree object is required to have a name and run_type. These and other important attributes are as follows:

  • name: str - used to identify the component's purpose
  • run_type: str - Currently one of "llm", "chain" or "tool"; more options will be added in the future
  • inputs: dict - the inputs to the component
  • outputs: Optional[dict] - the (optional) returned values from the component
  • error: Optional[str] - Any error messages that may have arisen during the call
from langsmith.run_trees import RunTree

parent_run = RunTree(
    name="My Chat Bot",
    run_type="chain",
    inputs={"text": "Summarize this morning's meetings."},
    # project_name= "Defaults to the LANGSMITH_PROJECT env var"
)
parent_run.post()
# .. My Chat Bot calls an LLM
child_llm_run = parent_run.create_child(
    name="My Proprietary LLM",
    run_type="llm",
    inputs={
        "prompts": [
            "You are an AI Assistant. The time is XYZ."
            " Summarize this morning's meetings."
        ]
    },
)
child_llm_run.post()
child_llm_run.end(
    outputs={
        "generations": [
            "I should use the transcript_loader tool"
            " to fetch meeting_transcripts from XYZ"
        ]
    }
)
child_llm_run.patch()
# ..  My Chat Bot takes the LLM output and calls
# a tool / function for fetching transcripts ..
child_tool_run = parent_run.create_child(
    name="transcript_loader",
    run_type="tool",
    inputs={"date": "XYZ", "content_type": "meeting_transcripts"},
)
child_tool_run.post()
# The tool returns meeting notes to the chat bot
child_tool_run.end(outputs={"meetings": ["Meeting1 notes.."]})
child_tool_run.patch()

child_chain_run = parent_run.create_child(
    name="Unreliable Component",
    run_type="tool",
    inputs={"input": "Summarize these notes..."},
)
child_chain_run.post()

try:
    # .... the component does work
    raise ValueError("Something went wrong")
    child_chain_run.end(outputs={"output": "foo"}
    child_chain_run.patch()
except Exception as e:
    child_chain_run.end(error=f"I errored again {e}")
    child_chain_run.patch()
    pass
# .. The chat agent recovers

parent_run.end(outputs={"output": ["The meeting notes are as follows:..."]})
res = parent_run.patch()
res.result()
Copy

Create a Dataset from Existing Runs

Once your runs are stored in LangSmith, you can convert them into a dataset. For this example, we will do so using the Client, but you can also do this using the web interface, as explained in the LangSmith docs.

from langsmith import Client

client = Client()
dataset_name = "Example Dataset"
# We will only use examples from the top level AgentExecutor run here,
# and exclude runs that errored.
runs = client.list_runs(
    project_name="my_project",
    execution_order=1,
    error=False,
)

dataset = client.create_dataset(dataset_name, description="An example dataset")
for run in runs:
    client.create_example(
        inputs=run.inputs,
        outputs=run.outputs,
        dataset_id=dataset.id,
    )
Copy

Evaluating Runs

Check out the LangSmith Testing & Evaluation dos for up-to-date workflows.

For generating automated feedback on individual runs, you can run evaluations directly using the LangSmith client.

from typing import Optional
from langsmith.evaluation import StringEvaluator

def jaccard_chars(output: str, answer: str) -> float:
    """Naive Jaccard similarity between two strings."""
    prediction_chars = set(output.strip().lower())
    answer_chars = set(answer.strip().lower())
    intersection = prediction_chars.intersection(answer_chars)
    union = prediction_chars.union(answer_chars)
    return len(intersection) / len(union)

def grader(run_input: str, run_output: str, answer: Optional[str]) -> dict:
    """Compute the score and/or label for this run."""
    if answer is None:
        value = "AMBIGUOUS"
        score = 0.5
    else:
        score = jaccard_chars(run_output, answer)
        value = "CORRECT" if score > 0.9 else "INCORRECT"
    return dict(score=score, value=value)

evaluator = StringEvaluator(evaluation_name="Jaccard", grading_function=grader)

runs = client.list_runs(
    project_name="my_project",
    execution_order=1,
    error=False,
)
for run in runs:
    client.evaluate_run(run, evaluator)
Copy

Integrations

LangSmith easily integrates with your favorite LLM framework.

OpenAI SDK

We provide a convenient wrapper for the OpenAI SDK.

In order to use, you first need to set your LangSmith API key.

export LANGSMITH_API_KEY=<your-api-key>
Copy

Next, you will need to install the LangSmith SDK:

pip install -U langsmith
Copy

After that, you can wrap the OpenAI client:

from openai import OpenAI
from langsmith import wrappers

client = wrappers.wrap_openai(OpenAI())
Copy

Now, you can use the OpenAI client as you normally would, but now everything is logged to LangSmith!

client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Say this is a test"}],
)
Copy

Oftentimes, you use the OpenAI client inside of other functions. You can get nested traces by using this wrapped client and decorating those functions with @traceable. See this documentation for more documentation how to use this decorator

from langsmith import traceable

@traceable(name="Call OpenAI")
def my_function(text: str):
    return client.chat.completions.create(
        model="gpt-4",
        messages=[{"role": "user", "content": f"Say {text}"}],
    )

my_function("hello world")
Copy

Instructor

We provide a convenient integration with Instructor, largely by virtue of it essentially just using the OpenAI SDK.

In order to use, you first need to set your LangSmith API key.

export LANGSMITH_API_KEY=<your-api-key>
Copy

Next, you will need to install the LangSmith SDK:

pip install -U langsmith
Copy

After that, you can wrap the OpenAI client:

from openai import OpenAI
from langsmith import wrappers

client = wrappers.wrap_openai(OpenAI())
Copy

After this, you can patch the OpenAI client using instructor:

import instructor

client = instructor.patch(OpenAI())
Copy

Now, you can use instructor as you normally would, but now everything is logged to LangSmith!

from pydantic import BaseModel

class UserDetail(BaseModel):
    name: str
    age: int

user = client.chat.completions.create(
    model="gpt-3.5-turbo",
    response_model=UserDetail,
    messages=[
        {"role": "user", "content": "Extract Jason is 25 years old"},
    ]
)
Copy

Oftentimes, you use instructor inside of other functions. You can get nested traces by using this wrapped client and decorating those functions with @traceable. See this documentation for more documentation how to use this decorator

@traceable()
def my_function(text: str) -> UserDetail:
    return client.chat.completions.create(
        model="gpt-3.5-turbo",
        response_model=UserDetail,
        messages=[
            {"role": "user", "content": f"Extract {text}"},
        ]
    )

my_function("Jason is 25 years old")
Copy

Pytest Plugin

The LangSmith pytest plugin lets Python developers define their datasets and evaluations as pytest test cases. See online docs for more information.

This plugin is installed as part of the LangSmith SDK, and is enabled by default. See also official pytest docs: How to install and use plugins

Additional Documentation

To learn more about the LangSmith platform, check out the docs.

License

The LangSmith SDK is licensed under the MIT License.

The copyright information for certain dependencies' are reproduced in their corresponding COPYRIGHT.txt files in this repo, including the following:

Classes

Class

ApiKeyAuth

API key authentication for write replicas.

Class

ServiceAuth

Service-to-service JWT authentication for write replicas.

Class

AuthHeaders

Custom authentication headers for write replicas.

Class

WriteReplica

Configuration for a write replica endpoint.

Class

RunTree

Run Schema with back-references for posting runs.

Class

ReplicaAuth

Class

CacheEntry

A single cache entry with metadata for TTL tracking.

Class

CacheMetrics

Cache performance metrics.

Class

PromptCache

Thread-safe LRU cache with background thread refresh.

Class

AsyncPromptCache

Thread-safe LRU cache with asyncio task refresh.

Class

Cache

Deprecated alias for PromptCache. Use PromptCache instead.

Class

AsyncCache

Deprecated alias for AsyncPromptCache. Use AsyncPromptCache instead.

Class

LangSmithError

An error occurred while communicating with the LangSmith API.

Class

LangSmithAPIError

Internal server error while communicating with LangSmith.

Class

LangSmithRequestTimeout

Client took too long to send request body.

Class

LangSmithUserError

User error caused an exception when communicating with LangSmith.

Class

LangSmithRateLimitError

You have exceeded the rate limit for the LangSmith API.

Class

LangSmithAuthError

Couldn't authenticate with the LangSmith API.

Class

LangSmithNotFoundError

Couldn't find the requested resource.

Class

LangSmithConflictError

The resource already exists.

Class

LangSmithConnectionError

Couldn't connect to the LangSmith API.

Class

LangSmithExceptionGroup

Port of ExceptionGroup for Py < 3.11.

Class

LangSmithWarning

Base class for warnings.

Class

LangSmithMissingAPIKeyWarning

Warning for missing API key.

Class

FilterPoolFullWarning

Filter urllib3 warnings logged when the connection pool isn't reused.

Class

FilterLangSmithRetry

Filter for retries from this lib.

Class

LangSmithRetry

Wrapper to filter logs with this name.

Class

ContextThreadPoolExecutor

ThreadPoolExecutor that copies the context to the child thread.

Class

LangSmithPlugin

Plugin for rendering LangSmith results.

Class

StringNode

String node extracted from the data.

Class

StringNodeProcessor

Processes a list of string nodes for masking.

Class

ReplacerOptions

Configuration options for replacing sensitive data.

Class

StringNodeRule

Declarative rule used for replacing sensitive data.

Class

RuleNodeProcessor

String node processor that uses a list of rules to replace sensitive data.

Class

CallableNodeProcessor

String node processor that uses a callable function to replace sensitive data.

Class

_NULL_SENTRY

A sentinel singleton class used to distinguish omitted keyword arguments

Class

_Matcher

A class for making assertions on expectation values.

Class

_Expect

A class for setting expectations on test results.

Class

LangSmithExtra

Any additional info to be injected into the run dynamically.

Class

SupportsLangsmithExtra

Implementations of this Protocol accept an optional langsmith_extra parameter.

Class

trace

Manage a LangSmith run in context.

Class

ZoneInfo

Introduced in python 3.9.

Class

TracerProvider

Used for optional OTEL tracing.

Class

ListThreadsItem

Item returned by :meth:Client.list_threads.

Class

Client

Client for interacting with the LangSmith API.

Class

Attachment

Annotated type that will be stored as an attachment if used.

Class

BinaryIOLike

Protocol for binary IO-like objects.

Class

ExampleBase

Example base model.

Class

ExampleCreate

Example upload with attachments.

Class

ExampleUpsertWithAttachments

Example create with attachments.

Class

AttachmentInfo

Info for an attachment.

Class

Example

Example model.

Class

ExampleSearch

Example returned via search.

Class

AttachmentsOperations

Operations to perform on attachments.

Class

ExampleUpdate

Example update with attachments.

Class

DataType

Enum for dataset data types.

Class

DatasetBase

Dataset base model.

Class

DatasetTransformation

Schema for dataset transformations.

Class

Dataset

Dataset ORM model.

Class

DatasetVersion

Class representing a dataset version.

Class

RunBase

Base Run schema.

Class

Run

Run schema when loading from the DB.

Class

RunTypeEnum

(Deprecated) Enum for run types. Use string directly.

Class

RunLikeDict

Run-like dictionary, for type-hinting.

Class

RunWithAnnotationQueueInfo

Run schema with annotation queue info.

Class

FeedbackSourceBase

Base class for feedback sources.

Class

APIFeedbackSource

API feedback source.

Class

ModelFeedbackSource

Model feedback source.

Class

FeedbackSourceType

Feedback source type.

Class

FeedbackBase

Feedback schema.

Class

FeedbackCategory

Specific value and label pair for feedback.

Class

FeedbackConfig

Represents how a feedback value ought to be interpreted.

Class

FeedbackCreate

Schema used for creating feedback.

Class

Feedback

Schema for getting feedback.

Class

TracerSession

TracerSession schema for the API.

Class

TracerSessionResult

A project, hydrated with additional information.

Class

BaseMessageLike

A protocol representing objects similar to BaseMessage.

Class

DatasetShareSchema

Represents the schema for a dataset share.

Class

AnnotationQueueRubricItem

Represents a rubric item assigned to an annotation queue.

Class

AnnotationQueue

Represents an annotation queue.

Class

AnnotationQueueWithDetails

Represents an annotation queue with details.

Class

BatchIngestConfig

Configuration for batch ingestion.

Class

LangSmithInfo

Information about the LangSmith server.

Class

LangSmithSettings

Settings for the LangSmith tenant.

Class

FeedbackIngestToken

Represents the schema for a feedback ingest token.

Class

RunEvent

Run event schema.

Class

TimeDeltaInput

Timedelta input schema.

Class

DatasetDiffInfo

Represents the difference information between two datasets.

Class

ComparativeExperiment

Represents a comparative experiment.

Class

PromptCommit

Represents a Prompt with a manifest.

Class

ListedPromptCommit

Represents a listed prompt commit with associated metadata.

Class

Prompt

Represents a Prompt with metadata.

Class

ListPromptsResponse

A list of prompts with metadata.

Class

PromptSortField

Enum for sorting fields for prompts.

Class

InputTokenDetails

Breakdown of input token counts.

Class

OutputTokenDetails

Breakdown of output token counts.

Class

InputCostDetails

Breakdown of input token costs.

Class

OutputCostDetails

Breakdown of output token costs.

Class

UsageMetadata

Usage metadata for a message, such as token counts.

Class

ExtractedUsageMetadata

Usage metadata dictionary extracted from a run.

Class

UpsertExamplesResponse

Response object returned from the upsert_examples_multipart method.

Class

ExampleWithRuns

Example with runs.

Class

ExperimentRunStats

Run statistics for an experiment.

Class

ExperimentResults

Results container for experiment data with stats and examples.

Class

InsightsReport

An Insights Report created by the Insights Agent over a tracing project.

Class

FeedbackFormulaWeightedVariable

A feedback key and weight used when calculating feedback formulas.

Class

FeedbackFormulaCreate

Schema used for creating a feedback formula.

Class

FeedbackFormulaUpdate

Schema used for updating a feedback formula.

Class

FeedbackFormula

Schema for getting feedback formulas.

Class

FeedbackConfigSchema

Represents a feedback configuration for a tenant's feedback key.

Class

TracingMiddleware

Middleware for propagating distributed tracing context using LangSmith.

Class

AsyncClient

Async Client for interacting with the LangSmith API.

Class

GitInfo

Class

TracingExtra

Class

TracingExtra

Class

TracingExtra

Class

ExecutionResult

Result of executing a command in a sandbox.

Class

ResourceSpec

Resource specification for a sandbox.

Class

Volume

Represents a persistent volume.

Class

VolumeMountSpec

Specification for mounting a volume in a sandbox template.

Class

SandboxTemplate

Represents a SandboxTemplate.

Class

ResourceStatus

Lightweight provisioning status for any async-created resource.

Class

Pool

Represents a Sandbox Pool for pre-provisioned sandboxes.

Class

OutputChunk

A single chunk of streaming output from command execution.

Class

CommandHandle

Handle to a running command with streaming output and auto-reconnect.

Class

AsyncCommandHandle

Async handle to a running command with streaming output and auto-reconnect.

Class

AsyncSandboxClient

Async client for interacting with the Sandbox Server API.

Class

SandboxClient

Client for interacting with the Sandbox Server API.

Class

Sandbox

Represents an active sandbox for running commands and file operations.

Class

SandboxClientError

Base exception for sandbox client errors.

Class

SandboxAPIError

Raised when the API endpoint returns an unexpected error.

Class

SandboxAuthenticationError

Raised when authentication fails (invalid or missing API key).

Class

SandboxConnectionError

Raised when connection to the sandbox server fails.

Class

SandboxServerReloadError

Raised when the server sends a 1001 Going Away close frame.

Class

ResourceNotFoundError

Raised when a resource is not found.

Class

ResourceTimeoutError

Raised when an operation times out.

Class

ResourceInUseError

Raised when deleting a resource that is still in use.

Class

ResourceAlreadyExistsError

Raised when creating a resource that already exists.

Class

ResourceNameConflictError

Raised when updating a resource name to one that already exists.

Class

ValidationError

Raised when request validation fails.

Class

QuotaExceededError

Raised when organization quota limits are exceeded.

Class

ResourceCreationError

Raised when resource provisioning fails.

Class

DataplaneNotConfiguredError

Raised when dataplane_url is not available for the sandbox.

Class

SandboxNotReadyError

Raised when attempting to interact with a sandbox that is not ready.

Class

SandboxOperationError

Raised when a sandbox operation fails (run, read, write).

Class

CommandTimeoutError

Raised when a command exceeds its timeout.

Class

RetryTransport

Sync httpx transport that retries on transient errors.

Class

AsyncRetryTransport

Async httpx transport that retries on transient errors.

Class

AsyncSandbox

Represents an active sandbox for running commands and file operations async.

Class

Category

A category for categorical feedback.

Class

FeedbackConfig

Configuration to define a type of feedback.

Class

EvaluationResult

Evaluation result.

Class

EvaluationResults

Batch evaluation results.

Class

RunEvaluator

Evaluator interface class.

Class

ComparisonEvaluationResult

Feedback scores for the results of comparative evaluations.

Class

DynamicRunEvaluator

A dynamic evaluator that wraps a function and transforms it into a RunEvaluator.

Class

DynamicComparisonRunEvaluator

Compare predictions (as traces) from 2 or more runs.

Class

AsyncExperimentResults

Class

CategoricalScoreConfig

Configuration for a categorical score.

Class

ContinuousScoreConfig

Configuration for a continuous score.

Class

LLMEvaluator

A class for building LLM-as-a-judge evaluators.

Class

ExperimentResultRow

Class

ExperimentResults

Represents the results of an evaluate() call.

Class

ComparativeExperimentResults

Represents the results of an evaluate_comparative() call.

Class

StringEvaluator

Grades the run's string input, output, and optional answer.

Functions

Function

get_cached_client

Function

configure

Configure global LangSmith tracing context.

Function

validate_extracted_usage_metadata

Validate that the dict only contains allowed keys.

Function

configure_global_prompt_cache

Configure the global prompt cache.

Function

configure_global_async_prompt_cache

Configure the global prompt cache.

Function

get_invalid_prompt_identifier_msg

Get the error message for an invalid prompt identifier.

Function

tracing_is_enabled

Return True if tracing is enabled.

Function

test_tracking_is_disabled

Return True if testing is enabled.

Function

xor_args

Validate specified keyword args are mutually exclusive.

Function

raise_for_status_with_text

Raise an error with the response text.

Function

get_enum_value

Get the value of a string enum.

Function

log_once

Log a message at the specified level, but only once.

Function

get_messages_from_inputs

Extract messages from the given inputs dictionary.

Function

get_message_generation_from_outputs

Retrieve the message generation from the given outputs.

Function

get_prompt_from_inputs

Retrieve the prompt from the given inputs.

Function

get_llm_generation_from_outputs

Get the LLM generation from the outputs.

Function

get_docker_compose_command

Get the correct docker compose command for this system.

Function

convert_langchain_message

Convert a LangChain message to an example.

Function

is_base_message_like

Check if the given object is similar to BaseMessage.

Function

is_env_var_truish

Check if the given environment variable is truish.

Function

get_env_var

Retrieve an environment variable from a list of namespaces.

Function

get_tracer_project

Get the project name for a LangSmith tracer.

Function

filter_logs

Temporarily adds specified filters to a logger.

Function

get_cache_dir

Get the testing cache directory.

Function

filter_request_headers

Filter request headers based on ignore_hosts and allow_hosts.

Function

with_cache

Use a cache for requests.

Function

with_optional_cache

Use a cache for requests.

Function

deepish_copy

Deep copy a value with a compromise for uncopyable objects.

Function

is_version_greater_or_equal

Check if the current version is greater or equal to the target version.

Function

parse_prompt_identifier

Parse a string in the format of owner/name:hash, name:hash, owner/name, or name.

Function

get_api_url

Get the LangSmith API URL from the environment or the given value.

Function

get_api_key

Get the API key from the environment or the given value.

Function

get_workspace_id

Get workspace ID.

Function

get_host_url

Get the host URL based on the web URL or API URL.

Function

is_truish

Check if the value is truish.

Function

pytest_addoption

Set a boolean flag for LangSmith output.

Function

pytest_cmdline_preparse

Call immediately after command line options are parsed (pytest v7).

Function

pytest_load_initial_conftests

Handle args in pytest v8+.

Function

pytest_runtest_call

Apply LangSmith tracking to tests marked with @pytest.mark.langsmith.

Function

pytest_report_teststatus

Remove the short test-status character outputs ("./F").

Function

pytest_configure

Register the 'langsmith' marker.

Function

create_anonymizer

Create an anonymizer function.

Function

get_current_run_tree

Get the current run tree.

Function

set_tracing_parent

Set a RunTree as the active tracing parent within this block.

Function

set_run_metadata

Update metadata on the current run tree.

Function

get_tracing_context

Get the current tracing context.

Function

tracing_context

Set the tracing context for a block of code.

Function

is_traceable_function

Check if a function is @traceable decorated.

Function

ensure_traceable

Ensure that a function is traceable.

Function

is_async

Inspect function or wrapped function to see if it is async.

Function

traceable

Trace a function with langsmith.

Function

as_runnable

Convert a function wrapped by the LangSmith @traceable decorator to a Runnable.

Function

close_session

Close the session.

Function

convert_prompt_to_openai_format

Convert a prompt to OpenAI format.

Function

convert_prompt_to_anthropic_format

Convert a prompt to Anthropic format.

Function

dump_model

Dump model depending on pydantic version.

Function

prep_obj_for_push

Format the object so its Prompt Hub compatible.

Function

uuid7

Generate a random UUID v7.

Function

uuid7_from_datetime

Generate a UUID v7 from a datetime.

Function

exec_git

Function

get_git_info

Get information about the git repository.

Function

get_runtime_and_metrics

Get the runtime information as well as metrics.

Function

get_system_metrics

Get CPU and other performance metrics.

Function

get_runtime_environment

Get information about the environment.

Function

get_langchain_environment

Function

get_langchain_core_version

Function

get_docker_version

Function

get_docker_compose_version

Function

get_docker_environment

Get information about the environment.

Function

get_langchain_env_vars

Retrieve the langchain environment variables.

Function

get_langchain_env_var_metadata

Retrieve the langchain environment variables.

Function

get_release_shas

Function

wrap_openai

Patch the OpenAI client to make it traceable.

Function

wrap_anthropic

Patch the Anthropic client to make it traceable.

Function

wrap_gemini

Patch the Google Gen AI client to make it traceable.

Function

run_ws_stream

Execute a command over WebSocket, yielding raw message dicts.

Function

reconnect_ws_stream

Reconnect to an existing command over WebSocket.

Function

run_ws_stream_async

Async equivalent of run_ws_stream.

Function

reconnect_ws_stream_async

Async equivalent of reconnect_ws_stream.

Function

parse_error_response

Parse standardized error response.

Function

parse_error_response_simple

Parse error response (simplified version for sandbox operations).

Function

parse_validation_error

Parse Pydantic validation error response.

Function

extract_quota_type

Extract quota type from error message.

Function

raise_creation_error

Raise ResourceCreationError with the error_type from the API response.

Function

handle_sandbox_creation_error

Handle HTTP errors specific to sandbox creation.

Function

handle_volume_creation_error

Handle HTTP errors specific to volume creation.

Function

handle_pool_error

Handle HTTP errors specific to pool creation/update.

Function

handle_client_http_error

Handle HTTP errors and raise appropriate exceptions (for client operations).

Function

handle_sandbox_http_error

Handle HTTP errors for sandbox operations (run, read, write).

Function

process_inputs

Function

run_evaluator

Create a run evaluator from a function.

Function

process_inputs

Function

comparison_evaluator

Create a comaprison evaluator from a function.

Function

aevaluate

Evaluate an async target system on a given dataset.

Function

aevaluate_existing

Evaluate existing experiment runs asynchronously.

Function

async_chain_from_iterable

Chain multiple async iterables.

Function

async_iter_from_list

Convert a list of examples to an async iterable.

Function

random_name

Generate a random name.

Function

evaluate

Evaluate a target system on a given dataset.

Function

evaluate_existing

Evaluate existing experiment runs.

Function

evaluate_comparative

Evaluate existing experiment runs against each other.

Modules

Types