For AI agents: the complete documentation index is available at https://flow.jig.md/llms.txt, the full documentation bundle is available at https://flow.jig.md/llms-full.txt, and this page is available as Markdown at https://flow.jig.md/build/outcomes.md.
DocumentationBuildPrerelease

#Handle outcomes and failures

View Markdown

A method can finish successfully and tell its caller that a person must decide what happens next. Use a domain outcome for that answer. Use an operational error when the invocation cannot perform its declared work.

This guide extends the illustrative request classifier. Its manual suggestion becomes a declared needs-review outcome. The application retains responsibility for the next action.

#Declare a domain outcome

Save this as flows/classify-request/FLOW.contract.json:

{
  "$schema": "https://flow.jig.md/schemas/invocation-contract-0.schema.json",
  "outcomes": {
    "needs-review": "A person must choose the request's queue."
  }
}

The descriptor declares the additional normal outcome. done remains available implicitly. An anonymous descriptor is sufficient for this local declaration.

Replace the classifier's final return with:

return {
  outcome: queue === "manual" ? "needs-review" : "done",
  output: { queue },
};

Review the source and run a message the rules cannot classify:

jig review --allow-resolution-network
jig run flow:flows/classify-request --input '{"message":"Please help."}' --json

The host reports successful execution with this method result:

{"outcome":"needs-review","output":{"queue":"manual"}}

The method completed its job by reporting the need for review. It has neither selected a team nor changed the customer's account.

#Handle the answer at the caller

Inside a Flow, run.call() returns domain outcomes as ordinary result data:

const result = await run.call({
  operationId: "classify:1",
  slot: "classifier",
  input: run.input,
});
if (result.outcome === "needs-review") {
  console.error("The request needs a person's judgment.");
}

Decide how your own method handles each accepted outcome. Declare any custom outcome you forward in your own descriptor. Returning the child's data alone loses the meaning supplied by its outcome.

At an application boundary, first check the host's execution and cleanup status. Then branch on the method outcome before using its output. The application tutorial shows the public client exchange.

#Preserve operational failure

The classifier raises INVALID_INPUT when message has the wrong type. A missing dependency can produce UNAVAILABLE. Such failures reject the SDK call with OperationError.

ObservationCaller response
Successful execution with doneCheck and use the output.
Successful execution with needs-reviewPresent or retain the request for the required decision.
Operational errorHandle the reported failure and its cause.
Cancellation or uncertain executionInspect the host's evidence before deciding what work may safely start.

Test the invalid-input path with {"message":12}. It should fail rather than return a successful queue suggestion. Keep operational errors visible instead of converting every exception into done.

Use cancellation-aware work and finally blocks for resources your method owns. The host owns deadline enforcement and execution settlement. Cancellation alone leaves previously dispatched external effects subject to their actual state.

Next, validate the values that cross the method boundary.