@@ -166,7 +166,9 @@ def __init__(
166166 self ._project_id = None
167167 sample_rate = sample_rate or float (os .environ .get (LANGFUSE_SAMPLE_RATE , 1.0 ))
168168 if not 0.0 <= sample_rate <= 1.0 :
169- raise ValueError (f"Sample rate must be between 0.0 and 1.0, got { sample_rate } " )
169+ raise ValueError (
170+ f"Sample rate must be between 0.0 and 1.0, got { sample_rate } "
171+ )
170172
171173 self ._tracing_enabled = (
172174 tracing_enabled
@@ -1214,12 +1216,15 @@ def create_score(
12141216 * ,
12151217 name : str ,
12161218 value : float ,
1217- trace_id : str ,
1219+ session_id : Optional [str ] = None ,
1220+ dataset_run_id : Optional [str ] = None ,
1221+ trace_id : Optional [str ] = None ,
12181222 observation_id : Optional [str ] = None ,
12191223 score_id : Optional [str ] = None ,
12201224 data_type : Optional [Literal ["NUMERIC" , "BOOLEAN" ]] = None ,
12211225 comment : Optional [str ] = None ,
12221226 config_id : Optional [str ] = None ,
1227+ metadata : Optional [Any ] = None ,
12231228 ) -> None : ...
12241229
12251230 @overload
@@ -1228,25 +1233,31 @@ def create_score(
12281233 * ,
12291234 name : str ,
12301235 value : str ,
1231- trace_id : str ,
1236+ session_id : Optional [str ] = None ,
1237+ dataset_run_id : Optional [str ] = None ,
1238+ trace_id : Optional [str ] = None ,
12321239 score_id : Optional [str ] = None ,
12331240 observation_id : Optional [str ] = None ,
12341241 data_type : Optional [Literal ["CATEGORICAL" ]] = "CATEGORICAL" ,
12351242 comment : Optional [str ] = None ,
12361243 config_id : Optional [str ] = None ,
1244+ metadata : Optional [Any ] = None ,
12371245 ) -> None : ...
12381246
12391247 def create_score (
12401248 self ,
12411249 * ,
12421250 name : str ,
12431251 value : Union [float , str ],
1244- trace_id : str ,
1252+ session_id : Optional [str ] = None ,
1253+ dataset_run_id : Optional [str ] = None ,
1254+ trace_id : Optional [str ] = None ,
12451255 observation_id : Optional [str ] = None ,
12461256 score_id : Optional [str ] = None ,
12471257 data_type : Optional [ScoreDataType ] = None ,
12481258 comment : Optional [str ] = None ,
12491259 config_id : Optional [str ] = None ,
1260+ metadata : Optional [Any ] = None ,
12501261 ) -> None :
12511262 """Create a score for a specific trace or observation.
12521263
@@ -1256,12 +1267,15 @@ def create_score(
12561267 Args:
12571268 name: Name of the score (e.g., "relevance", "accuracy")
12581269 value: Score value (can be numeric for NUMERIC/BOOLEAN types or string for CATEGORICAL)
1270+ session_id: ID of the Langfuse session to associate the score with
1271+ dataset_run_id: ID of the Langfuse dataset run to associate the score with
12591272 trace_id: ID of the Langfuse trace to associate the score with
1260- observation_id: Optional ID of the specific observation to score
1273+ observation_id: Optional ID of the specific observation to score. Trace ID must be provided too.
12611274 score_id: Optional custom ID for the score (auto-generated if not provided)
12621275 data_type: Type of score (NUMERIC, BOOLEAN, or CATEGORICAL)
12631276 comment: Optional comment or explanation for the score
12641277 config_id: Optional ID of a score config defined in Langfuse
1278+ metadata: Optional metadata to be attached to the score
12651279
12661280 Example:
12671281 ```python
@@ -1292,6 +1306,8 @@ def create_score(
12921306 try :
12931307 score_event = {
12941308 "id" : score_id ,
1309+ "session_id" : session_id ,
1310+ "dataset_run_id" : dataset_run_id ,
12951311 "trace_id" : trace_id ,
12961312 "observation_id" : observation_id ,
12971313 "name" : name ,
@@ -1300,6 +1316,7 @@ def create_score(
13001316 "comment" : comment ,
13011317 "config_id" : config_id ,
13021318 "environment" : self ._environment ,
1319+ "metadata" : metadata ,
13031320 }
13041321
13051322 new_body = ScoreBody (** score_event )
0 commit comments