# `LLMProxy.Guardrail`
[🔗](https://github.com/elixir-vibe/llm_proxy/blob/v0.3.1/lib/llm_proxy/guardrail.ex#L1)

Behaviour for host-defined request/response policy hooks.

Guardrails are configured with:

    config :llm_proxy, guardrails: [MyApp.LLMPolicy]

Callbacks run in order. They should be deterministic and side-effect-light.

# `context`

```elixir
@type context() :: %{
  optional(:actor) =&gt; LLMProxy.Actor.t(),
  optional(:api_key) =&gt; map(),
  optional(:route) =&gt; atom(),
  optional(:model) =&gt; String.t(),
  optional(:provider) =&gt; module(),
  optional(:provider_name) =&gt; String.t() | nil,
  optional(:trace_id) =&gt; String.t(),
  optional(:cache_key) =&gt; String.t(),
  optional(:metadata) =&gt; map()
}
```

# `after_response`
*optional* 

```elixir
@callback after_response(LLMProxy.Response.t(), context()) ::
  {:ok, LLMProxy.Response.t()} | {:error, term()}
```

# `before_request`
*optional* 

```elixir
@callback before_request(LLMProxy.Protocol.Request.t(), context()) ::
  {:ok, LLMProxy.Protocol.Request.t()} | {:error, term()}
```

# `on_stream_event`
*optional* 

```elixir
@callback on_stream_event(LLMProxy.Stream.Event.t(), context()) ::
  {:ok, LLMProxy.Stream.Event.t() | nil} | {:error, term()}
```

---

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