Skip to content
Last updated

Success criteria and failure handling

In Arazzo, successCriteria define when a step succeeds, and onFailure defines what happens when a step fails. This guide shows how to configure both with Warp API examples.

Defining successCriteria

The successCriteria field lists the conditions, typically runtime expressions, that must all pass for a step to succeed.

Here's a basic check for Warp's timeTravel:

steps:
  - stepId: "jumpTo1889"
    operationId: "warpApi.timeTravel"
    requestBody:
      payload:
        destination: "tml_tesla_mission_1"
    successCriteria:
      - condition: "$statusCode == 200"

How it works

  • $statusCode: A runtime expression grabbing the HTTP response code.
  • == 200: Verifies that the request returned a 200 OK status code.

You can add multiple conditions to a single step. This example also checks the arrival time:

successCriteria:
  - condition: "$statusCode == 200"
  - condition: "$response.body#/arrival_time == '1889-03-10T23:50:00Z'"

Both conditions must pass, or the step fails and triggers onFailure. You can also use JSONPath for nested response checks:

successCriteria:
  - condition: "$statusCode == 200"
  - condition: "$[?length(@.items_transported) > 0]"
    context: "$response.body"
    type: "jsonpath"

This confirms we brought back Tesla's blueprint (items_transported isn't empty). A JSONPath condition is an RFC 9535 filter expression that's applied to the context. The condition passes when the filter selects at least one value. Write $[?@.is_stable == true], not $.is_stable == true.

Configuring onFailure

When a step fails (for example, because Warp's servers are overloaded or your token expired), Arazzo runs the actions in onFailure. This optional field supports three action types:

  • end: Abort the workflow immediately.
  • retry: Try the step again, with limits.
  • goto: Jump to another step or workflow as a backup plan.

Configuring onSuccess

When a step succeeds, Arazzo runs the actions in onSuccess. This optional field supports two action types:

  • end: Stop the workflow immediately.
  • goto: Jump to another step or workflow.

Exit on failure

For a must-succeed step like setting an anchor:

- stepId: "setHomeAnchor"
  operationId: "warpApi.setAnchor"
  requestBody:
    payload:
      timestamp: "2025-02-19T12:00:00Z"
      description: "Home base"
  successCriteria:
    - condition: "$statusCode == 201"
  onFailure:
    - name: "exitOnFailure"
      type: "end"

If setting the anchor doesn't return 201 Created, the workflow stops immediately.

Retry on failure

For a flaky jump that might time out (e.g., 503):

- stepId: "jumpTo1889"
  operationId: "warpApi.timeTravel"
  requestBody:
    payload:
      destination: "tml_tesla_mission_1"
  successCriteria:
    - condition: "$statusCode == 200"
  onFailure:
    - name: "retryOnTimeout"
      type: "retry"
      retryLimit: 3
      retryAfter: 5
      criteria:
        - condition: "$statusCode == 503"

This retries the step up to 3 times, waiting 5 seconds between attempts, to handle temporary server errors.

Goto another step

For an unauthorized jump (401), go to a re-authentication step:

- stepId: "jumpTo1889"
  operationId: "warpApi.timeTravel"
  requestBody:
    payload:
      destination: "tml_tesla_mission_1"
  successCriteria:
    - condition: "$statusCode == 200"
  onFailure:
    - name: "reAuthOn401"
      type: "goto"
      stepId: "reAuth"
      criteria:
        - condition: "$statusCode == 401"
- stepId: "reAuth"
  operationId: "warpApi.someAuthOperation"  # Hypothetical endpoint
  outputs:
    newToken: $response.body#/token

If the jump fails with a 401, the workflow goes to the reAuth step to refresh the token. From there, you loop back manually or adjust the workflow.

Practical examples

Handling timeouts

Warp's monitorTimeline might time out (503). Retry, then give up:

- stepId: "monitorJump"
  operationId: "warpApi.monitorTimeline"
  parameters:
    - in: query
      name: timeline_id
      value: "tml_tesla_mission_1"
  successCriteria:
    - condition: "$statusCode == 200"
  onFailure:
    - name: "retryOnTimeout"
      type: "retry"
      retryLimit: 3
      retryAfter: 10
      criteria:
        - condition: "$statusCode == 503"
    - name: "exitOnMaxRetries"
      type: "end"
      criteria:
        - condition: "$retryCount >= 3"

After 3 failed attempts, the workflow exits.

Unauthorized responses

For a 401 on checkParadox:

- stepId: "checkStability"
  operationId: "warpApi.checkParadox"
  requestBody:
    payload:
      timeline_id: "tml_tesla_mission_1"
      proposed_changes:
        - event: "Retrieve Tesla's blueprint"
          time: "1889-03-10T23:50:00Z"
  successCriteria:
    - condition: "$statusCode == 200"
    - condition: "$[?@.adam_stable == true]"
      context: "$response.body"
      type: "jsonpath"
  onFailure:
    - name: "logOn401"
      type: "goto"
      stepId: "logIssue"
      criteria:
        - condition: "$statusCode == 401"
- stepId: "logIssue"
  operationId: "warpApi.someLogOperation"  # Hypothetical logging endpoint
  requestBody:
    payload:
      message: "Unauthorized paradox check"

If authorization fails, the workflow goes to the logIssue step to log the issue.

Tips

  • Start simple: Use $statusCode checks first, then add response body conditions.
  • Match reality: Test successCriteria against actual Warp API responses (e.g., does adam_stable exist?).
  • Handle critical failures: Add onFailure to any step whose failure should stop, retry, or redirect the workflow.
  • Tune retries: Set retryLimit and retryAfter based on your API's behavior (Warp's docs suggest timeouts are rare but possible).