You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
fromhaystackimportDocumentfromhaystack.components.routers.conditional_routerimportConditionalRouterDOC_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.
The text was updated successfully, but these errors were encountered:
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 setunsafe=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 therun
methodAlternative
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.
The text was updated successfully, but these errors were encountered: