Add meaningful human approval
Tie approval to the exact draft and keep changed or expired work on hold. This module has 3 lessons and takes about 1h 50m. Each lesson has a practice exercise that runs real Python in your browser and a short quiz.
Start module 12 in the Learning LabRequire an explicit decision
Map approved to proceed, rejected to stop, and every other decision to wait.
A review step needs a clear decision. In this teaching workflow, approved means proceed, rejected means stop, and any other value means wait.
Compare exact status strings. A missing decision is not approval. Do not use general truthiness because the string rejected is also truthy in Python.
Record who reviewed the work and what they saw. A status field alone does not establish who had authority to approve.
See it in action
def solve(decision):
if decision == "approved":
return "proceed"
if decision == "rejected":
return "stop"
return "wait"
print(solve("approved"))
Record who reviewed the work and what they saw. A status field alone does not establish who had authority to approve.
Bind approval to a version
Return True only when status is approved and the current draft version matches the approved version.
An approval belongs to the version that was reviewed. Changing the recipient or text after approval should require a new review.
This function compares the current draft version with the approved version and checks an explicit approved status. In a real system the version should identify all action-relevant fields.
An old approval must not silently authorise a new draft. Keep the approved content and decision together.
See it in action
def solve(current_version, approved_version, status):
return status == "approved" and current_version == approved_version
print(solve("v2", "v2", "approved"))
An old approval must not silently authorise a new draft. Keep the approved content and decision together.
Practical: Enforce an approval gate
Return a boolean approval gate using exact approved status, matching versions, reviewer_allowed=True, and now less than expires.
Combine decision, version, reviewer authority, and expiry before an action. The inputs here come from a trusted application record, not from AI output.
The gate passes only for an approved matching version, an authorised reviewer, and a current time strictly before expiry. At the expiry time, the approval is no longer valid.
This is a local permission check. A production action should recheck current state immediately before execution and record the outcome.
Your experiment plan
Use the browser editor or the notebook. All records and AI responses are fictional. No network calls, credentials, or real messages are used.
- Define who can approve the fictional workshop draft and for how long.
- Run the example and predict its result before changing it.
- Complete the function in Practice and run the checks. Add your own normal, empty, and failure cases.
- Change each gate input one at a time and inspect the decision.
- Save the notebook with your observations and explain one limitation of the simulation.
What to hand in
- An approval record design and a tested gate with expiry and version cases.
- A test table with inputs, expected outputs, actual outputs, and one revision.
Reflect on your results
What happens if the draft changes during execution?
The automatic exercise checks the core code behaviour. Review observations and written deliverables yourself or with a mentor.
See it in action
def solve(status, version, approved_version, reviewer_allowed, now, expires):
return status == "approved" and version == approved_version and reviewer_allowed is True and now < expires
print(solve("approved", "v1", "v1", True, 100, 200))
This is a local permission check. A production action should recheck current state immediately before execution and record the outcome.
Free, open and run by a nonprofit.
This page is part of AI Automation, a free course of 20 modules and 60 lessons in the engineering.fit( ) Learning Lab. The Learning Lab is built and run by engineering.fit( ), a nonprofit founded by Abdullateef Opeyemi Bakare that helps African engineering students gain research experience. You do not need an account or pay a fee to learn.