From a Process to Code
Why This Matters
Most failed automations fail before the first line of code: nobody wrote down what the process really is, which decisions it contains, and what should happen when something is unusual. AI makes this worse, because it happily writes code for a process nobody understood. Map the process first.
The order intake process, on paper
At BuitenGear, an outdoor retailer, the purchasing team receives about forty order confirmations from suppliers per week. Today someone reads each email and types the order into the ERP. That takes about six hours a week, and typing errors cause wrong stock and wrong invoices.
Write the process as steps and decisions:
| # | Step | Who / what today | Automated by |
|---|---|---|---|
| 1 | Read the email | Person | sources.py: read the .eml file |
| 2 | Find supplier, order number, date, lines and prices | Person | extract.py: an LLM turns free text into fields |
| 3 | Check the order against the catalogue and the rules | Person, from memory | validate.py: explicit rules |
| 4 | Decision: book or ask? | Person | pipeline.py: no issues → book, issues → human |
| 5 | Type the order into the ERP | Person | erp.py: the ERP’s order API |
Three outcomes, never a silent one
Every message ends in exactly one of three statuses (see intake/pipeline.py):
| Status | When | What happens |
|---|---|---|
booked | Extraction worked and no rule found an issue | The order is in the ERP, with its ERP id logged |
needs_review | Extraction worked, but a rule found an issue | Nothing is booked; a person gets the order and the list of issues |
failed | The LLM answer was unusable, or the ERP refused | Nothing is booked; the error is logged |
The most important design decision is in that table: when in doubt, a human decides. An automation that books a wrong order silently is worse than no automation.
Where the risks are
For each step, ask what can go wrong and how you would notice:
- The LLM misreads or invents a value. Mitigation: the prompt says “do not guess”, and the rules check every value.
- A rule is wrong. Mitigation: tests for every rule, at its boundaries (lesson 8, Testing Business Rules: Boundaries and Breaking It on Purpose).
- The ERP is down or refuses. Mitigation: the status is
failed, nothing is lost, and someone is alerted (lesson 11, CI, Logging and a Human Fallback).
Use AI to challenge your map
Here is a process map for automating supplier order confirmations: <paste the table>.
Which steps, decisions or failure situations am I missing?
Answer as a table: situation, what should happen, how we would notice.
Exercise
- Take the task you chose in lesson 1, Why Python, and What Changes with AI and write it as a table of steps and decisions, like the one above.
- For each step, decide: rule, LLM, integration, or human?
- Define your three outcomes, and what a person receives for each.
- Ask an AI assistant to challenge your map. Add the situations that are real; reject the rest.
Key Takeaways
- Map steps, decisions and outcomes before writing or generating code.
- Every message gets exactly one status: booked, needs review or failed.
- When in doubt, a human decides; nothing is booked silently.
- List the risks per step and how you would notice them.