Feature Request: Adding If-Else Conditional Logic to ChainForge
Feature Request: Conditional Logic Support
I'd like to request a critical workflow enhancement for ChainForge: the addition of conditional logic, specifically if-else functionality. After thoroughly reviewing your documentation, I haven't found a way to implement conditional branching in workflows, which significantly limits the creation of more sophisticated prompt engineering pipelines.
Use Case Example
To illustrate why this feature is essential, let me describe a specific text expansion workflow I'm trying to implement:
- Step 1: A user provides a topic (e.g., "What is the future of AI?")
- Step 2: An AI analyzes the topic to determine what text structure would be most appropriate (poetry, news article, research report, or academic paper)
- Step 3: Based on the structure determined in Step 2, the workflow should automatically select and execute the appropriate specialized prompt for that specific text format
With the current version of ChainForge, I can create different prompts for each potential text structure, but I have no way to dynamically route the workflow based on the AI's determination in Step 2. This forces me to either:
- Run all possible prompts regardless of relevance
- Manually intervene in the workflow, breaking automation
Proposed Solution
I would greatly appreciate if you could consider implementing conditional logic nodes that would allow:
IF (output from previous node contains/matches X)
THEN (route to node A)
ELSE (route to node B)
Or perhaps a more sophisticated switch-case structure:
SWITCH (output from previous node)
CASE "poetry": (route to poetry prompt)
CASE "news": (route to news prompt)
CASE "research": (route to research prompt)
CASE "academic": (route to academic prompt)
DEFAULT: (route to general prompt)
Benefits
Adding conditional logic would:
- Enable truly dynamic, responsive workflows
- Allow for more sophisticated prompt engineering patterns
- Reduce manual intervention in complex workflows
- Make the tool more competitive with other workflow automation tools
- Open up entirely new use cases for ChainForge
Conclusion
This feature would be transformative for implementing complex, multi-stage prompt engineering workflows. Conditional logic is a standard feature in most workflow tools, and adding it to ChainForge would significantly enhance its capabilities for users working on sophisticated prompt chains.
Thank you for considering this request, and for all your excellent work on ChainForge so far. I look forward to seeing how the tool continues to evolve.
Hi, @Sander-Chen. This is an interesting feature request. If it aligns with the overall vision, I’d be happy to contribute to its implementation.
Dr. @ianarawjo, I’d appreciate your thoughts on this approach before I proceed:
-
Instead of adding separate if-else logic, we could extend Prompt Evaluators to process Tabular Data nodes as key-value dictionaries.
-
This would allow evaluators to dynamically analyze outputs and return results that Prompt nodes can directly use. However, we would need to modify Prompt nodes to accept data from Prompt Evaluators.
I would love to hear your feedback—does this direction make sense to you?
That is not a bad idea to use the existing evaluator functionality. You would not amend the prompt node however. You would instead add a small node, the “SwitcherNode” or “RouterNode”, that takes scored LLM responses as input and is able to group them into different output handles.
An alternative is just to extend the existing JoinNode to be able to group by eval scores… this might be conceptually a little confusing to people though.
Note that I haven’t added a Switcher because ChainForge is not really for making applications, and conditional logic like this is deterministic, and dependent on the specific (random) outputs you get from the LLM.
I understand that ChainForge isn't primarily designed for creating end-user applications. However, with the rapid advancement of large language models, complex agent workflows like the scenario I described earlier are becoming increasingly common in the development process.
My request for conditional logic functionality is specifically aimed at enhancing ChainForge's core value proposition: enabling better assessment and testing across a wider range of LLM scenarios. This would allow prompt engineers and LLM application developers to more effectively debug and refine their prompts within these multi-stage workflows.
The ability to test how different prompt paths perform based on initial LLM classifications or analyses would be incredibly valuable for understanding prompt effectiveness in complex systems, even if the final implementation happens elsewhere.
Thank you for considering this perspective and for your continued work on this excellent tool!
Thank you for the clarification, Dr. Arawjo.
I see your point about ChainForge not being intended to build full applications. That makes sense. I also find the idea of a small RouterNode appealing—it seems like a clean way to introduce basic conditional behavior without changing the core philosophy of the tool.
@Sander-Chen, I agree that having some ability to route based on evaluator output could still be helpful in the context of testing or comparing prompts. Especially for debugging multi-stage prompt chains, this might help isolate what types of outputs trigger which paths.
Dr. Arawjo, would you be open to me exploring a simple version of this RouterNode? I’d definitely appreciate your feedback before moving forward—I want to make sure it fits ChainForge’s vision.
Thanks again for your guidance!