# `ToolCall.Audit`

Dispatch audit hooks.

A policy is a module implementing `record/1`. Configure it with
`use ToolCall, audit: Policy` or `run/4 audit: Policy`; `audit: nil` disables
a module policy for one call. `record/1` receives a
`%ToolCall.Audit.Entry{}` once per dispatch attempt, including resolve
failures, approvals, timeouts, raises and resolve/execute policy exceptions.

This is a hook, not a log store: the application persists the entry, applies
redaction and retention, and decides whether a failed audit is fatal. The
library calls the hook synchronously and ignores an exception it raises, so
a broken audit does not change the tool result. A policy module without
`record/1` is a configuration error and raises `ArgumentError` before the
hook runs. The raw `args` and `context` are passed through; redact them in
`record/1` when they contain secrets.

# `outcome`

```elixir
@type outcome() ::
  :ok
  | :error
  | :raised
  | :pending
  | :denied
  | :timeout
  | :invalid_arguments
  | :unknown_tool
```

# `record`

```elixir
@callback record(ToolCall.Audit.Entry.t()) :: term()
```

# `entry`

```elixir
@spec entry(module(), String.t(), term(), term(), outcome(), keyword()) ::
  ToolCall.Audit.Entry.t()
```

Builds the entry passed to `c:record/1`.

`outcome` is one of the `t:outcome/0` values; `opts` accepts
`:duration_us`, `:error`, `:approval_request_id` and `:timeout`.
Custom dispatchers call this when they bypass `ToolCall.run/4`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
