Skip to main content

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
Without declare_task_failed, the agent might spend excessive time trying to work around insurmountable obstacles.

How It Works

  1. The agent encounters a condition you’ve defined as a failure
  2. It calls declare_task_failed with a description of the failure
  3. Workflow execution immediately terminates
  4. The run is marked with status task_failed (shown in the dashboard as Task Failed)
  5. No trajectory is saved (the run is not cached)
  6. The failure reason is recorded for debugging
Important: Once declare_task_failed is called, the workflow stops immediately. This tool is never cached because failed runs don’t create trajectories.
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

  1. Be Specific: Clearly define what constitutes a failure
  2. Provide Context: Explain why this is a failure condition
  3. Include Messages: Specify what message to include when failing
  4. Set Boundaries: Define how many attempts before failing
  5. 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

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

  1. Define clear, specific failure conditions
  2. Fail fast when recovery is impossible
  3. Include descriptive failure messages
  4. Don’t use for recoverable errors
  5. Consider the business impact of failing vs. continuing
  6. Set reasonable retry limits before failing
  7. Document why each failure condition exists
  8. Test failure scenarios to ensure proper handling

Common Mistakes to Avoid

Don’t use declare_task_failed for:
  • Temporary UI delays (use wait/retry instead)
  • Minor data variations (use focused_action to adapt)
  • Recoverable errors (implement retry logic)
  • Success scenarios (even if no action needed)

❌ Incorrect Usage

✅ Correct Usage