Skip to main content
Skyvern lets you make your agents and tasks handle errors gracefully instead of failing silently. Every run returns a status. When it’s not completed, you need to know what went wrong and respond programmatically. The flow is:
  1. Check status to detect failure states
  2. Read failure_reason to get the raw error description
  3. Set up error_code_mapping to map failures to your own error codes
  4. Respond in code to branch your logic based on the error code
This page covers each step with exact field locations and full code examples.

Step 1: Check status

Every run transitions through these states: Terminal states: completed, failed, terminated, timed_out, canceled You can detect failures in two ways:
  1. by polling get_run
  2. by checking the webhook payload
Both contain the same status field.
The status field is at the top level of both responses.

For tasks

Poll get_run until the status is terminal:

For agents

Same polling pattern works for agent runs:
failed vs terminated: A failed run hit infrastructure problems, so retry might work. A terminated run means the AI recognized the goal is unachievable with current conditions. Retrying without changes (new credentials, different URL) will produce the same result.

Step 2: Read failure_reason

When a run fails or terminates, the failure_reason field contains a description of what went wrong. This is a free-text string, useful for logging but hard to branch on programmatically. The field is available in both the polling response and webhook payload:

For tasks

For agents


Step 3: Use error_code_mapping

failure_reason contains an AI-generated description of what went wrong. Define custom error codes to get consistent, actionable error messages. When the run fails, Skyvern evaluates your natural language error descriptions against the page state and returns the matching code. How it works: The error_code_mapping values are LLM-evaluated descriptions, so you don’t need exact string matches. For example, "The login credentials are incorrect" will match pages showing “Invalid password”, “Wrong username”, “Authentication failed”, etc.

In tasks

Pass error_code_mapping as a parameter to run_task:

In agents

Add error_code_mapping to individual blocks (navigation, task, validation):
The JSON examples below include comments (//) for clarity. Remove comments before using in actual agent definitions; JSON does not support comments.

Where the error code appears

When a mapped error occurs, your code appears in output.error. This field is available in both polling responses and webhook payloads:
Both output.error (your code) and failure_reason (raw text) are present. Use output.error for branching, failure_reason for logging. Quick reference: Where error codes appear

Step 4: Respond in code

Now you can write clean switch/match logic:

Validation blocks as assertions

Validation blocks are assertions that check conditions at critical points, like unit test assertions. If validation fails, the agent terminates immediately with your error code instead of continuing and failing later with a confusing error. Use validation blocks after steps where you need to confirm success before proceeding:
If verify_login sees a login error, the agent terminates with output.error = "login_failed". Your Step 4 code handles it the same way as any other error code.

Common error patterns


Next steps

Reliability Tips

Write prompts that fail less often

Webhooks

Get notified when runs complete or fail