Skip to content

Conversation

@vblagoje
Copy link
Member

@vblagoje vblagoje commented Dec 3, 2025

Why:

Replaces cryptic "Can't compile non template nodes" errors with actionable guidance when users provide non-string values (e.g., 2 instead of "2") as route outputs in ConditionalRouter.

What:

  • Added type checking in _validate_template() to detect non-string templates before Jinja parsing
  • Enhanced error messages in _validate_routes() to show value type and suggest fixes (e.g., "use '2' instead of 2")
  • Added test cases verifying improved error messages for single and list outputs

How can it be used:

from haystack.components.routers import ConditionalRouter

# Before: Cryptic error
routes = [{"condition": "{{ True }}", "output": 2, "output_name": "num", "output_type": int}]
# ValueError: Can't compile non template nodes

# After: Clear guidance
routes = [{"condition": "{{ True }}", "output": 2, "output_name": "num", "output_type": int}]
# ValueError: Invalid template for output: 2 (type: int). Output must be a string representing a valid Jinja2 template. For example, use '2' instead of 2.

How did you test it:

  • Added unit tests for non-string output templates (single and list cases)
  • Verified error messages contain required guidance keywords
  • Ran full ConditionalRouter test suite (28 tests passing)

Notes for the reviewer:

Error message improvements are backward compatible and only enhance user experience during initialization validation.

@vercel
Copy link

vercel bot commented Dec 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
haystack-docs Ignored Ignored Preview Dec 10, 2025 9:23am

@github-actions github-actions bot added topic:tests type:documentation Improvements on the docs labels Dec 3, 2025
@vblagoje vblagoje marked this pull request as ready for review December 3, 2025 15:31
@vblagoje vblagoje requested a review from a team as a code owner December 3, 2025 15:31
@vblagoje vblagoje requested review from mpangrazzi and removed request for a team December 3, 2025 15:31
@vblagoje
Copy link
Member Author

vblagoje commented Dec 3, 2025

@mpangrazzi nothing urgent 🙏

@coveralls
Copy link
Collaborator

coveralls commented Dec 3, 2025

Pull Request Test Coverage Report for Build 19899324781

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 14 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.003%) to 92.196%

Files with Coverage Reduction New Missed Lines %
components/routers/conditional_router.py 14 87.97%
Totals Coverage Status
Change from base Build 19898946186: -0.003%
Covered Lines: 14082
Relevant Lines: 15274

💛 - Coveralls

assert "Invalid template for output" in error_message
assert "string" in error_message
assert "Jinja2 template" in error_message
assert "2" in error_message or "2!" in error_message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused on this statement. When would 2! appear in the error message?

Copy link
Contributor

@sjrl sjrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment, otherwise looks good!

@vblagoje vblagoje merged commit 7daefb8 into main Dec 10, 2025
21 checks passed
@vblagoje vblagoje deleted the cr_invalid_template branch December 10, 2025 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error reporting for invalid / non-template jinja2 template on ConditionalRouter

4 participants