Skip to content

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

  1. 01

    Name stages

    Each hop has a typed input and output. Code validates before the next LLM call.

  2. 02

    Gate between hops

    If the extract is invalid, do not draft. Repair or ask_human — do not hope.

  3. 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 loopNo max-turns, token, wall-clock, or money budget. The agent rambles until the bill or the context dies.
  • Eval by demoArchitecture first, golden set never. Success is a recorded GIF.

Load with this

Load next

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