Every week someone used to turn a pile of commits into release notes. Most of the commits don't matter to users: CI tweaks, test fixes, contributor docs. Some weeks none of them do.

So we split the job into a chain. A small model sorts the commits and keeps only the changes a user would notice. Then a plain Python if checks the result. If anything is left, a stronger model writes the notes. If nothing is left, the chain stops and the stronger model never runs.

This is prompt chaining, and it's the last of the five workflow patterns in lecture 6 of Stanford's CS329Z. Below is the example we built with Railtracks, with the real numbers from the run.

What is prompt chaining?

You break a task into steps that run in order. Each step's output is the next step's input. Between steps you can add a gate: ordinary code that checks the output and decides whether to keep going.

Why not just send one big prompt? Because each step gets a small job you can check:

  • Each step can use a different model. Sorting commits is easy, so a small cheap model does it. Writing is the hard part, so it goes to a stronger model.
  • You can check what's between the steps. The sorter returns a list, not prose, so the gate is one line of Python.
  • The later steps only see what they need. The writer gets the sorted list, not the raw commit messages. This can also be used as an extra layer of security in different applications.

The input

Two real lists of commit subjects from the Railtracks open-source repo:

  • last_week.txt: all 15 commits merged to main in the week of November 23. It's a mix of features, fixes, refactors, one docs commit and one test commit.
  • internal_only.txt: 5 commits that only touch CI, tests and contributor docs. There wasn't a real week with only internal commits, so we picked these five from the last few months. Two of them are also in last week's list.
ci: add stale PR triage workflow (#1832) docs: add issue claiming policy to CONTRIBUTING.md (#1829) test: isolate UNC attachment paths from network access (#1821) test(mcp): bound mcp below 2 in the MCP test fixture (#1724) chore(e2e): get the E2E live-test workflow running again (#1696) 

The code

from pathlib import Path import railtracks as rt from pydantic import BaseModel class Changes(BaseModel): user_facing: list[str] Sorter = rt.agent_node( "Sorter", llm=rt.llm.OpenAILLM("gpt-6-luna"), system_message=( "From these commits, keep only the changes a user of the library would notice. " "Skip CI, tests, contributor docs and internal refactors. " "Rewrite each one in plain words and keep its PR number." ), output_schema=Changes, ) Writer = rt.agent_node( "Writer", llm=rt.llm.AnthropicLLM("claude-sonnet-5-5"), system_message="Write short release notes from these changes. Most useful first. At most 5 bullets.", ) @rt.function_node async def release_notes(commits: str) -> str: # Step 1: a small model sorts the commits. response = await rt.call(Sorter, commits) changes = response.structured.user_facing # Gate: plain Python decides whether step 2 runs at all. if not changes: return "Nothing to announce." # Step 2: a stronger model writes, and only sees the sorted list. response = await rt.call(Writer, "\n".join(changes)) return response.text flow = rt.Flow(name="Release Notes", entry_point=release_notes) for file in ["last_week.txt", "internal_only.txt"]: commits = Path(file).read_text() notes = flow.invoke(commits) print(f"--- {file}\n{notes}\n") 

Here's what each part does:

  • Sorter is an agent_node with output_schema=Changes, so it returns a Changes object instead of text. response.structured.user_facing is a real Python list.
  • The gate is if not changes. It's ordinary code, so it costs nothing and always behaves the same way.
  • Writer is a normal text agent. It only gets the sorted list, joined into lines.
  • release_notes is a function_node that runs the steps in order. Wrapping it in a Flow puts every step in the same trace.

What happened

Last week's 15 commits. The sorter kept 12. It dropped the docs commit, the test commit, and one internal move of a metrics class. It kept the breaking refactor that removed the old human-in-the-loop package, which is right: users will notice that one. Here's the start of what the writer made from the list:

## Release notes - **Removed:** The legacy human-in-the-loop package and local chat UI are gone. (#1833) - **Upgrade notes:** - `.content` will become a list of parts in 1.9.0, and a warning now flags this. (#1834) - Loader argument names are standardized, with deprecation shims for the old names. (#1807) - The Store protocol's public interface has been updated. (#1808) - **New:** - An XAI provider for Grok models. (#1817) - The Turbovec vector backend. (#1729) - Middleware that summarizes tool output. (#1739) ... 

The full notes have 5 headings and 12 items under them.

The 5 internal-only commits. The sorter returned {"user_facing": []}. The gate returned "Nothing to announce.", and the writer never ran. In the visualizer, that run's tree has a Sorter node and nothing after it.

The numbers

These come from the run's trace in the Railtracks visualizer (railtracks viz --beta):

Input Sorter (gpt-6-luna) Writer (claude-sonnet-5-5) Whole chain
last_week.txt, 15 commits 8.2s · $0.0005 5.5s · $0.0086 13.7s · $0.0091
internal_only.txt, 5 commits 1.8s · $0.00004 didn't run 1.8s · $0.00004
  • The gate made the quiet run over 200 times cheaper. Almost all of the full chain's cost was the writer, and the gate skipped it.
  • It was also 1.8s instead of 13.7s, for the same reason.
  • The sorter is cheap but wasn't fast. On the 15 commits it took 8.2s and wrote 925 output tokens for a list of 12 short lines. That's most likely hidden reasoning tokens. If you use a small reasoning model for the first step, check its output token count.

Things to watch

  • The writer bent the rule. We asked for "at most 5 bullets." It wrote 5 bold headings with 12 sub-bullets under them. That fits the letter of the rule but not what was meant. If a rule matters, check it in code, the same way the gate does.
  • A gate only checks what you can check in code. An empty list is easy to test. "Is this list right?" isn't. The sorter decides what users would notice, and nothing here double-checks it.
  • Chains add up. Each step waits for the one before it, so the total time is the sum of the steps. If two steps don't depend on each other, run them at the same time instead (that's sectioning, part 5).
  • We didn't compare against one prompt doing everything. One strong model could probably sort and write in one call. The point of the chain is that the cheap step runs first, and you only pay for the expensive one when there's something to write.

When to use it

Prompt chaining fits when a task splits into steps that each depend on the one before, and you can check the output between them. Extract, then write. Outline, check the outline, then draft. Translate, then check the terms you care about. It works best when an early step can be done by a smaller model, and when its output tells you whether the later steps are worth running.

That's the series

This was the last part of our series on the CS329Z workflow patterns. All five are now runnable Railtracks examples:

  1. Orchestrator-workers
  2. Evaluator-optimizer
  3. Parallelization: voting
  4. Routing
  5. Parallelization: sectioning
  6. Prompt chaining

We may cover concepts from other areas of agent design next.

Railtracks is open source: github.com/RailtownAI/railtracks.
Stanford Lecture Slides are worth reading.

Questions, or a topic you'd like us to cover next? Come hang out in our Discord: https://discord.gg/2JUb2TxjJv