Building on conditional branching, this example adds validation with retry logic—allowing users to correct mistakes before reaching the maximum attempt limit.Documentation Index
Fetch the complete documentation index at: https://docs.syllable.ai/llms.txt
Use this file to discover all available pages before exploring further.
Objective
In this example, you’ll learn:- How to validate input format using conditions
- How to implement retry loops with loop-back transitions
- How to track attempt counts with the
incaction - How to exit gracefully after too many failures
- How to provide helpful error feedback with conditional
sayactions
The Scenario
Your contact form collects email addresses, but users sometimes enter invalid formats. You want to:- Check if the email contains ”@” and ”.”
- Allow up to 3 retry attempts if invalid
- Show helpful error messages on each retry
- Exit gracefully if the user can’t provide a valid email
Implementation
Here’s the complete tool definition:Key Concepts
Validation with CEL Expressions
Theon.presubmit hook runs before validation, allowing you to check custom conditions:
- CEL supports string methods like
contains() - JMESPath doesn’t have built-in string manipulation
local.email_is_valid for use in conditions.
Retry Counter Pattern
Track attempts by incrementing a counter when validation fails:on.enter (not on.submit) so it starts at 0 when first entering the step.
Loop-Back Transitions
A step can transition to itself, creating a retry loop:- If valid → proceed to COLLECT_TIME
- If 3+ failed attempts → go to error step
- Otherwise → retry COLLECT_EMAIL
Conditional Error Messages
Use conditionalsay actions to provide contextual feedback:
- The email is invalid, AND
- We haven’t hit the max attempts yet
Graceful Error Handling
TheERROR_TOO_MANY_ATTEMPTS step provides a clean exit:
How It Works
Successful Validation (First Try)
Validation Failure with Retry
Maximum Attempts Exceeded
Try It
To test this workflow in the Syllable Console:- Create a new tool with the JSON above
- Assign it to an agent
- Test various scenarios:
- Valid email on first try (
test@example.com) - Invalid email then valid (
test→test@example.com) - Three invalid emails to trigger error step
- Valid email on first try (
What’s Next
This example handles validation within the workflow. In Example 7: Tool Integration, you’ll learn how to:- Call external tools during workflow execution
- Control which tools are available per step
- Implement progressive tool disclosure for security

