View module source on GitHub

Models for LangChain logging and tracing functionality.

This module contains data models used for tracking and logging LangChain operations, including metadata storage and run information.

Metadata

@dataclass
class Metadata()

RunMetadata class to holds the metadata info associated with a run

__init__

def __init__(metadata: Optional[Dict[str, Any]])

Initializes the RunMetadata object

Arguments:

NameTypeDescription
metadataOptional[Dict[str,Any]]Metadata to initialize from

Container

class Container()

Container class to hold the container id, type and name for logging

create

def create(tags: Optional[Dict[str, str]] = None) -> None

Creates the container in the logger

id

def id() -> str

Returns:

NameDescription
strid of the container

type

def type() -> str

Returns:

NameDescription
strtype of the container

is_created

def is_created() -> bool

Checks if the container has been created

Returns:

NameDescription
boolTrue if the container has been created, False otherwise

parent

def parent() -> Optional[str]

Returns:

NameDescription
[Container](/sdk/python/references/logger/models/container)parent container

add_generation

@abstractmethod
def add_generation(config: GenerationConfig) -> Generation

Adds a generation to the container

Returns:

NameDescription
[Generation](/sdk/python/references/logger/components/generation)Generation object

add_tool_call

@abstractmethod
def add_tool_call(config: ToolCallConfig) -> ToolCall

Adds a tool call to the container

Returns:

NameDescription
[ToolCall](/sdk/python/references/models/prompt)ToolCall object

add_event

def add_event(event_id: str,
              name: str,
              tags: Dict[str, str],
              metadata: Optional[Dict[str, Any]] = None) -> None

Adds an event to the container.

Arguments:

NameTypeDescription
event_idstrUnique identifier for the event.
namestrName of the event.
tagsDict[str, str]Additional key-value pairs to associate with the event.

Returns:

None

add_span

@abstractmethod
def add_span(config: SpanConfig) -> Span

Adds a span to the container

Returns:

NameDescription
[Span](/sdk/python/references/logger/components/span)Span object

add_retrieval

@abstractmethod
def add_retrieval(config: RetrievalConfig) -> Retrieval

Adds a retrieval to the container

Returns:

NameDescription
[Retrieval](/sdk/python/references/logger/components/retrieval)Retrieval object

add_tags

def add_tags(tags: Dict[str, str]) -> None

Adds tags to the container

Arguments:

NameTypeDescription
tagsOptional[Dict[str,str]]Tags to add

add_error

def add_error(error: ErrorConfig) -> None

Adds an error to the container

Arguments:

NameTypeDescription
errorGenerationErrorError to add

set_input

def set_input(input: str) -> None

Sets the input to the container

Arguments:

NameTypeDescription
inputstrInput to set

set_output

def set_output(output) -> None

Sets the output to the container

Arguments:

NameTypeDescription
outputstrOutput to set

add_metadata

def add_metadata(metadata: Dict[str, str]) -> None

Adds metadata to the container

Arguments:

NameTypeDescription
metadataOptional[Dict[str,str]]Metadata to add

end

def end() -> None

Ends the container

TraceContainer

class TraceContainer(Container)

A trace in the logger

add_generation

def add_generation(config: GenerationConfig) -> Generation

Adds a generation to the container

Returns:

NameDescription
[Generation](/sdk/python/references/logger/components/generation)Generation object

end

def end() -> None

Ends the container

SpanContainer

class SpanContainer(Container)

A span in the logger

end

def end() -> None

Ends the container