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.
Summary
Types
@type context() :: %{ optional(:actor) => LLMProxy.Actor.t(), optional(:api_key) => map(), optional(:route) => atom(), optional(:model) => String.t(), optional(:provider) => module(), optional(:provider_name) => String.t() | nil, optional(:trace_id) => String.t(), optional(:cache_key) => String.t(), optional(:metadata) => map() }
Callbacks
@callback after_response(LLMProxy.Response.t(), context()) :: {:ok, LLMProxy.Response.t()} | {:error, term()}
@callback before_request(LLMProxy.Protocol.Request.t(), context()) :: {:ok, LLMProxy.Protocol.Request.t()} | {:error, term()}
@callback on_stream_event(LLMProxy.Stream.Event.t(), context()) :: {:ok, LLMProxy.Stream.Event.t() | nil} | {:error, term()}