Private flows
Create isolated execution environments within your workflows.
Nested flows in ControlFlow allow you to create isolated threads within a larger workflow. This feature is particularly useful when you need to perform operations that shouldn’t affect or be visible to the main flow, or when you want to encapsulate a set of tasks for modularity or security reasons.
In this example, we’ll demonstrate how to use private flows to process sensitive information without exposing it to the main workflow. In a real-world version of this, you might use a locally-hosted LLM or private API for the sensitive data processing.
Code
Key points
-
Isolation: Private flows create an isolated execution environment. Tasks within a private flow cannot access or modify the context of the parent flow directly.
-
Data encapsulation: Sensitive information (
sensitive_info
) is only available within the private flow, protecting it from accidental exposure in the main workflow. -
Context control: By setting
args_as_context=False
, we can pass the sensitive information to the flow function without adding it to context automatically. -
Result passing: Results from the private flow (like
masked_info
) can be explicitly passed back to the main flow for further processing. -
Nested structure: Private flows can be nested within larger workflows, allowing for modular and secure task organization.
Further reading
- To learn more about flows in ControlFlow, see the flows documentation.
By using private flows, you can create more secure and modular workflows, especially when dealing with sensitive information or when you need to isolate certain operations from the main workflow context.