Skill · pattern · prompt-chaining
Prompt chain
Implement a prompt chain: named stages in series with code gates between LLM hops. Use when the path is known (extract → transform → write), invoice/document pipelines, or someone is about to turn a five-step process into a free-running ReAct loop.
GET /api/canon/skills/prompt-chaining?format=md
The cheapest workflow that earns extra hops. Each gate is a schema or a predicate. Fail closed. n8n, Dify, and LangGraph all industrialize this.
When
You can name the stages and check the intermediates.
Do
- 01
Name stages
Each hop has a typed input and output. Code validates before the next LLM call.
- 02
Gate between hops
If the extract is invalid, do not draft. Repair or ask_human — do not hope.
- 03
Add a loop only where evals fail without one
An agent island at the ambiguous stage, not around the whole pipeline.
Don't
- Wrap the chain in an unbounded agent 'in case it needs to think'.
- Skip the gate because the model 'usually gets it'.
Hard rules
- Known path → chain. Unknown path → agent.
- Gates are code. The model does not grade its own passport.
Refuse
- Unbounded loop — No max-turns, token, wall-clock, or money budget. The agent rambles until the bill or the context dies.
- Eval by demo — Architecture first, golden set never. Success is a recorded GIF.
Load with this
Load next
- Workflows versus agentsYou are about to pick a topology. Most production systems that work are workflows with a small agentic island.
- Router / handoffStable categories and a cheap, accurate classifier.
- Evaluator–optimizerClear scoring criteria and iterative gains. If you cannot write the rubric, you cannot loop it.
Trigger tests
Should fire
- “Chain extract then draft then send”
- “This is a five-step invoice pipeline”
Should not
- “The agent has to explore an unknown repo”