> For the complete documentation index, see [llms.txt](https://docs.zenml.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zenml.io/kitaru/guides/error-handling.md).

# Error Handling

Kitaru exposes a typed exception hierarchy so you can distinguish usage, context, state, runtime, backend, and execution failures.

## Core exception types

```python
import kitaru

try:
    result = my_flow.run(...).get()
except kitaru.KitaruUserCodeError as exc:
    # user checkpoint/flow code raised
    print(exc.exec_id, exc.status, exc.failure_origin)
except kitaru.KitaruDivergenceError:
    # replay divergence surfaced from backend contract
    ...
except kitaru.KitaruExecutionError:
    # other execution-level failure
    ...
```

## Wait-input validation failures

`client.executions.input(...)` raises `kitaru.KitaruWaitValidationError` when supplied input does not satisfy the wait schema.

```python
try:
    client.executions.input(exec_id, wait="approve_deploy", value="yes")
except kitaru.KitaruWaitValidationError as exc:
    print(exc)
```

When validation fails, the execution remains in `waiting`.

## Failure journaling in the client

`KitaruClient` surfaces structured failure details:

* `execution.failure`: failure summary for failed executions
* `checkpoint.failure`: final checkpoint failure (if terminal attempt failed)
* `checkpoint.attempts`: full retry attempt history, including failed attempts

```python
client = kitaru.KitaruClient()
execution = client.executions.get(exec_id)

if execution.failure:
    print(execution.failure.origin, execution.failure.message)

for checkpoint in execution.checkpoints:
    for attempt in checkpoint.attempts:
        print(attempt.attempt_id, attempt.status)
        if attempt.failure:
            print("  ", attempt.failure.exception_type, attempt.failure.message)
```

## Replay divergence behavior

`client.executions.replay(...)` may fail immediately with `kitaru.KitaruDivergenceError` when the backend detects an incompatible durable call sequence.

Even when replay submission succeeds, divergence can still surface later on the replayed execution as normal execution failure metadata:

```python
replayed = client.executions.replay(exec_id, from_="write_draft")
latest = replayed.refresh()

if latest.failure and latest.failure.origin == kitaru.FailureOrigin.DIVERGENCE:
    print("Replay divergence:", latest.failure.message)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zenml.io/kitaru/guides/error-handling.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
