Subgraphs
Subgraphs let one graph call another graph in the same project. They are the main way to turn a busy canvas into smaller reusable pieces.
In this tutorial, you will make a helper graph with explicit inputs and outputs, then call it from another graph with a Subgraph Node.
What a Subgraph Is
A Rivet project can contain many graphs. Any graph can be used as a subgraph by another graph.
The callable interface of a graph is defined by:
- Graph Input Nodes, which become input ports on the Subgraph node.
- Graph Output Nodes, which become output ports on the Subgraph node.
If you change the inputs or outputs inside the called graph, the Subgraph node updates to match.
Create a Helper Graph
- Create a new graph in the current project.
- Name it
Format Greeting. - Add a Graph Input node.
- Set the Graph Input ID to
name. - Set its data type to
String. - Add a Text node.
- Set the Text node template to:
Hello, {{name}}.
- Connect the Graph Input output to the Text node
nameinput. - Add a Graph Output node.
- Set the Graph Output ID to
greeting. - Connect the Text node output to the Graph Output node.
You now have a graph that accepts name and returns greeting.
Call the Helper Graph
- Open your main graph.
- Add a Text node with the value:
Rivet
- Add a Subgraph node.
- In the Subgraph node settings, choose
Format Greeting. - Connect the Text node output to the Subgraph node
nameinput. - Run the graph.
The Subgraph node output greeting should contain:
Hello, Rivet.
The important part is that the Subgraph node did not need custom code. Its ports came from the Graph Input and Graph Output nodes in the called graph.
Reuse the Same Graph
You can add another Subgraph node and point it to Format Greeting again. Each Subgraph node can receive different inputs, but both use the same graph definition.
This is useful for:
- formatting repeated prompt sections
- normalizing API responses
- wrapping a group of nodes that you use in several places
- keeping large workflows readable
Error Handling
The Subgraph node has a Use Error Output setting.
When it is off, an error inside the called graph fails the Subgraph node. When it is on, the Subgraph node produces the error text on its Error output instead.
Use the error output when a subgraph call is optional or when you want the parent graph to decide how to recover.
Notes
- A Subgraph node calls a graph from the same project.
- A graph can call another subgraph, so you can build layers of reusable workflow pieces.
- Avoid accidental recursion unless you intentionally combine subgraphs with loop control.
- Keep Graph Input and Graph Output IDs stable once other graphs depend on them.