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

handoff must expose approve, revise, reject, and escalate

Error message

handoff must expose approve, revise, reject, and escalate

What it means

Error "handoff must expose approve, revise, reject, and escalate" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at certifications/claude/lessons/07-workflow-design-and-human-handoffs/code/main.py:61

    handoff = workflow.get("handoff")
    if not isinstance(handoff, dict) or HANDOFF_FIELDS - set(handoff):
        errors.append("handoff is incomplete")
    else:
        for field in HANDOFF_FIELDS - {"checksPassed", "checksFailed", "actionsAvailable"}:
            if not str(handoff.get(field, "")).strip():
                errors.append(f"handoff.{field} is required")
        if not isinstance(handoff.get("checksFailed"), list):
            errors.append("handoff.checksFailed must be a list")
        actions = handoff.get("actionsAvailable")
        if not isinstance(actions, list) or not {"approve", "revise", "reject", "escalate"} <= set(actions):
            errors.append("handoff must expose approve, revise, reject, and escalate")
    return errors


def next_action(workflow: dict[str, Any]) -> dict[str, Any]:
    errors = validate_workflow(workflow)
    if errors:
        raise ValueError("; ".join(errors))
    handoff = workflow["handoff"]
    return {"decisionRequired": handoff["decisionRequired"], "failedChecks": handoff["checksFailed"], "recommendedAction": "escalate" if handoff["checksFailed"] else "approve", "fallback": handoff["fallback"]}


def load_workflow(path: Path) -> dict[str, Any]:
    value = json.loads(path.read_text(encoding="utf-8"))
    if not isinstance(value, dict):
        raise ValueError("workflow root must be an object")
    return value


if __name__ == "__main__":
    path = Path(__file__).parents[1] / "outputs" / "workflow-handoff-packet.json"
    workflow = load_workflow(path)
    print(json.dumps({"valid": not validate_workflow(workflow), "next": next_action(workflow)}, indent=2))

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at certifications/claude/lessons/07-workflow-design-and-human-handoffs/code/main.py:61 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/df1c2a1b35eb0a97. Report an issue: GitHub.