AgentSea.Guardrails (agentsea_guardrails v0.1.0)

Copy Markdown

Run a pipeline of AgentSea.Guardrails over text. Apply it to user input before AgentSea.Agent.run/3 and/or to the agent's output before returning:

case AgentSea.Guardrails.run(user_input, [
       {AgentSea.Guardrail.MaxLength, max: 2000},
       {AgentSea.Guardrail.Blocklist, terms: ["ignore previous instructions"]},
       AgentSea.Guardrail.PIIRedactor
     ]) do
  {:ok, safe} -> AgentSea.Agent.run(agent, safe)
  {:block, {guardrail, reason}} -> {:error, {:blocked, guardrail, reason}}
end

Guardrails run in order. A {:transform, _} updates the content seen by later guardrails; the first {:block, _} short-circuits.

Summary

Types

guardrail()

@type guardrail() :: module() | {module(), keyword()}

Functions

run(content, guardrails)

@spec run(String.t(), [guardrail()]) ::
  {:ok, String.t()} | {:block, {name :: String.t(), reason :: term()}}