By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Pricing is no longer a function in the support repository. Another team owns it, ships it weekly, and runs it for support and checkout alike. The support graph needs one answer — the discounted total for an order — so it composes the pricing graph as a subgraph. The parent state dictionary and the child state dictionary are different schemas, owned by different teams, and the moment they are wired together that difference becomes a contract with a version number and a test.
A subgraph boundary is not free composition. It is an interface: parent channels are mapped to child inputs, the child runs with its own state and possibly its own checkpointer, and a declared subset of its results is mapped back. Everything that crosses is now shared ownership; everything that does not cross is the child's private business. The applied skill is drawing that line deliberately and testing it like an API.
In LangGraph the boundary is usually a parent node that invokes a compiled child graph. Keep the translation in two pure functions: one builds the child's input from the parent state, and one builds the parent's update from the child's result. The functions are where the contract lives — a single place to read, test and version. If the child starts returning a new key, only to_parent needs to change, and a test fails until it does.
from typing import Any
# A support graph calls a pricing subgraph. Only these two adapters move data
# across the boundary; the child's scratch keys never reach the parent state.
def to_child(parent: dict[str, Any]) -> dict[str, Any]:
"""Parent support state -> child pricing state (declared inputs only)."""
return {
"order_id": parent["order_id"],
"amount_cents": parent["amount_cents"],
"membership": parent["customer_tier"] == "gold",
}
def to_parent(child: dict[str, Any]) -> dict[str, Any]:
"""Child result -> parent update (declared outputs only)."""
return {
"amount_cents": child["discounted_cents"],
"discount_cents": child["discount_cents"],
}
parent = {"order_id": "A17", "customer_tier": "gold", "amount_cents": 8400}
child = to_child(parent)
child["discount_cents"] = 500
child["discounted_cents"] = child["amount_cents"] - child["discount_cents"]
child["scratch_debug"] = "internal only"
update = to_parent(child)
print("child keys:", sorted(child))
print("parent update:", update)
print("scratch leaked:", "scratch_debug" in update)The child ended with six keys and the parent accepted two. That ratio is not a bug: most of the child's state is its own working memory. The adapter is also where type and unit conversions belong — cents versus dollars, tier string versus membership boolean — because a unit mismatch discovered at the fan-in is a pricing incident, while one discovered in an adapter test is a failing assertion before lunch. Note what the boundary does not do: it does not hand the child the parent's whole dictionary and trust both teams to ignore the extra keys.
A well-drawn boundary limits what a failure can reach. The child should return a typed failure value rather than raising through the parent: the parent node decides whether a failed pricing call falls back to list price, retries once or escalates. The child gets a deadline and its own call budget from the parent, because the parent owns the customer's patience. And the child must never write a parent-owned channel — a subgraph that mutates the conversation it was called from has no boundary at all.
PricingError result channel lets the parent choose the customer-visible behaviour; an exception just aborts a superstep the parent could have handled.Composition has a cost, and the cost is paid at every change on either side. A boundary is worth it when it buys something real: a separate deploy cadence, a genuinely reusable capability, or an ownership line that keeps two teams out of each other's diffs. It is not worth it just because a graph has grown large — a second schema and two adapters are a poor substitute for renaming a node.
| Reason to split | What the boundary costs | Prefer |
|---|---|---|
| Another team owns and deploys the capability | Two schemas, adapters, version skew | A real subgraph with a versioned contract |
| Isolate a fragile vendor call | An extra hop and more failure modes | A node-level timeout and fallback |
| Reuse one capability from several parents | Contract maintenance and two test suites | An in-process subgraph with pure adapters |
| The graph file is getting long | Indirection with no owner | Split by ownership, not by line count |
Key takeaways
A subgraph boundary is an interface: parent inputs are mapped in, a declared subset of child outputs is mapped back, and everything else stays the child's private state.
Keep the contract in two pure adapter functions so the mapping has one place to read, test and version instead of being spread across node bodies.
Return child failures as typed values and pass deadlines down as explicit inputs; the parent decides the customer-visible fallback, and the child decides effect-level retries.
Know whether a pausing child inherits the parent's checkpointer (it resumes through the parent thread) or runs its own saver (it needs its own thread id); mixing the two sends a resume to the wrong graph.
Split for ownership, deploy cadence or reuse — not for file length; the boundary adds schema, adapter and version-skew costs forever.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.