What is Declare Task Failed?
Declare Task Failed is a specialized tool that allows your agent to immediately terminate workflow execution when specific failure conditions are met. This prevents the agent from continuing to attempt a task that cannot be completed, saving time and resources.In your prompts, always refer to this tool as
declare_task_failed (lowercase, with underscores).Why This Tool Exists
Not all workflow failures are the same. Some errors are recoverable, while others indicate fundamental issues that make task completion impossible:- Authentication Failures: Locked accounts or invalid credentials
- Missing Prerequisites: Required data or systems unavailable
- Business Rule Violations: Conditions that invalidate the entire process
- Technical Limitations: System errors that cannot be resolved
- User-Defined Conditions: Specific scenarios you define as failures
declare_task_failed, the agent might spend excessive time trying to work around insurmountable obstacles.
How It Works
- The agent encounters a condition you’ve defined as a failure
- It calls
declare_task_failedwith a description of the failure - Workflow execution immediately terminates
- The run is marked with status
task_failed(shown in the dashboard as Task Failed) - No trajectory is saved (the run is not cached)
- The failure reason is recorded for debugging
Think of
task_failed as a terminal run outcome, not an infrastructure crash. Cyberdesk still keeps the run’s message history and failure reason, and you can retry that run later from the Runs UI or API. The part that is discarded is the pending trajectory cache for that failed path.task_failed is reserved for explicit declare_task_failed calls. Other failure paths (for example infrastructure or unexpected execution errors) continue using status error.You can filter runs by this status using the Runs list
status=task_failed filter.When to Use Declare Task Failed
1. Authentication Errors
2. Missing Critical Data
3. System Unavailability
4. Business Rule Violations
How to Prompt for Task Failure
Best Practices
- Be Specific: Clearly define what constitutes a failure
- Provide Context: Explain why this is a failure condition
- Include Messages: Specify what message to include when failing
- Set Boundaries: Define how many attempts before failing
- Consider Timing: Specify timeouts for time-sensitive operations
Prompt Template
Real-World Examples
Healthcare: Patient Safety
Finance: Compliance Checks
E-commerce: Inventory Management
IT Operations: Deployment Safety
Common Failure Patterns
Multiple Attempt Failures
Timeout Conditions
Validation Failures
Permission Denials
Failure vs. Recovery Strategies
When to Fail vs. Retry
- Use declare_task_failed
- Retry/Recover
Cascading Failures
Integration with Other Tools
With Focused Action
With Terminal Commands
Conditional Workflow Paths
Advanced Usage
Complex Failure Conditions
Partial Success Handling
Pre-flight Checks
Best Practices Summary
- Define clear, specific failure conditions
- Fail fast when recovery is impossible
- Include descriptive failure messages
- Don’t use for recoverable errors
- Consider the business impact of failing vs. continuing
- Set reasonable retry limits before failing
- Document why each failure condition exists
- Test failure scenarios to ensure proper handling