Skip to content

Conditional output bug #80

@endymion

Description

@endymion

LangGraphScore Conditional Outputs Override by Top-Level Output Mappings

Summary

LangGraphScore configurations with conditional outputs are being overridden by top-level output mappings, causing incorrect score results. When a node's conditions should trigger specific output values (e.g., value: "Yes"), the final result shows the classification value instead (e.g., value: "Computer_With_Internet").

Environment

  • Plexus Version: Latest main branch
  • Python Version: 3.11
  • Affected Component: plexus/scores/LangGraphScore.py

Bug Description

Expected Behavior

When a LangGraphScore has a node with conditions that route to END and specify conditional outputs, those outputs should be preserved in the final result, taking precedence over any top-level output mappings.

Actual Behavior

Top-level output mappings (e.g., value: classification) override conditional outputs, causing incorrect results to be returned.

Reproduction Case

Score Configuration

# Simplified example based on "Computer w/ Internet" score (scorecard 1039, score 45417)
output:
  value: classification  # This is overriding conditional outputs

nodes:
  device_response_analyzer:
    type: Classifier
    prompt: "Classify if device has internet access"
    classes:
      - Computer_With_Internet
      - Computer_Without_Internet
      - Mobile_Device
    conditions:
      Computer_With_Internet:
        target: END
        output:
          value: "Yes"  # This should be the final value
          explanation: "Computer with internet access detected"

Test Input

Any input that gets classified as "Computer_With_Internet"

Expected Output

{
  "value": "Yes",
  "explanation": "Computer with internet access detected",
  "classification": "Computer_With_Internet"
}

Actual Output

{
  "value": "Computer_With_Internet",  // ❌ Wrong - should be "Yes"
  "explanation": "Computer with internet access detected",
  "classification": "Computer_With_Internet"
}

Steps to Reproduce

  1. Create a LangGraphScore with:

    • A node that has conditions routing to END
    • Conditional outputs that set specific values
    • Top-level output mapping (e.g., value: classification)
  2. Run a prediction that triggers the condition

  3. Observe that the final result uses the top-level output mapping instead of the conditional output

Technical Analysis

Root Cause

In plexus/scores/LangGraphScore.py, the add_edges method appears to have issues with conditional routing logic:

  1. Final Node Conditions: Conditions on final nodes may not be properly processed
  2. Conditional Routing: The routing from conditional nodes to END may not preserve conditional outputs
  3. Output Priority: Top-level output mappings are taking precedence over conditional outputs

Code Location

The issue is in the add_edges method of the LangGraphScore class, specifically around line areas that handle:

  • Conditional edge creation
  • Final node processing
  • Output aliasing logic

Impact

Severity: High

This bug affects the core functionality of LangGraphScore conditional logic, causing incorrect classification results.

Affected Scores

Any LangGraphScore that uses:

  • Conditional routing to END
  • Conditional outputs that differ from top-level mappings
  • Multiple nodes with conditions

Business Impact

  • Incorrect score results in production
  • Potential misclassification of important data
  • Unreliable conditional logic in complex scoring workflows

Additional Context

Real-World Example

The "Computer w/ Internet" score in production is affected:

  • Scorecard ID: 1039
  • Score ID: 45417
  • Symptom: Returns "Computer_With_Internet" instead of "Yes"

Testing Suggestions

  1. Create unit tests with single-node conditional scenarios
  2. Test multi-node workflows with conditions on middle nodes
  3. Test final node conditions routing to END
  4. Verify output precedence rules

Debugging Information

When testing predictions with the affected score:

# Using MCP service to test
plexus_predict(
    scorecard_name="Computer w/ Internet", 
    score_name="Computer w/ Internet",
    item_id="test_item"
)

Proposed Investigation Steps

  1. Code Review: Examine the add_edges method for conditional routing logic
  2. Debug Logging: Add comprehensive logging to trace output value precedence
  3. Unit Tests: Create regression tests for various conditional scenarios
  4. Integration Testing: Test with real score configurations

Related Files

  • plexus/scores/LangGraphScore.py - Main implementation
  • plexus/scores/LangGraphScore_test.py - Test file for adding regression tests

Labels Suggestion

  • bug
  • high-priority
  • scoring
  • langgraph

Note: This bug affects the reliability of conditional scoring logic and should be prioritized for investigation and resolution.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions