Generate User Profiles
Use ControlFlow to generate test data based on a template.
This example demonstrates how to use ControlFlow to create a task that generates test data based on a given template. It showcases the use of custom types and efficient batch processing.
Code
The following code creates a function that takes a count then returns a list of generated user profiles that match a provide result_type
template:
Now we can generate some test data:
Key concepts
This implementation showcases several important ControlFlow features:
-
Pydantic models: We use a Pydantic model (
UserProfile
) to define the structure of our generated data. This ensures that the generation task returns well-structured, consistent results. -
Batch processing: We generate multiple user profiles in a single task, which is more efficient than generating them individually. This is achieved by specifying
List[UserProfile]
as theresult_type
. -
Context passing: We pass the desired count as context to the task, allowing the LLM to generate multiple data points based on the given parameters.
By leveraging these ControlFlow features, we create an efficient and flexible test data generation tool. This example demonstrates how ControlFlow can be used to build AI-powered data generation workflows that can produce multiple data points in a single operation, based on customizable templates. This approach is particularly useful for creating diverse and realistic test datasets for various applications.