From b55d88ad7dae7abfdca2794acc1dd754fbffa833 Mon Sep 17 00:00:00 2001 From: Aliyev Doniyor Date: Thu, 15 Jan 2026 20:30:44 +0500 Subject: [PATCH] Add metadata parameter to score_current_span and score_current_trace Added optional metadata parameter to both score_current_span and score_current_trace methods to allow attaching additional context to scores. This brings these convenience methods to feature parity with the underlying create_score method which already supports metadata. Changes: - Added metadata parameter to all overloads of score_current_span - Added metadata parameter to all overloads of score_current_trace - Updated docstrings with metadata parameter documentation - Updated examples to demonstrate metadata usage - Passed metadata parameter through to create_score calls --- langfuse/_client/client.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/langfuse/_client/client.py b/langfuse/_client/client.py index 7ee2f962f..ded3103e5 100644 --- a/langfuse/_client/client.py +++ b/langfuse/_client/client.py @@ -2108,6 +2108,7 @@ def score_current_span( data_type: Optional[Literal["NUMERIC", "BOOLEAN"]] = None, comment: Optional[str] = None, config_id: Optional[str] = None, + metadata: Optional[Any] = None, ) -> None: ... @overload @@ -2120,6 +2121,7 @@ def score_current_span( data_type: Optional[Literal["CATEGORICAL"]] = "CATEGORICAL", comment: Optional[str] = None, config_id: Optional[str] = None, + metadata: Optional[Any] = None, ) -> None: ... def score_current_span( @@ -2131,6 +2133,7 @@ def score_current_span( data_type: Optional[ScoreDataType] = None, comment: Optional[str] = None, config_id: Optional[str] = None, + metadata: Optional[Any] = None, ) -> None: """Create a score for the current active span. @@ -2144,6 +2147,7 @@ def score_current_span( data_type: Type of score (NUMERIC, BOOLEAN, or CATEGORICAL) comment: Optional comment or explanation for the score config_id: Optional ID of a score config defined in Langfuse + metadata: Optional metadata to be attached to the score Example: ```python @@ -2157,7 +2161,8 @@ def score_current_span( name="relevance", value=0.85, data_type="NUMERIC", - comment="Mostly relevant but contains some tangential information" + comment="Mostly relevant but contains some tangential information", + metadata={"model": "gpt-4", "prompt_version": "v2"} ) ``` """ @@ -2180,6 +2185,7 @@ def score_current_span( data_type=cast(Literal["CATEGORICAL"], data_type), comment=comment, config_id=config_id, + metadata=metadata, ) @overload @@ -2192,6 +2198,7 @@ def score_current_trace( data_type: Optional[Literal["NUMERIC", "BOOLEAN"]] = None, comment: Optional[str] = None, config_id: Optional[str] = None, + metadata: Optional[Any] = None, ) -> None: ... @overload @@ -2204,6 +2211,7 @@ def score_current_trace( data_type: Optional[Literal["CATEGORICAL"]] = "CATEGORICAL", comment: Optional[str] = None, config_id: Optional[str] = None, + metadata: Optional[Any] = None, ) -> None: ... def score_current_trace( @@ -2215,6 +2223,7 @@ def score_current_trace( data_type: Optional[ScoreDataType] = None, comment: Optional[str] = None, config_id: Optional[str] = None, + metadata: Optional[Any] = None, ) -> None: """Create a score for the current trace. @@ -2229,6 +2238,7 @@ def score_current_trace( data_type: Type of score (NUMERIC, BOOLEAN, or CATEGORICAL) comment: Optional comment or explanation for the score config_id: Optional ID of a score config defined in Langfuse + metadata: Optional metadata to be attached to the score Example: ```python @@ -2242,7 +2252,8 @@ def score_current_trace( name="overall_quality", value=0.95, data_type="NUMERIC", - comment="High quality end-to-end response" + comment="High quality end-to-end response", + metadata={"evaluator": "gpt-4", "criteria": "comprehensive"} ) ``` """ @@ -2263,6 +2274,7 @@ def score_current_trace( data_type=cast(Literal["CATEGORICAL"], data_type), comment=comment, config_id=config_id, + metadata=metadata, ) def flush(self) -> None: