-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConditionalRouter output type is not working anymore #8161
Comments
That's expected. Because of the changes to fix the security issue we had to make this breaking change. The I would suggest creating a custom Component to cover those cases where the Something like this should do the trick: from typing import List
from haystack import component
from haystack.dataclasses import ChatMessage
@component
class Decision:
@component.output_types(short_streams_message=ChatMessage, long_streams_message=ChatMessage)
def run(self, streams: List[str], message: ChatMessage):
if len(streams) > 2:
return {"long_streams_message": message}
return {"short_streams_message": message} |
I see. So the parameter We did not expect to see a breaking change with a patch version change. Should we worry about those updates too? |
We decided to release this security change as a patch release even if it's a breaking change as it's a pretty critical, it could lead to remote code execution. |
Perhaps we could add an option to the I also had this case, where I wanted to route a list of Documents depending on a reply generated from the LLM. I don't have to go through jinja to route these documents because I don't want to change anything about them. So something like:
This part would need to be changed to something like:
Would that solve your use case too @gustavo-has-stone ? |
In our scenario, we were routing a variable of a custom type (similar to |
Hi, I ran into this problem too when upgrading to 2.3.1. I use a custom |
@gustavo-has-stone @alexsniffin We discussed a bit internally and decided to give the possibility to enable the previous behaviour by creating I just created a PR to bring that change in and we'll release it on the upcoming |
I don't think that using an unsafe version is a good solution for us. We will try to find an alternative solution for our use case |
Hey @silvanocerza Idk if it`s a good solution because you are publishing a version that the only way to use previews behavior is forcing unsafe. It forces people to open security breaches when need a feature. An approach that could help us is using Haystack |
It's unsafe only if the Jinja templates used are users inputs too. If you know the templates it's completely safe to use.
Setting If you know what you're doing and know you're not using users inputs as Jinja template that is completely fine to use. |
Let me see if I understand. If we try to route based on some controlled condition (e.g., message length), we will be fine. However, if we try to use the content of a message for conditional routing, we could be in trouble. Is that right? |
No. You are vulnerable if you let your users write their own templates from scratch. A simple example: from typing import List
from haystack.components.routers import ConditionalRouter
user_input = input("Write a Jinja template:")
routes = [
{
"condition": user_input,
"output": "{{streams}}",
"output_name": "enough_streams",
"output_type": List[int],
},
{
"condition": "{{streams|length <= 2}}",
"output": "{{streams}}",
"output_name": "insufficient_streams",
"output_type": List[int],
},
]
router = ConditionalRouter(routes)
...
router.run(whatever_input) |
Thank you @silvanocerza . It sounds like a plan! 😄 |
Describe the bug
We tried to update the Haystack version to 2.3.1 due to the security update and our code stopped working. We identified that the
ConditionalRouter
is returning a string instead of the type assigned inoutput_type
Error message
We are getting errors related to the fact that a string is now being returned. Here is an example of the error when running the provided code:
AttributeError: 'str' object has no attribute 'content'
Expected behavior
We expected that the
output_type
provided in the route would be returnedAdditional context
The problem is related to version 2.3.1. Our provided example works on 2.3.0
To Reproduce
The following code works on haystack 2.3.0 but it does not work on haystack 2.3.1:
FAQ Check
System:
The text was updated successfully, but these errors were encountered: