Workflow automation in code
Define the lab goal and success criteria
Workflow automation in code is production work only when one frozen failure can be reproduced, one measurable gate can stop a release, and one operator can safely reverse it.
1Try it yourself
Playground
Workflow automation wire-up
Map trigger → LLM step → action — with idempotency and human confirm on sends.
New row in Google Sheet
Before you start
Why this matters
Read this incident aloud: a ticket webhook is delivered three times and the model marks an ambiguous message as urgent. In two minutes, write the earliest deterministic check that should fail, the telemetry signal you would inspect, and the action that must not happen automatically. Compare your answer with this chapter's boundary: verify webhook signatures before parsing; the model proposes actions but cannot send externally.
2Learn the idea
Read
Explain the system and define success
Start by drawing the boundary around a webhook-to-LLM support triage workflow with a human-approved outbound action. The unit under control is not “the model”; it is one repeatable transaction from WebhookEvent with event_id, signature, occurred_at, ticket_id, text, and dry_run to TriageDecision with category, urgency, confidence, evidence, proposed_action, and approval_required. In this lab, a ticket webhook is delivered three times and the model marks an ambiguous message as urgent. That makes the learning target observable: we can replay the transaction, record the same fields, and decide whether a release is safer than its baseline. The primary decision metric is correct actions per unique event. The release rule is zero duplicate sends, at least 0.90 triage precision, and 100% approval for outbound messages. Those values are deliberately paired: a single average cannot hide a critical subgroup or a security escape.
Write the failure before writing implementation code. Our named reproduction is: the retry handler posts three Slack alerts because idempotency is recorded after the side effect. A useful reproduction contains a frozen input, an expected decision, the release identifier, and enough deterministic dependencies to rerun locally. It must not depend on a live customer, changing clock, or unrestricted provider account. The fixture below is synthetic but shaped like production. Keep it in version control and add a case whenever an incident exposes a missing behavior.
Success has three levels. A request-level assertion explains one example. An aggregate metric catches drift over many examples. An operational rule says who acts and how quickly. Here, workflow_action_total records the aggregate, while the request artifact carries a correlation ID. The owner should be able to move from an alert to the exact failing fixture without searching raw prompts. The security boundary is equally explicit: verify webhook signatures before parsing; the model proposes actions but cannot send externally.
The deliverable is a one-page acceptance contract plus the first red test. Do not tune a model yet; uncertainty about the contract is the bug to remove on this page.
Read
Focused implementation artifact
{"event_id":"evt_884","signature":"test-valid","occurred_at":"2026-07-18T05:10:00Z","ticket_id":"T-91","text":"Maybe locked out; payroll closes today","dry_run":true}
Read
Turn the incident into a lab contract
Use the fixture above as the first row of an acceptance table. Add columns for expected decision, prohibited side effect, severity, policy version, and evidence to retain. The failure statement—the retry handler posts three Slack alerts because idempotency is recorded after the side effect—must be falsifiable: a teammate should know exactly which assertion turns red. Write the baseline result before trying a candidate so improvement is comparative rather than anecdotal.
Now calculate correct actions per unique event by hand for a three-case toy set: one pass, one ordinary failure, and one critical failure. Apply the published gate, zero duplicate sends, at least 0.90 triage precision, and 100% approval for outbound messages, without rounding. This exposes whether weighting, critical-case overrides, and empty slices behave as intended. Emit workflow_action_total once for the toy run and verify that its labels contain a bounded release and outcome, never fixture text.
The lab is ready only when its fixture is synthetic, its dangerous actions are replaced by recording fakes, and its evidence can be retained safely. The expected incident response is to record the proposal transactionally, request human approval, and execute once with an idempotency key. Assign that decision to a role, not “the team,” and state which artifact proves recovery.
Continue learning · glossary & guides
-
Is the failure falsifiable from one frozen fixture?
-
Does the gate combine a population metric with critical-case handling?
-
Are owner, evidence, and forbidden action explicit?
-
Local references: Glossary: webhook · Glossary: idempotency