feat(client): add score metadata argument to span client score methods#1498
Merged
feat(client): add score metadata argument to span client score methods#1498
Conversation
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.
Important
Add optional
metadataargument toscoreandscore_tracemethods inlangfuse/_client/span.pyto allow attaching additional data to scores.metadataargument toscore()andscore_trace()methods inlangfuse/_client/span.py.metadatais optional and allows attaching additional data to scores.score()andscore_trace()to includemetadatain all overloads and internalcreate_scorecalls.This description was created by
for 44ce8e0. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Greptile Summary
This PR adds optional
metadataparameter support to thescore()andscore_trace()methods in theLangfuseObservationWrapperclass, enabling users to attach additional contextual data to scores.Changes Made
metadata: Optional[Any] = Noneparameter to both overloads and implementations ofscore()method (lines 280, 294, 307)metadata: Optional[Any] = Noneparameter to both overloads and implementations ofscore_trace()method (lines 363, 377, 390)create_scorecalls to pass the metadata parameter through (lines 349, 432)Implementation Details
The implementation correctly passes the metadata parameter through to the underlying
create_scoremethod in the Langfuse client, which already supports metadata via theScoreBodyAPI type. The feature is backward compatible since metadata is optional and defaults toNone.Issue Found
Parameter Order Inconsistency: The PR adds
metadataaftertimestampin the method signatures, but the underlyingcreate_scoremethod inclient.pyhasmetadatabeforetimestamp. While this doesn't cause functional issues (all parameters are keyword-only), it creates an API inconsistency that could confuse developers and violates the principle of matching parameter order with the underlying implementation.Confidence Score: 4/5
Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant User participant Span as LangfuseObservationWrapper participant Client as Langfuse Client participant API as Score API User->>Span: span.score(name, value, metadata={...}) Note over Span: Validates parameters<br/>Prepares score data Span->>Client: create_score(name, value, trace_id, observation_id, metadata) Note over Client: Creates ScoreBody<br/>with metadata field Client->>API: POST score-create event Note over API: Score stored with<br/>attached metadata API-->>Client: Success Client-->>Span: Score created Span-->>User: Returns User->>Span: span.score_trace(name, value, metadata={...}) Note over Span: Validates parameters<br/>Prepares trace score Span->>Client: create_score(name, value, trace_id, metadata) Note over Client: Creates ScoreBody<br/>with metadata field Client->>API: POST score-create event Note over API: Trace score stored<br/>with metadata API-->>Client: Success Client-->>Span: Score created Span-->>User: Returns