codebaobab
Python workspace

All problemsData & Systems

Expense Approval Workflow

Build an expense approval engine from a one-page spec.

Python55 minutesData & Systems

Challenge brief

Read before you begin

Your mission · Build from a spec

Build the engine that routes expense reports through their approvals and records every decision.

An internal audit found a regional manager who approved his own $3,800 hotel bill, and 412 reports that have waited more than 30 days because the email routing lost them. The auditors want a fix in place by January 15, or the finance team must review every report by hand.

  • Target · All public checks
  • Mode · Build from a spec
Skip to round setup

Your assignment

  1. Read docs/spec.md and choose the data model.
  2. Build the approval chain, shown by status.
  3. Add approve, reject, resubmit, inbox and log.
  4. Handle the new requirement when it arrives.
  5. Write the model and next steps in NOTES.md.

The problem

Managers approve their own reports

The email macro sends a report to the manager field, even when that is the submitter.

Impact: Audit finding 2026-14 against the controls of the finance team.

Reports get lost after a rejection

A rejected report goes nowhere, and nobody knows who must act next.

Impact: 412 reports waiting more than 30 days to be paid.

The chain and decisions are stubs

Routing and decisions raise NotImplementedError.

Impact: The engine cannot replace the macro before January 15.

Context

Self-approved by a manager
$3,800
Reports stuck 30+ days
412
Audit deadline
Jan 15

Requirements

  • Chain: manager, second level, category, finance.
  • "Over" means strictly greater.
  • Nobody approves their own report.
  • A missing manager goes to the fallback.
  • Each person once, at their first place.
  • Only the current approver decides.
  • A resubmission starts from the first step.
  • status, inbox and log change nothing.

System overview

Edit the components marked “Your work”. The other components show where your changes fit.

Expense appSubmits expense reports
Approval engine(Your work)Routes reports, records decisions
HR directoryOrg chart
Approver inboxApprove or reject
PayrollPays approved reports
Audit trailDecision log
Read the connections
  • Expense app → Approval engine: submit, resubmit
  • HR directory → Approval engine: org chart
  • Approver inbox → Approval engine: approve, reject
  • Approval engine → Payroll: approved reports
  • Approval engine → Audit trail: decision log
  • Expense app: Technicians submit and resubmit reports from their phones.
  • Approval engine: simulate(policy, events) in approvals/workflow.py; the chain in approvals/services/routing.py.
  • HR directory: Everyone's manager, synced every night.
  • Approver inbox: Managers, the IT lead, finance and audit approve or reject here.
  • Payroll: Pays approved reports with the next paycheck.
  • Audit trail: Every decision, kept seven years.

Data model

Policy

FieldTypeNotes
people{id: {manager}}Everyone who submits or approves. The top of the org has manager null.
second_level_overinteger centsOver this, the manager's manager approves too. Larkspur: 100000 ($1,000).
finance_overinteger centsOver this, finance approves last. Larkspur: 500000 ($5,000).
finance, fallbackperson idThe finance approver, and internal audit for steps nobody else can take.
categories{name: approver or null}Software needs the IT lead.

Report

FieldTypeNotes
reportstringThe expense app's id, for example "EXP-7102".
employeeperson idThe submitter.
amountinteger cents1 or more.
chain, stepperson ids, indexWho approves, in order, and who is next.
state"pending", "returned" or "approved"
entrieslistThe decision log, oldest first.

Details

Full requirements

Functional

  1. simulate(policy, events) runs the events in order on a new workflow and returns one result per event. The policy holds the people and their managers, the two thresholds in cents, the finance and fallback approvers, and the categories.
  2. The chain is, in order: the submitter's manager; the manager's manager when the amount is over second_level_over; the category's approver when it has one; finance when the amount is over finance_over. This is the order the finance policy signs off in: the people who know the work first, money last.
  3. Nobody approves their own report, which is the audit finding: a step that would go to the submitter, or to nobody at the top of the org, goes to the fallback approver from internal audit. Each person appears once, at their first place.
  4. Only the current approver may approve or reject. A rejection needs a reason and returns the report to the submitter, who may resubmit it with a new amount; the chain is then worked out again from the first step, because the old approvals were for a different amount.
  5. status, inbox and log answer questions without changing anything. The log keeps every submission, decision and resubmission in order, with the reason for each rejection.
  6. Bad input raises ValueError naming the field, and any other op raises ValueError mentioning op.

Non-functional

  • Scale: about 9,000 reports a month, 450 on a busy day, with chains of one to four people.
  • Determinism: replaying the event log must reproduce every result exactly. Amounts are whole cents, so no threshold depends on floating point.
  • Audit: every decision is kept with who made it, in order, for seven years. Nothing is ever removed from a log.
  • Latency: the approver inbox asks for a person's reports when they open it. An inbox over a month of reports must answer in under 100 ms.
  • Cost of a wrong answer: a self-approval is an audit finding; a report sent to the wrong person waits about 9 days on average before someone notices.

