Skip to content
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

Allow for Haystack native data types as outputs to ConditionalRouter #8517

Open
sjrl opened this issue Nov 4, 2024 · 0 comments
Open

Allow for Haystack native data types as outputs to ConditionalRouter #8517

sjrl opened this issue Nov 4, 2024 · 0 comments
Assignees
Labels
P2 Medium priority, add to the next sprint if no P1 available

Comments

@sjrl
Copy link
Contributor

sjrl commented Nov 4, 2024

Related to this issue #8161

Due to very valid security reasons by default we only allow for Python Literal types as valid output types for our ConditionalRouter and OutputAdapter (e.g. basically any Jinja2 output type).

However, there are instances where it would be really nice to route things like a List of Haystack Documents or a ChatMessage and this can only be accomplished by using the unsafe=True option, which isn't ideal.

Describe the solution you'd like
It would be great if we could additionally add native Haystack data types (e.g. haystack.Document) as a valid output types for Jinja2 outputs without needing to set unsafe=True. This would be especially helpful in deepset Cloud since this design pattern comes up often. For example, routing user requests to two different branches based on a variable passed to the run method

from haystack import Document
from haystack.components.routers.conditional_router import ConditionalRouter

DOC_LIST = [
    Document(content="test when values are lists", meta={"valuelist": ["12"], "split_id": 3}),
    Document(content="test when values are lists2", meta={"valuelist": ["12"], "split_id": 4}),
    Document(content="test when values are lists3", meta={"valuelist": ["12"], "split_id": 8}),
]

routes= [
        {
            "condition": '{{path == "generative"}}',
            "output": "{{documents}}",
            "output_name": "generative",
            "output_type": "typing.List[haystack.Document]",
        },
        {
            "condition": '{{path == "doc_retrieval"}}',
            "output": "{{documents}}",
            "output_name": "doc_retrieval",
            "output_type": "typing.List[haystack.Document]",
        },
    ]

router = ConditionalRouter(routes=routes)

res = router.run(path="generative", documents=DOC_LIST)

Alternative
Perhaps an alternative (if it's possible) could be to automatically set the output_type to be the input type of the variable. That would cover the above use case, but I'm unsure if this is any easier than natively supporting Haystack data types.

@julian-risch julian-risch added the P2 Medium priority, add to the next sprint if no P1 available label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Medium priority, add to the next sprint if no P1 available
Projects
None yet
Development

No branches or pull requests

3 participants