fix(experiments): move evals out of root span #1437
Merged
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
Move evaluator execution out of the root span in
_process_experiment_item()inclient.pyto ensure evaluations run independently of task execution._process_experiment_item()inclient.py.langfuse_logger.error().client.py.This description was created by
for dad3bfe. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Greptile Summary
Moved evaluator execution outside the
experiment-item-runspan context to prevent evaluation operations from being nested under the root experiment span.Key changes:
observation_id=span.idwithblocks after exitConfidence Score: 4/5
withblocks), error handling is preserved (evaluators only run on success), and the span.id reference is valid after context exit since it's an instance attribute.Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant Client as Langfuse Client participant Span as Experiment Span participant Task as User Task participant Eval as Evaluators Client->>Span: start_as_current_span("experiment-item-run") activate Span Span->>Task: run task with item input Task-->>Span: return output Span->>Span: update span with input/output Client->>Span: exit span context deactivate Span Note over Client,Eval: Evaluators run OUTSIDE span context loop For each evaluator Client->>Eval: run_evaluator(input, output, expected_output) Eval-->>Client: evaluation results Client->>Client: create_score(trace_id, observation_id=span.id) end Client->>Client: return ExperimentItemResult