{"record":{"id":"d40bf4ae480cbdc3","repo":"deepset-ai/haystack","slug":"error-evaluating-condition-for-route-route-e","errorCode":null,"errorMessage":"Error evaluating condition for route '{route}': {e}","messagePattern":"Error evaluating condition for route '(.+?)': (.+?)","errorType":"exception","errorClass":"RouteConditionException","httpStatus":null,"severity":"error","filePath":"haystack/components/routers/conditional_router.py","lineNumber":478,"sourceCode":"                        # This doesn't support any user types.\n                        with contextlib.suppress(Exception):\n                            if not self._unsafe:\n                                output_value = ast.literal_eval(output_value)\n\n                    # Validate output type if needed\n                    if self._validate_output_type and not self._output_matches_type(output_value, output_type):\n                        raise ValueError(f\"Route '{output_name}' type doesn't match expected type\")  # noqa: TRY301\n\n                    result[output_name] = output_value\n\n                return result\n\n            except Exception as e:\n                # If this was a type-validation failure or missing passthrough variable, let it propagate\n                if isinstance(e, ValueError):\n                    raise\n                msg = f\"Error evaluating condition for route '{route}': {e}\"\n                raise RouteConditionException(msg) from e\n\n        raise NoRouteSelectedException(f\"No route fired. Routes: {self.routes}\")\n\n    def _validate_routes(self, routes: list[Route]) -> None:\n        \"\"\"\n        Validates a list of routes.\n\n        :param routes: A list of routes.\n        \"\"\"\n        for route in routes:\n            try:\n                keys = set(route.keys())\n            except AttributeError as e:\n                raise ValueError(f\"Route must be a dictionary, got: {route}\") from e\n\n            mandatory_fields = {\"condition\", \"output\", \"output_type\", \"output_name\"}\n            has_all_mandatory_fields = mandatory_fields.issubset(keys)\n            if not has_all_mandatory_fields:","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/routers/conditional_router.py#L460-L496","documentation":"While evaluating a route's Jinja condition in run(), an unexpected exception occurred (anything other than a ValueError, which propagates unchanged). Haystack wraps it in RouteConditionException with the route and original error in the message, chained as __cause__.","triggerScenarios":"Condition template references a variable not passed to run() (Jinja undefined renders, then literal_eval or comparison fails); template syntax or runtime errors; in unsafe mode, NativeEnvironment code raising inside the condition.","commonSituations":"Forgetting to pass all condition variables to run(); typos in variable names inside condition templates; non-boolean-rendering conditions that break ast.literal_eval in safe mode.","solutions":["Read the chained __cause__ to see the underlying Jinja error.","Ensure every variable used in the condition is passed to run() and to the router's inputs in the pipeline.","Fix template syntax/typos in the route's condition.","Catch RouteConditionException (and optionally NoRouteSelectedException) around pipeline.run()/router.run() to handle routing failures."],"exampleFix":"// before\nrouter.run()  # condition uses 'query'\n// after\nrouter.run(query=\"hello\")","handlingStrategy":"try-catch","validationCode":"for r in router.routes:\n    for var in re.findall(r\"\\w+\", r[\"condition\"]):\n        if var not in RESERVED and var not in kwargs:\n            raise KeyError(f\"condition variable '{var}' not in inputs\")","typeGuard":"def condition_vars_supplied(router, kwargs: dict) -> bool:\n    import re, jinja2\n    env = jinja2.Environment()\n    for r in router.routes:\n        names = jinja2.meta.find_undeclared_variables(env.parse(r[\"condition\"]))\n        if not names.issubset(kwargs.keys()):\n            return False\n    return True","tryCatchPattern":"try:\n    result = router.run(**kwargs)\nexcept RouteConditionException as e:\n    logger.warning(\"route condition failed: %s\", e.__cause__)\n    result = default_route_result","preventionTips":["Pass all condition variables to run(); keep router input names identical to template variable names.","Use jinja2.meta.find_undeclared_variables to check template variables against expected inputs.","Inspect __cause__ of RouteConditionException for the real Jinja error."],"tags":["router","jinja","condition-evaluation"],"backgroundTag":"route-condition-evaluation-failed","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}