0The workflow and the production rule
Companion: The framework is not the product
| Mechanism | Used for | Illustrative paths at a public service counter | Paths in this workflow |
|---|---|---|---|
| Chain | Predictable interpretation | Detect language and intent, normalise, retrieve approved information, produce a structured answer with sources, ask the person to confirm. | |
| Graph | Controlled decisions | Multiple documents, missing or conflicting information, follow-up questions, human review, case handoff, retry after a service failure, a controlled external action. | |
| Human | Accountability | Decisions with consequences for a person, any approval, and every case outside confidence, identity or policy thresholds. |
1Structured outputs
Part 1: From model call to structured output
Every field that code acts on has a defined shape, a check and a route when it is wrong.
- Every model output that code acts on is bound to a schema with a version field. Evidence:
- Fields that drive routing are closed lists or checked values, never free text. Evidence:
- Validation in code checks what the schema cannot: source identifiers, ranges, supported languages. Evidence:
- Refusal, truncation and parsing failure each have an explicit branch. Evidence:
- Retries are bounded on purpose (model call retries and correction retries), and every attempt is logged. Evidence:
- Structured output has been tested on the chosen provider with tools bound. Evidence:
- Each call records raw output, parsed result, schema version, prompt version, model identifier and retries. Evidence:
- A contract card lists each field, its consumer, its check and its failure route. Evidence:
2Prompt versioning
Part 2: Prompt templates are versioned components
Prompts are released like components, and every output can be traced to the exact version that produced it.
- Every template has a version, a named owner and a home (registry or reviewed repository). Evidence:
- Code refers to a label; the trace records the exact version identifier. Evidence:
- Each version passed a fixed evaluation set, including escalation, refusal and protected-term cases. Evidence:
- Changes are classified (cosmetic, tone, behavioural, boundary, contract) before merge, with the matching approver. Evidence:
- Rollback is a label move to a version that already passed, and it has been rehearsed. Evidence:
- Shared templates list the workflows that depend on them. Evidence:
- Behaviour when the prompt store is unreachable is decided (fail closed or cached known version). Evidence:
- Rules that must always hold are enforced in code, not only stated in the prompt. Evidence:
3Retrieval evidence
Part 3: Retrieval with evidence and source boundaries
Answers come from approved sources, and the system can show which source supported which answer.
- The approved source set is listed, with an owner and a review date for each source. Evidence:
- Retrieval is restricted to the approved set for this workflow. Evidence:
- Each answer carries source identifiers that are checked against the approved set. Evidence:
- Superseded or expired sources are excluded, and the exclusion is tested. Evidence:
- When no approved source applies, the workflow says so or routes to a person, rather than answering from the model alone. Evidence:
- Retrieved text is treated as data, never as instructions. Evidence:
4State
Part 4: Stateful workflows with LangGraph
Work that spans steps, failures or people keeps its state somewhere durable and explicit.
- The workflow states which paths are a simple chain and which need a stateful graph. Evidence:
- The state object is defined: fields, owner, retention and what must never be stored in it. Evidence:
- State is persisted to a durable store, not held only in memory. Evidence:
- Maximum steps, timeouts and explicit termination conditions exist for every loop. Evidence:
- Each transition between steps is explicit and testable. Evidence:
- Conversation memory and process state are kept separate. Evidence:
5Tool boundaries
Part 5: Tools and MCP connections need boundaries
Each tool is allowlisted, typed and limited, and the first version is read-only.
- Tools are allowlisted per workflow; discovering a new tool does not add it to the workflow. Evidence:
- Every tool input and output has a schema, and arguments are validated before the call. Evidence:
- The first version uses read-only tools only. Evidence:
- Each tool has an identity, least-privilege permissions, a timeout and a rate limit. Evidence:
- Tool failure and timeout paths are tested and do not produce uncontrolled loops. Evidence:
- Every side effect is idempotent before any write tool is enabled. Evidence:
- Each MCP server has a named owner and has passed a security review. Evidence:
6Approval and resume
Part 6: Human approval and durable checkpoints
Side-effecting actions pause for an accountable person and resume safely.
- The exact tool calls that need review are listed. Evidence:
- The reviewer sees the proposed arguments and the evidence behind them. Evidence:
- The workflow pauses at a durable checkpoint, not in memory. Evidence:
- The reviewer, decision, time and reason are recorded. Evidence:
- Resume continues from the same state without running the side effect twice. Evidence:
- Code that runs before the pause is safe to run again on resume. Evidence:
- Rejection and safe recovery are supported and tested. Evidence:
- Reviewers have the authority for the decisions they approve. Evidence:
7Tracing and evaluations
Part 7: Tracing, evaluations and failure reconstruction
The team can reconstruct any run and knows whether a change made the service better or worse.
- Every run has a correlation identifier that joins model, retrieval, tool and approval events. Evidence:
- Traces record model version, prompt version, tool name, latency, token counts and outcome. Evidence:
- Personal information in traces is minimised, and trace retention and access are decided. Evidence:
- An evaluation set with expected outcomes runs before every model, prompt, tool or dependency change. Evidence:
- Evaluation reports give a pass or fail reason per case. Evidence:
- A past failure can be reconstructed from the trace alone. Evidence:
- Cost and outcome are reported together, per accepted result. Evidence:
8Pinning and rollback
Part 8: Production packaging, version pinning and rollback
The workflow can be installed elsewhere, upgraded deliberately and rolled back.
- Direct dependencies are pinned to exact versions, naming each package. Evidence:
- The runtime (for example the Python version) is recorded. Evidence:
- A lockfile is committed and used for every installation. Evidence:
- Model, prompt, tool and agent versions are recorded with each release. Evidence:
- Regression evaluations run before any upgrade. Evidence:
- A rollback path exists and has been rehearsed. Evidence:
- Every framework change has a migration note. Evidence:
- Secrets live in environment variables or a secret manager and are never committed. Evidence:
9Acceptance tests to demonstrate
A workflow is ready for a production pilot only when the team can demonstrate each test below, live or from a recorded run, to someone who did not build it. Use synthetic or public data.
| # | Test | What must be shown | Date shown | Evidence location | Witness |
|---|---|---|---|---|---|
| 1 | Same task, two runtimes | The same task runs through a plain loop and a graph, with comparable results recorded on the same task suite. | |||
| 2 | Reproducible structured output | The same input produces the same validated structure, and the record shows raw output, parsed result and versions. | |||
| 3 | Paused for approval | A side-effecting tool call is paused for approval, with its arguments and evidence shown to the reviewer. | |||
| 4 | Safe resume after restart | After a process restart, the workflow resumes from its checkpoint without repeating the side effect. | |||
| 5 | Bounded retry | A failed tool is retried within set limits, then stops or escalates, with no uncontrolled loop. | |||
| 6 | Readable trace | A trace shows the sequence of model, retrieval and tool events for one request, joined by a correlation identifier. | |||
| 7 | Evaluation report | An evaluation report gives pass or fail, with a reason, for every case. | |||
| 8 | Installable elsewhere | The locked dependency set installs on another machine and the regression suite passes there. |