Skip to content

StepCondition

Base classes

Name Children Inherits
Schema
schemez.schema
Base class for configuration models.

⋔ Inheritance diagram

graph TD
  1128385590["chain.StepCondition"]
  330168112["schema.Schema"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  330168112 --> 1128385590
  3879467795 --> 330168112
  2751680898 --> 3879467795

🛈 DocStrings

Bases: Schema

Condition for conditional execution.

Source code in src/llmling/core/chain.py
class StepCondition(Schema):
    """Condition for conditional execution."""

    field: str  # Field to check in result
    operator: Literal["eq", "gt", "lt", "contains", "exists"]
    value: Any = None

    def evaluate_with_value(self, value: Any) -> bool:
        """Evaluate this condition against a value.

        Args:
            value: The value to evaluate against the condition.

        Returns:
            bool: True if the condition is met, False otherwise.
        """
        field_value = value.get(self.field) if isinstance(value, dict) else value

        match self.operator:
            case "eq":
                return field_value == self.value
            case "gt":
                return field_value > self.value
            case "lt":
                return field_value < self.value
            case "contains":
                try:
                    return self.value in field_value
                except TypeError:
                    return False
            case "exists":
                return field_value is not None

evaluate_with_value

evaluate_with_value(value: Any) -> bool

Evaluate this condition against a value.

Parameters:

Name Type Description Default
value Any

The value to evaluate against the condition.

required

Returns:

Name Type Description
bool bool

True if the condition is met, False otherwise.

Source code in src/llmling/core/chain.py
def evaluate_with_value(self, value: Any) -> bool:
    """Evaluate this condition against a value.

    Args:
        value: The value to evaluate against the condition.

    Returns:
        bool: True if the condition is met, False otherwise.
    """
    field_value = value.get(self.field) if isinstance(value, dict) else value

    match self.operator:
        case "eq":
            return field_value == self.value
        case "gt":
            return field_value > self.value
        case "lt":
            return field_value < self.value
        case "contains":
            try:
                return self.value in field_value
            except TypeError:
                return False
        case "exists":
            return field_value is not None

:fa-brands-github: Show source on GitHub