{"record":{"id":"df1c2a1b35eb0a97","repo":"rohitg00/ai-engineering-from-scratch","slug":"handoff-must-expose-approve-revise-reject-and-e","errorCode":null,"errorMessage":"handoff must expose approve, revise, reject, and escalate","messagePattern":"handoff must expose approve, revise, reject, and escalate","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/07-workflow-design-and-human-handoffs/code/main.py","lineNumber":61,"sourceCode":"    handoff = workflow.get(\"handoff\")\n    if not isinstance(handoff, dict) or HANDOFF_FIELDS - set(handoff):\n        errors.append(\"handoff is incomplete\")\n    else:\n        for field in HANDOFF_FIELDS - {\"checksPassed\", \"checksFailed\", \"actionsAvailable\"}:\n            if not str(handoff.get(field, \"\")).strip():\n                errors.append(f\"handoff.{field} is required\")\n        if not isinstance(handoff.get(\"checksFailed\"), list):\n            errors.append(\"handoff.checksFailed must be a list\")\n        actions = handoff.get(\"actionsAvailable\")\n        if not isinstance(actions, list) or not {\"approve\", \"revise\", \"reject\", \"escalate\"} <= set(actions):\n            errors.append(\"handoff must expose approve, revise, reject, and escalate\")\n    return errors\n\n\ndef next_action(workflow: dict[str, Any]) -> dict[str, Any]:\n    errors = validate_workflow(workflow)\n    if errors:\n        raise ValueError(\"; \".join(errors))\n    handoff = workflow[\"handoff\"]\n    return {\"decisionRequired\": handoff[\"decisionRequired\"], \"failedChecks\": handoff[\"checksFailed\"], \"recommendedAction\": \"escalate\" if handoff[\"checksFailed\"] else \"approve\", \"fallback\": handoff[\"fallback\"]}\n\n\ndef load_workflow(path: Path) -> dict[str, Any]:\n    value = json.loads(path.read_text(encoding=\"utf-8\"))\n    if not isinstance(value, dict):\n        raise ValueError(\"workflow root must be an object\")\n    return value\n\n\nif __name__ == \"__main__\":\n    path = Path(__file__).parents[1] / \"outputs\" / \"workflow-handoff-packet.json\"\n    workflow = load_workflow(path)\n    print(json.dumps({\"valid\": not validate_workflow(workflow), \"next\": next_action(workflow)}, indent=2))\n","sourceCodeStart":43,"sourceCodeEnd":77,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/07-workflow-design-and-human-handoffs/code/main.py#L43-L77","documentation":"Error \"handoff must expose approve, revise, reject, and escalate\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at certifications/claude/lessons/07-workflow-design-and-human-handoffs/code/main.py:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}