chainfactory-py · python library

ChainFactory

an assembly line for inference

Declarative multi-step LLM workflows in a YAML-like syntax. Connect prompts into chains — the output of one link feeds the input of the next, with smart mapping in between.

fig. 01 — the line

The Blueprint

split — map — reduce, declared in three lines

pipeline.fctrchainfactory
@chainlink generator --     # runs once
@chainlink reviewer ||      # fans out in parallel over the generator's list
@chainlink summarizer --    # reduces the parallel outputs

Every @chainlink is one stop on the line. The -- marker means sequential: the link runs once and passes its output downstream. The || marker means parallel: when the previous link emits an iterable, the link fans out automatically — one worker per item.

Here the generator produces a list, reviewer runs over every element concurrently, and summarizer collects the whole batch back into a single result. Split-map-reduce for LLM calls, with zero orchestration code.

no glue code required

Standard Equipment

everything on the factory floor

01

Purpose-Driven Prompts

Write purpose: generate creative haiku topics and the system generates the optimal prompt for you. Less reliance on exact prompt wording, more on intent.

02

Pydantic-Typed Outputs

Every link's output is validated against a Pydantic model. Type-safe structures move between stations — malformed parts never leave the machine.

03

Parallel Over Iterables

Mark a link || and it fans out over any iterable from the previous link. Built for split-map-reduce workflows without manual batching.

04

Hash-Based Caching

Intermediate generated prompts are cached by content hash. Re-running a chain reuses identical work instead of paying for it twice.

05

Chain Inheritance

Chains extend other chains. Define a base pipeline once, then specialize it — reusability for workflows, not just functions.

06

Tool Calling

Links can invoke tools mid-chain, so the assembly line reaches outside the model when the job needs real machinery.

pip install chainfactory-py read the docs ↗