fix(scores): support CORRECTION score data type#1713
Merged
hassiebp merged 1 commit intoJun 16, 2026
Conversation
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.
7e402ee to
be47c48
Compare
Collaborator
|
Thanks for your contribution, @DavidTraina ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The score methods' type hints omitted the
CORRECTIONscore data type, so the example in the Corrections docs —langfuse.create_score(..., value="...", data_type="CORRECTION")— failed static type checking (mypy/pyrightreport[call-overload]), even though the runtime already accepted it.This adds
CORRECTIONto:ScoreDataTypealias (langfuse/types.py);@overloads and internalcasts ofcreate_score,score_current_span, andscore_current_trace(langfuse/_client/client.py);casts ofLangfuseObservationWrapper.score/score_trace(langfuse/_client/span.py);and updates the corresponding
data_type:/value:docstrings.CORRECTIONis 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_typealready passes straight through toScoreBody, whose generatedScoreDataTypeenum already includesCORRECTION.Fixes: no tracking issue — corrects the documented example linked above.
Type of change
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/unitChecklist
code_review.md.get_args(ScoreDataType)membership test would be a change-detector. The type checker is the effective verification: it now accepts the documentedcreate_score(..., data_type="CORRECTION")example and still rejects numericCORRECTION..env.templateif needed — updated the inlinedata_type:/value:docstrings.langfuse/api/untouched.🤖 Generated with Claude Code
Greptile Summary
This PR adds
CORRECTIONto the publicScoreDataTypealias and to all string-value@overloads (and their internalcasts) ofcreate_score,score_current_span,score_current_trace,LangfuseObservationWrapper.score, andscore_trace. The generated API enum inlangfuse/api/commons/types/score_data_type.pyalready includedCORRECTION, so there is no runtime behaviour change.langfuse/types.py:ScoreDataTypeLiteral type alias now includes"CORRECTION", bringing it in sync with the generatedScoreDataTypeStrEnum.langfuse/_client/client.pyandlangfuse/_client/span.py: All string-value overloads andcastexpressions 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
CORRECTIONto 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]%%{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]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(scores): support CORRECTION score da..." | Re-trigger Greptile