Error hooks let you run code whenever a workflow, activity (step/evaluator), or runtime error occurs. Use them for logging, metrics, or alerting. When an error is emitted, all registered handlers are triggered at the same time (concurrently). Handler code is invoked asynchronously and never throws — any error in your handler is caught and logged by the framework.Documentation Index
Fetch the complete documentation index at: https://docs.output.ai/llms.txt
Use this file to discover all available pages before exploring further.
Setup
1. Create a hook file
Create a file that registers your handler. ImportonError from @outputai/core/hooks.
2. Register the file in package.json
List your hook file(s) underoutput.hookFiles. Paths are relative to the package root. The worker loads these files at startup.
"hookFiles": ["./src/error_hooks.js", "./src/other_hooks.js"].
The three sources
Errors are emitted from three origins. Every payload includessource and error. Activity- and workflow-scoped errors also include stable ids and names for the run and workflow.
| Source | When it fires | Fields besides source and error |
|---|---|---|
activity | A step or evaluator fails (after retries are exhausted). | activityId, activityName, workflowId, workflowName |
workflow | The workflow function itself throws (e.g. uncaught step error or logic error). | workflowId, workflowName |
runtime | An error outside workflow/activity scope (e.g. in the worker/runtime). | — |
- Activity —
source: 'activity',activityId,activityName,workflowId,workflowName,error. - Workflow —
source: 'workflow',workflowId,workflowName,error(no activity fields). - Runtime —
source: 'runtime'anderroronly.
source to branch in one handler, or ignore payload fields that are undefined for that source.
Handler safety: no throws
Your handler is wrapped in a try/catch. If the handler throws or rejects, the framework catches it, logs it (e.g.onError hook error with the error), and does not rethrow. Execution of the workflow and worker continues. You can focus on side effects (logging, metrics, alerts) without worrying about breaking the run.