Out of scope

  • Receipts, mileage rates and per diem rules. The amount comes from the expense app.
  • Email and push notifications to approvers.
  • Paying the report. Payroll reads approved reports on its own schedule.
  • The HTTP layer in practice_api/ and the HR directory sync.
Files you are given · 6
  • config/policy.json Larkspur's finance policy in the format simulate reads: the org chart, the two thresholds and the category approvers.
    {
      "people": {
        "olu": {
          "manager": null
        },
        "dee": {
          "manager": "olu"
        },
        "lee": {
          "manager": "olu"
        },
        "fay": {
          "manager": "olu"
        },
        "ann": {
          "manager": "olu"
        },
        "raj": {
          "manager": "dee"
        },
        "mia": {
          "manager": "dee"
        },
        "tom": {
          "manager": "raj"
        },
        "kim": {
          "manager": "raj"
        }
      },
      "second_level_over": 100000,
      "finance_over": 500000,
      "finance": "fay",
      "fallback": "ann",
      "categories": {
        "travel": null,
        "meals": null,
        "tools": null,
        "software": "lee"
      }
    }
  • docs/org-chart.md Who each id in the policy is, and their role.
    # Who is who in the policy
    
    | id | Role | Manager |
    | --- | --- | --- |
    | olu | Chief operating officer | none |
    | dee | VP field operations | olu |
    | lee | IT lead, approves software | olu |
    | fay | Finance controller, approves over $5,000 | olu |
    | ann | Internal audit, the fallback approver | olu |
    | raj | Regional manager, Ohio Valley | dee |
    | mia | Regional manager, Great Lakes | dee |
    | tom | Elevator technician | raj |
    | kim | HVAC technician | raj |
  • samples/one-week.json A small week: four reports, one rejected and resubmitted, a manager's own report and the IT lead's own software. Arguments for Preview.
    [
      {
        "people": {
          "olu": {
            "manager": null
          },
          "dee": {
            "manager": "olu"
          },
          "lee": {
            "manager": "olu"
          },
          "fay": {
            "manager": "olu"
          },
          "ann": {
            "manager": "olu"
          },
          "raj": {
            "manager": "dee"
          },
          "mia": {
            "manager": "dee"
          },
          "tom": {
            "manager": "raj"
          },
          "kim": {
            "manager": "raj"
          }
        },
        "second_level_over": 100000,
        "finance_over": 500000,
        "finance": "fay",
        "fallback": "ann",
        "categories": {
          "travel": null,
          "meals": null,
          "tools": null,
          "software": "lee"
        }
      },
      [
        {
          "op": "submit",
          "report": "EXP-7101",
          "employee": "tom",
          "amount": 8640,
          "category": "meals"
        },
        {
          "op": "submit",
          "report": "EXP-7102",
          "employee": "kim",
          "amount": 214500,
          "category": "tools"
        },
        {
          "op": "submit",
          "report": "EXP-7103",
          "employee": "raj",
          "amount": 380000,
          "category": "travel"
        },
        {
          "op": "submit",
          "report": "EXP-7104",
          "employee": "lee",
          "amount": 59900,
          "category": "software"
        },
        {
          "op": "approve",
          "report": "EXP-7101",
          "by": "raj"
        },
        {
          "op": "approve",
          "report": "EXP-7102",
          "by": "raj"
        },
        {
          "op": "reject",
          "report": "EXP-7102",
          "by": "dee",
          "reason": "Split the torque wrench and the cart into two reports"
        },
        {
          "op": "resubmit",
          "report": "EXP-7102",
          "by": "kim",
          "amount": 96500
        },
        {
          "op": "approve",
          "report": "EXP-7103",
          "by": "dee"
        },
        {
          "op": "inbox",
          "person": "raj"
        },
        {
          "op": "inbox",
          "person": "olu"
        },
        {
          "op": "status",
          "report": "EXP-7104"
        },
        {
          "op": "log",
          "report": "EXP-7102"
        }
      ]
    ]
  • samples/one-week-expected.json What the spec says that week returns, event by event.
    [
      {"report": "EXP-7101", "state": "pending", "approver": "raj"},
      {"report": "EXP-7102", "state": "pending", "approver": "raj"},
      {"report": "EXP-7103", "state": "pending", "approver": "dee"},
      {"report": "EXP-7104", "state": "pending", "approver": "olu"},
      {"report": "EXP-7101", "state": "approved"},
      {"report": "EXP-7102", "state": "pending", "approver": "dee"},
      {"report": "EXP-7102", "state": "returned", "to": "kim"},
      {"report": "EXP-7102", "state": "pending", "approver": "raj"},
      {"report": "EXP-7103", "state": "pending", "approver": "olu"},
      {"person": "raj", "reports": ["EXP-7102"]},
      {"person": "olu", "reports": ["EXP-7103", "EXP-7104"]},
      {"report": "EXP-7104", "state": "pending", "chain": ["olu", "ann"], "approver": "olu"},
      {"report": "EXP-7102", "state": "pending", "entries": [{"action": "submitted", "by": "kim", "amount": 214500}, {"action": "approved", "by": "raj"}, {"action": "rejected", "by": "dee", "reason": "Split the torque wrench and the cart into two reports"}, {"action": "resubmitted", "by": "kim", "amount": 96500}]}
    ]
  • reports/audit-finding-2026-14.md The audit finding behind this work, with the January 15 deadline.
    # Audit finding 2026-14: expense approvals
    
    Severity: high. Owner: Finance Systems. Due: 2027-01-15.
    
    1. Report EXP-5530 ($3,800.00, travel) was submitted by a regional manager and approved by the
       same person. The macro sends each report to the manager field the submitter fills in.
    2. 412 reports from August to October waited more than 30 days. 371 of them had been rejected
       once; the macro has no step for a rejected report, so the reply email was the only record.
    3. No single record shows who approved a report and in what order.
    
    Required: an approval chain worked out from the org chart and the policy, no self-approval, a
    clear owner for every open report, and a decision log.
  • metrics/open-reports-2026-11.csv Reports submitted, approved and returned each week, and how many have waited more than 30 days.
    week,submitted,approved,returned,open_over_30_days,median_days_to_pay
    2026-11-02,2104,1876,141,398,11
    2026-11-09,2230,1941,152,405,12
    2026-11-16,2187,1902,133,409,12
    2026-11-23,2251,1988,160,412,13
