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
Workflow-contract check: handoff.actionsAvailable must be a list containing at least approve, revise, reject, and escalate. The field is missing, not a list, or omits one of the four, meaning the human at the handoff point would lack a complete decision vocabulary.
Solutions
- Set actionsAvailable to ["approve", "revise", "reject", "escalate"] in the workflow JSON
- Generate the canonical action list from a shared constant so it cannot drift
- Validate the handoff block before computing next_action and name the missing actions
Defensive patterns
Strategy: validation
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.
Appendix: 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)