Learning resourcesReviewed · Pydantic

Pydantic Graph: Joins and Reducers

Joins and Reducers is a guide for Python developers combining parallel work in Pydantic Graph, but it assumes asynchronous Python knowledge and leaves version compatibility unspecified. It explains collecting results, merging dictionaries, computing totals, writing custom reducers and canceling remaining tasks when a result is found.

Researched 24 Nov 2026

In short.

Joins and Reducers is a Pydantic Graph guide for Python developers collecting parallel task results, but it leaves ordering guarantees, failure handling and compatible package versions unspecified. Its examples progress from list collection and numeric sums to stateful aggregation and early cancellation. The documented behavior is useful for designing graph workflows; the examples were not executed, and performance and operational reliability remain unassessed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete selected page at [https://pydantic.dev/docs/ai/graph/builder/joins/index.md]: introductory documentation notices, every reducer example, state access, sibling cancellation, multiple joins, custom node IDs and the fork/reduce/finalize explanation. The documentation-index and query-parameter notices are page content, not software installation requirements. Linked index, API, parallel-execution and conditional-branching pages are excluded. No examples were executed; compatibility, edge cases, cancellation cleanup and real-world performance remain unassessed.

The overview

identity

This is the Joins and Reducers documentation page for Pydantic Graph's GraphBuilder API, published at [https://pydantic.dev/docs/ai/graph/builder/joins/index.md]. It teaches synchronization and aggregation of parallel execution paths.

The resource is a feature guide with Python examples. Its examples cover general software workflows and do not invoke a language model.

assessment

The page provides a useful progression from collecting mapped results to custom aggregation and stopping unnecessary sibling tasks. Each major reducer has an example showing graph construction and an illustrative output.

It is most useful when the reader already understands graph steps and asynchronous Python. It does not establish installation compatibility, failure recovery or production performance.

users

Python developers can use this guide when several tasks must feed one downstream result, such as collecting processed items, merging per-item dictionaries or calculating a total.

Beginners need familiarity with async functions, type annotations and basic graph construction. Experienced developers get examples of reducer context, state mutation, conditional routing, multiple joins and cancellation within a fork.

capabilities

The documented built-ins collect individual values with reduce_list_append, flatten incoming iterables with reduce_list_extend, merge dictionaries with reduce_dict_update, discard values with reduce_null and add numeric inputs with reduce_sum.

ReduceFirstValue accepts the first received value and cancels other parallel tasks. Custom reducers can combine an accumulator with each input, access graph state through ReducerContext and call cancel_sibling_tasks(). The page also demonstrates independent joins and custom node IDs.

Using it

requirements

The examples require Python, the pydantic_graph package and asynchronous execution. They use GraphBuilder, decorated step functions, typed StepContext inputs and, in several examples, dataclasses for state.

Supported Python versions, package versions, installation extras, operating systems and hardware requirements are not stated. No model-service credentials appear in the examples.

mechanism

A join brings parallel paths back together and reduces their outputs into an aggregate. GraphBuilder.join receives a reducer plus an initial value or an initial-value factory.

The page describes internal tracking of the fork that created the parallel paths. A join associates results with that fork, calls reduce() for incoming values, then calls finalize() before forwarding the result. This tracking is described as supporting nested parallel operations. Early-cancellation reducers provide an exception to waiting for every sibling task to finish normally.

setup

The examples construct a GraphBuilder, define async steps with g.step, create a join and connect the graph with g.add. A typical path runs from the start node to a list-producing step, maps its items into parallel processing steps, sends their outputs to the join and connects the join to the end node.

After g.build(), the examples await graph.run(), supplying state where required. Many snippets define main() without invoking it; the page instructs readers to import asyncio and add asyncio.run(main()). Package installation and version-pinning instructions are absent.

example

The introductory example generates integers 1 through 5, maps them to a square step and collects the results with reduce_list_append and initial_factory=list[int]. The page shows the sorted result as [1, 4, 9, 16, 25]. Sorting makes the displayed result deterministic; it does not establish collection order.

A custom search reducer accepts the first input containing 'target' and cancels its siblings. Two searches deliberately wait indefinitely, and the documented output reports target_item with three searches completed. These are source-provided illustrations, not independently executed results.

Assessment & evidence

limitations

The page does not specify input-order preservation, duplicate-key precedence during dictionary merging, empty-fork behavior, exception propagation, retries or timeouts. Several examples sort their outputs, so their displayed ordering should not be treated as a join guarantee.

Cancellation cleanup, rollback of completed side effects and shared-state concurrency guarantees are not explained. ReduceFirstValue selects the first arriving value; handling a task failure before any value arrives is unspecified. Nothing was executed, so compatibility and runtime behavior remain unassessed.

reasoning

The examples suggest choosing a reducer according to the downstream result: append for individual outputs, extend for batches, sum for totals and null when only completion and side effects matter.

For a search that needs an acceptable match, the custom target-matching reducer is the closer template than ReduceFirstValue. The former examines content before canceling; the latter accepts the first received value. This distinction matters when the fastest response may not satisfy the application.

alternatives

Within this API, built-in reducers offer ready-made aggregation choices, while a custom reducer supports application-specific acceptance rules or accumulator types. The stateful example demonstrates separate joins for even and odd inputs, followed by another reduction over their aggregate metrics.

The page does not compare competing graph libraries or other Python concurrency approaches. Relative performance, complexity and migration effort are unknown.

evidence

The evidence consists of the complete selected documentation page, including explanations, code examples and expected-output comments.

The examples support descriptions of the documented API and intended behavior. They do not provide independent execution evidence, benchmarks or production reliability measurements. Linked documentation was not assessed.

Access & freshness

costs

The page gives no prices, subscription requirements or usage charges. Library-related charges and deployment costs are unknown from this evidence.

No execution-time, memory-use or cost measurements are provided. Cancellation stops remaining sibling work as documented, but the page does not quantify resulting savings.

rights

The supplied page contains no license statement or explicit permissions governing reuse of its prose, example code or library. Those rights cannot be established from this page alone.

freshness

The supplied page was captured on 24 November 2026 at 02:48:32 UTC. This is a capture time, not a publication or software-release date.

The page states no update date, package release number or supported-version range. Compatibility with a particular installed release and any subsequent documentation changes are unknown.

actions

Start with the square-and-collect example to understand mapping into a join, then choose the reducer that matches the required output. Establish a compatible pydantic_graph version before adapting the examples.

Before adopting a workflow, assess ordering, empty inputs, task failures and shared-state behavior in the intended environment. For early cancellation, define what counts as an acceptable result and assess cleanup of interrupted work. The page links to a fuller reducer reference at [https://pydantic.dev/docs/ai/api/pydantic_graph/join/#pydantic_graph.join], whose contents were not assessed here.

Evidence for this report

selected-page.txtselected · checked 2026-11-24