Tickets · 4
  • TASK-201 Read docs/spec.md and decide the data model Reported by Grace (finance systems)

    Expected NOTES.md says what a report holds and how you know who it waits on, and why that is enough for rejections and resubmissions.

    Actual Workflow stores reports, but nothing writes down what a decision changes, and the chain and the decisions are stubs.

  • TASK-202 Core: the approval chain for a report, shown by status Reported by Grace (finance systems)

    Expected EXP-7104 from the IT lead has the chain ["olu", "ann"]: his manager, then the fallback in place of himself.

    Actual Every submission fails with NotImplementedError: "Implement approval_chain using the request contract".

  • TASK-203 Then approvals, rejections and resubmission, then the inbox and the log Reported by Hector (accounts payable)

    Expected Every result matches the expected file. EXP-7102 is back with raj after the resubmission, and its log has all four entries.

    Actual The first approval fails with NotImplementedError: "Implement Workflow.decide using the request contract".

  • TASK-204 Write down anything you chose to leave out or would do next Reported by Nadia (controller)

    Expected A short list of what the engine does not handle yet and what you would build next, with a reason for each.

    Actual NOTES.md has no entry.

What you hand in
  • Every public check passing, including the new requirement when it arrives.
  • NOTES.md: the data model in a few lines, the order you built it in, and what you left out or would do next.
  • Your answer to the interviewer's follow-up and the debrief questions.
How the work is judged
Breaking down the work
States the data model before asking for code, then builds the chain, decisions, resubmission, the inbox and the log in that order, with the checks run after each.
Directing the assistant
Hands the assistant one function at a time with the spec rule it must follow, such as the four steps in order and the two cases that use the fallback.
Checking the work
Works chains out by hand from the org chart, checks the week in samples/ against its expected file, and tries the top of the org and the IT lead's own software.
Judging the assistant
Rejects a chain that drops the submitter instead of using the fallback, a set that loses the order, or approvals kept across a resubmission.
Correct result
All checks pass, including exactly $1,000, the fallback listed once, decisions by the current approver only, and the follow-up delegation.
Explaining the work
Explains the chain rules and the report states in a few sentences an auditor could follow, and names what was left out.
Trade-offs to discuss
  • Storing the chain when a report is submitted versus working it out again on each decision, when the org chart changes in the middle.
  • Sending a step that would go to the submitter to the fallback versus to the next manager up, and what each does to audit's workload.
  • Starting a resubmission from the first step versus keeping approvals for an amount that went down.
  • Keeping the log inside each report versus one log for the whole engine.
How you are graded
  • Decomposition 25%
  • Prompting the assistant 15%
  • Verification 20%
  • Judgment about AI output 10%
  • Correctness 20%
  • Communication 10%

Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard

Interview guidance

Build the engine that routes expense reports for approval. The chain depends on the amount, the category and the org chart, and nobody may approve their own report. The spec is one page. Start with a working core and grow it. Use the AI assistant however you like, and tell me your data model before you ask it for code.

  • AI is allowed and expected: your own Claude, OpenAI or Gemini key, or the free in-browser model.
  • You are graded on how you drive and check the AI, not on how much you prompt.
  • Run the checks; read what fails.
  • A new requirement will arrive partway through.
  • Too little AI use is reported as “not enough to grade”, never as a fail.
Debrief · 8 questions
  • What did you delegate to the AI, and why?
  • Name one AI suggestion you rejected or changed, and why.
  • Choose one block the AI helped write. Explain what each line does and which test verifies it.
  • What is still risky, and what would you test or ship next?
  • What was your core, and how long did it take to get its first check passing?
  • What is your data model, and what did you decide yourself before asking the assistant?
  • Which edge case did you test that the assistant's first version got wrong?
  • What did you leave out, and what would you build next?