Skip to content

fix(scores): support CORRECTION score data type#1713

Merged
hassiebp merged 1 commit into
langfuse:mainfrom
DavidTraina:fix/correction-score-data-type
Jun 16, 2026
Merged

fix(scores): support CORRECTION score data type#1713
hassiebp merged 1 commit into
langfuse:mainfrom
DavidTraina:fix/correction-score-data-type

Conversation

@DavidTraina

@DavidTraina DavidTraina commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

The score methods' type hints omitted the CORRECTION score data type, so the example in the Corrections docslangfuse.create_score(..., value="...", data_type="CORRECTION") — failed static type checking (mypy/pyright report [call-overload]), even though the runtime already accepted it.

This adds CORRECTION to:

  • the public ScoreDataType alias (langfuse/types.py);
  • the string-value @overloads and internal casts of create_score, score_current_span, and score_current_trace (langfuse/_client/client.py);
  • the string-value overloads and casts of LangfuseObservationWrapper.score / score_trace (langfuse/_client/span.py);

and updates the corresponding data_type: / value: docstrings. CORRECTION is string-valued, so it is added only to the string overloads; the numeric overloads continue to reject it. There is no runtime behavior change — data_type already passes straight through to ScoreBody, whose generated ScoreDataType enum already includes CORRECTION.

Fixes: no tracking issue — corrects the documented example linked above.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update
  • Tooling, CI, or repo maintenance

Verification

List the main commands you ran:

uv run --frozen mypy langfuse --no-error-summary
uv run --frozen ruff check .
uv run --frozen ruff format --check langfuse/types.py langfuse/_client/client.py langfuse/_client/span.py
uv run --frozen pytest -n auto --dist worksteal tests/unit

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes — N/A: type-hint-only change with no runtime behavior change. A runtime test would pass identically before and after, and a get_args(ScoreDataType) membership test would be a change-detector. The type checker is the effective verification: it now accepts the documented create_score(..., data_type="CORRECTION") example and still rejects numeric CORRECTION.
  • I updated docs, examples, or .env.template if needed — updated the inline data_type: / value: docstrings.
  • I did not hand-edit generated files; if generated files changed, I used the upstream regeneration path — langfuse/api/ untouched.
  • I did not commit secrets or credentials.

🤖 Generated with Claude Code

Greptile Summary

This PR adds CORRECTION to the public ScoreDataType alias and to all string-value @overloads (and their internal casts) of create_score, score_current_span, score_current_trace, LangfuseObservationWrapper.score, and score_trace. The generated API enum in langfuse/api/commons/types/score_data_type.py already included CORRECTION, so there is no runtime behaviour change.

  • langfuse/types.py: ScoreDataType Literal type alias now includes "CORRECTION", bringing it in sync with the generated ScoreDataType StrEnum.
  • langfuse/_client/client.py and langfuse/_client/span.py: All string-value overloads and cast expressions are updated consistently; numeric overloads are untouched; docstrings are refreshed to list the new type.

Confidence Score: 5/5

Safe to merge — this is a type-hint-only change that brings public aliases in line with the already-shipped generated API enum; no runtime logic is altered.

All three changed files make consistent, surgical additions of CORRECTION to string-value overloads and casts. The underlying API enum already carried the value, so there is no surface for new runtime breakage. The single observation is a documentation comment that could be more precise.

No files require special attention; changes are localised to type annotations and docstrings.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Caller passes value and data_type] --> B{value type?}
    B -- float --> C["Overload: NUMERIC or BOOLEAN"]
    B -- str --> D["Overload: CATEGORICAL, TEXT, or CORRECTION"]
    C --> E[create_score / score / score_trace]
    D --> E
    E --> F[cast data_type to internal Literal]
    F --> G[ScoreBody to Langfuse API]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Caller passes value and data_type] --> B{value type?}
    B -- float --> C["Overload: NUMERIC or BOOLEAN"]
    B -- str --> D["Overload: CATEGORICAL, TEXT, or CORRECTION"]
    C --> E[create_score / score / score_trace]
    D --> E
    E --> F[cast data_type to internal Literal]
    F --> G[ScoreBody to Langfuse API]
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
langfuse/types.py:40-41
The comment on this line only mentions "Text scores" but `CORRECTION` is also a string-valued type that is intentionally absent from `ExperimentScoreType`. Updating the comment to cover both keeps future readers from wondering whether the omission of `CORRECTION` from `ExperimentScoreType` was accidental.

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

Reviews (1): Last reviewed commit: "fix(scores): support CORRECTION score da..." | Re-trigger Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Jun 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.
@DavidTraina DavidTraina force-pushed the fix/correction-score-data-type branch from 7e402ee to be47c48 Compare June 16, 2026 02:28
@hassiebp

Copy link
Copy Markdown
Collaborator

Thanks for your contribution, @DavidTraina !

@hassiebp hassiebp merged commit 53d98c9 into langfuse:main Jun 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants