Skip to content

Commit 53d98c9

Browse files
authored
fix(scores): support CORRECTION score data type (#1713)
CORRECTION was missing from the score data_type type hints, so the documented corrections example (create_score(..., data_type="CORRECTION")) failed type checking even though the runtime already accepted it. Add CORRECTION to the public ScoreDataType alias and to the string-value overloads (and internal casts) of create_score, score_current_span, score_current_trace, and the span score/score_trace methods, plus the data_type/value docstrings. It is string-valued, so it is added only to the string overloads; the numeric overloads still reject it. No runtime change: data_type already flows through to ScoreBody, whose generated enum already includes CORRECTION.
1 parent ffd28a4 commit 53d98c9

3 files changed

Lines changed: 30 additions & 20 deletions

File tree

‎langfuse/_client/client.py‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,9 @@ def create_score(
17861786
trace_id: Optional[str] = None,
17871787
score_id: Optional[str] = None,
17881788
observation_id: Optional[str] = None,
1789-
data_type: Optional[Literal["CATEGORICAL", "TEXT"]] = "CATEGORICAL",
1789+
data_type: Optional[
1790+
Literal["CATEGORICAL", "TEXT", "CORRECTION"]
1791+
] = "CATEGORICAL",
17901792
comment: Optional[str] = None,
17911793
config_id: Optional[str] = None,
17921794
metadata: Optional[Any] = None,
@@ -1816,13 +1818,13 @@ def create_score(
18161818
18171819
Args:
18181820
name: Name of the score (e.g., "relevance", "accuracy")
1819-
value: Score value (can be numeric for NUMERIC/BOOLEAN types or string for CATEGORICAL/TEXT)
1821+
value: Score value (can be numeric for NUMERIC/BOOLEAN types or string for CATEGORICAL/TEXT/CORRECTION)
18201822
session_id: ID of the Langfuse session to associate the score with
18211823
dataset_run_id: ID of the Langfuse dataset run to associate the score with
18221824
trace_id: ID of the Langfuse trace to associate the score with
18231825
observation_id: Optional ID of the specific observation to score. Trace ID must be provided too.
18241826
score_id: Optional custom ID for the score (auto-generated if not provided)
1825-
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, or TEXT)
1827+
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, TEXT, or CORRECTION)
18261828
comment: Optional comment or explanation for the score
18271829
config_id: Optional ID of a score config defined in Langfuse
18281830
metadata: Optional metadata to be attached to the score
@@ -1946,7 +1948,9 @@ def score_current_span(
19461948
name: str,
19471949
value: str,
19481950
score_id: Optional[str] = None,
1949-
data_type: Optional[Literal["CATEGORICAL", "TEXT"]] = "CATEGORICAL",
1951+
data_type: Optional[
1952+
Literal["CATEGORICAL", "TEXT", "CORRECTION"]
1953+
] = "CATEGORICAL",
19501954
comment: Optional[str] = None,
19511955
config_id: Optional[str] = None,
19521956
metadata: Optional[Any] = None,
@@ -1970,9 +1974,9 @@ def score_current_span(
19701974
19711975
Args:
19721976
name: Name of the score (e.g., "relevance", "accuracy")
1973-
value: Score value (can be numeric for NUMERIC/BOOLEAN types or string for CATEGORICAL/TEXT)
1977+
value: Score value (can be numeric for NUMERIC/BOOLEAN types or string for CATEGORICAL/TEXT/CORRECTION)
19741978
score_id: Optional custom ID for the score (auto-generated if not provided)
1975-
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, or TEXT)
1979+
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, TEXT, or CORRECTION)
19761980
comment: Optional comment or explanation for the score
19771981
config_id: Optional ID of a score config defined in Langfuse
19781982
metadata: Optional metadata to be attached to the score
@@ -2010,7 +2014,7 @@ def score_current_span(
20102014
name=name,
20112015
value=cast(str, value),
20122016
score_id=score_id,
2013-
data_type=cast(Literal["CATEGORICAL", "TEXT"], data_type),
2017+
data_type=cast(Literal["CATEGORICAL", "TEXT", "CORRECTION"], data_type),
20142018
comment=comment,
20152019
config_id=config_id,
20162020
metadata=metadata,
@@ -2036,7 +2040,9 @@ def score_current_trace(
20362040
name: str,
20372041
value: str,
20382042
score_id: Optional[str] = None,
2039-
data_type: Optional[Literal["CATEGORICAL", "TEXT"]] = "CATEGORICAL",
2043+
data_type: Optional[
2044+
Literal["CATEGORICAL", "TEXT", "CORRECTION"]
2045+
] = "CATEGORICAL",
20402046
comment: Optional[str] = None,
20412047
config_id: Optional[str] = None,
20422048
metadata: Optional[Any] = None,
@@ -2061,9 +2067,9 @@ def score_current_trace(
20612067
20622068
Args:
20632069
name: Name of the score (e.g., "user_satisfaction", "overall_quality")
2064-
value: Score value (can be numeric for NUMERIC/BOOLEAN types or string for CATEGORICAL/TEXT)
2070+
value: Score value (can be numeric for NUMERIC/BOOLEAN types or string for CATEGORICAL/TEXT/CORRECTION)
20652071
score_id: Optional custom ID for the score (auto-generated if not provided)
2066-
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, or TEXT)
2072+
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, TEXT, or CORRECTION)
20672073
comment: Optional comment or explanation for the score
20682074
config_id: Optional ID of a score config defined in Langfuse
20692075
metadata: Optional metadata to be attached to the score
@@ -2099,7 +2105,7 @@ def score_current_trace(
20992105
name=name,
21002106
value=cast(str, value),
21012107
score_id=score_id,
2102-
data_type=cast(Literal["CATEGORICAL", "TEXT"], data_type),
2108+
data_type=cast(Literal["CATEGORICAL", "TEXT", "CORRECTION"], data_type),
21032109
comment=comment,
21042110
config_id=config_id,
21052111
metadata=metadata,

‎langfuse/_client/span.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ def score(
308308
value: str,
309309
score_id: Optional[str] = None,
310310
data_type: Optional[
311-
Literal[ScoreDataType.CATEGORICAL, ScoreDataType.TEXT]
311+
Literal[
312+
ScoreDataType.CATEGORICAL, ScoreDataType.TEXT, ScoreDataType.CORRECTION
313+
]
312314
] = ScoreDataType.CATEGORICAL,
313315
comment: Optional[str] = None,
314316
config_id: Optional[str] = None,
@@ -335,9 +337,9 @@ def score(
335337
336338
Args:
337339
name: Name of the score (e.g., "relevance", "accuracy")
338-
value: Score value (numeric for NUMERIC/BOOLEAN, string for CATEGORICAL/TEXT)
340+
value: Score value (numeric for NUMERIC/BOOLEAN, string for CATEGORICAL/TEXT/CORRECTION)
339341
score_id: Optional custom ID for the score (auto-generated if not provided)
340-
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, or TEXT)
342+
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, TEXT, or CORRECTION)
341343
comment: Optional comment or explanation for the score
342344
config_id: Optional ID of a score config defined in Langfuse
343345
timestamp: Optional timestamp for the score (defaults to current UTC time)
@@ -364,7 +366,7 @@ def score(
364366
trace_id=self.trace_id,
365367
observation_id=self.id,
366368
score_id=score_id,
367-
data_type=cast(Literal["CATEGORICAL", "TEXT"], data_type),
369+
data_type=cast(Literal["CATEGORICAL", "TEXT", "CORRECTION"], data_type),
368370
comment=comment,
369371
config_id=config_id,
370372
timestamp=timestamp,
@@ -395,7 +397,9 @@ def score_trace(
395397
value: str,
396398
score_id: Optional[str] = None,
397399
data_type: Optional[
398-
Literal[ScoreDataType.CATEGORICAL, ScoreDataType.TEXT]
400+
Literal[
401+
ScoreDataType.CATEGORICAL, ScoreDataType.TEXT, ScoreDataType.CORRECTION
402+
]
399403
] = ScoreDataType.CATEGORICAL,
400404
comment: Optional[str] = None,
401405
config_id: Optional[str] = None,
@@ -423,9 +427,9 @@ def score_trace(
423427
424428
Args:
425429
name: Name of the score (e.g., "user_satisfaction", "overall_quality")
426-
value: Score value (numeric for NUMERIC/BOOLEAN, string for CATEGORICAL/TEXT)
430+
value: Score value (numeric for NUMERIC/BOOLEAN, string for CATEGORICAL/TEXT/CORRECTION)
427431
score_id: Optional custom ID for the score (auto-generated if not provided)
428-
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, or TEXT)
432+
data_type: Type of score (NUMERIC, BOOLEAN, CATEGORICAL, TEXT, or CORRECTION)
429433
comment: Optional comment or explanation for the score
430434
config_id: Optional ID of a score config defined in Langfuse
431435
timestamp: Optional timestamp for the score (defaults to current UTC time)
@@ -451,7 +455,7 @@ def score_trace(
451455
value=cast(str, value),
452456
trace_id=self.trace_id,
453457
score_id=score_id,
454-
data_type=cast(Literal["CATEGORICAL", "TEXT"], data_type),
458+
data_type=cast(Literal["CATEGORICAL", "TEXT", "CORRECTION"], data_type),
455459
comment=comment,
456460
config_id=config_id,
457461
timestamp=timestamp,

‎langfuse/types.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def my_evaluator(*, output: str, **kwargs) -> Evaluation:
3535

3636
SpanLevel = Literal["DEBUG", "DEFAULT", "WARNING", "ERROR"]
3737

38-
ScoreDataType = Literal["NUMERIC", "CATEGORICAL", "BOOLEAN", "TEXT"]
38+
ScoreDataType = Literal["NUMERIC", "CATEGORICAL", "BOOLEAN", "TEXT", "CORRECTION"]
3939

4040
# Text scores are not supported for evals and experiments
4141
ExperimentScoreType = Literal["NUMERIC", "CATEGORICAL", "BOOLEAN"]

0 commit comments

Comments
 (0)