rohitg00/ai-engineering-from-scratch · error · ValueError

unknown operator

Error message

unknown operator: {self.operator}

What it means

Raised in EvaluationGate.passes when the gate's operator string is not one of '>=', '<=', '=='. The comparison dispatch table has no entry for the operator, so the gate cannot be evaluated; the operator field on the gate object is the faulty input.

Solutions

  1. Use one of the supported comparison operators in the gate definition
  2. Extend the operations dict (e.g. with '<' or '>') if a new gate kind is needed
  3. Catch the ValueError in gate-loading tests to assert unknown operators are rejected
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at certifications/claude/lessons/32-architect-professional-system-capstone/code/main.py:60 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/9860ac2cbeb42781. Report an issue: GitHub.

Appendix: source

Thrown at certifications/claude/lessons/32-architect-professional-system-capstone/code/main.py:60

    hard_gate: bool = False


@dataclass(frozen=True)
class EvaluationGate:
    metric: str
    observed: float
    operator: str
    threshold: float
    segment: str = "all"

    def passes(self) -> bool:
        operations = {
            ">=": lambda value, target: value >= target,
            "<=": lambda value, target: value <= target,
            "==": lambda value, target: value == target,
        }
        if self.operator not in operations:
            raise ValueError(f"unknown operator: {self.operator}")
        return operations[self.operator](self.observed, self.threshold)


@dataclass(frozen=True)
class ArchitecturePacket:
    outcome: str
    non_goals: tuple[str, ...]
    requirements: tuple[Requirement, ...]
    decisions: tuple[Decision, ...]
    controls: tuple[Control, ...]
    evaluation_gates: tuple[EvaluationGate, ...]
    rollback_runbook: str
    operating_owner: str


@dataclass(frozen=True)
class Finding:
    category: str

View on GitHub (pinned to 39ea8a1c6d)