Skip to main content

ActionGuard

The main entry point. Assembles the evaluation pipeline, audit log, rollback system, and multi-agent trust ledger.

Constructor

GuardConfig | None
A GuardConfig Pydantic model. If None, uses GuardConfig() defaults.

ActionGuard.default()

Create an instance with sensible defaults. No config file needed — good for quick starts and testing.

ActionGuard.from_config()

Create an instance from a YAML config file.
str
required
Path to a YAML configuration file.
ActionGuard
A configured ActionGuard instance.

guard.protect()

Decorator to protect a function with ActionGuard.
str
required
Hierarchical action descriptor (e.g. "file.delete", "db.execute").
RiskLevel
default:"RiskLevel.MEDIUM"
Baseline risk level for this action. One of LOW, MEDIUM, HIGH, CRITICAL.
bool
default:"True"
Whether to capture a snapshot before execution for rollback support.
list[str] | None
default:"None"
Optional tags for categorization and filtering.
Callable
Decorator function. The wrapped function gains _plyra_guard_protected = True.

guard.wrap()

Wrap framework-native tools with ActionGuard protection. Auto-detects the framework and routes to the appropriate adapter.
list[Any]
required
List of framework-native tool objects (LangChain tools, plain functions, etc.).
list[Any]
Wrapped tools in their native format.
Do not use guard.wrap() with LangGraph. See framework integrations for the required pattern.

guard.evaluate()

Evaluate an ActionIntent without executing (dry-run).
ActionIntent
required
The action to evaluate.
EvaluatorResult
The final result with the most restrictive verdict from all evaluators.

guard.evaluate_async()

Async version. Runs the evaluation pipeline in a thread to avoid blocking the event loop.

guard.explain()

Run the full evaluation pipeline in dry-run mode and return a rich, human-readable explanation string. Never executes the action.
ActionIntent
required
The action to explain.
str
Human-readable explanation of which evaluators ran and why.

guard.explain_async()

Async version of explain().

guard.get_audit_log()

Query the audit log with optional filters.
AuditFilter | None
default:"None"
Optional filter criteria. If None, returns all entries up to the default limit.
list[AuditEntry]
Matching audit entries, newest first.

guard.get_metrics()

Get a snapshot of aggregate metrics.
GuardMetrics
Aggregate statistics for all actions evaluated by this guard instance.

guard.add_exporter()

Register an audit log exporter. Exporters receive every AuditEntry as it is written.
Any
required
An object implementing export(entry: AuditEntry) -> None.

guard.register_agent()

Register an agent with a trust level for multi-agent systems.
str
required
Unique agent identifier.
TrustLevel
required
Trust classification for this agent.

guard.rollback()

Roll back a single action by its ID.
str
required
The action_id from an ActionIntent or AuditEntry.
bool
True if rollback succeeded.

guard.rollback_last()

Roll back the last N actions.
int
default:"1"
Number of actions to roll back.
str | None
default:"None"
Optionally filter to one agent.
list[bool]
Per-action rollback results.

guard.rollback_task()

Roll back all actions for a task across all agents.
str
required
The task identifier.
RollbackReport
Summary with task_id, total_actions, rolled_back, failed, skipped lists.

guard.serve()

Start the HTTP sidecar server (dashboard + REST API).
str
default:"\"0.0.0.0\""
Bind address.
int
default:"8080"
Port number.
Requires pip install "plyra-guard[sidecar]". Raises ImportError if FastAPI or uvicorn are not installed.

Data classes

ActionIntent

The primary data structure that flows through the evaluation pipeline.

EvaluatorResult

The output of a single evaluator in the pipeline.

AuditEntry

Immutable audit record written for every action evaluated.

AuditFilter

Filter criteria for querying the audit log.

GuardMetrics

Prometheus-style metrics snapshot.

RollbackReport

Summary of a batch rollback operation. Property: report.successTrue if no failures and at least one rollback.

AgentCall

One hop in a multi-agent delegation chain.

Enums

Verdict

Helper methods:
  • verdict.is_permissive()True for ALLOW and WARN
  • verdict.is_blocking()True for BLOCK, ESCALATE, and DEFER

RiskLevel

Helper: risk_level.base_score() → returns the float value.

TrustLevel

Helper: trust_level.score() → returns the float value.

Exceptions

All exceptions inherit from ActionGuardError.

Execution exceptions

Policy exceptions

Config exceptions

Budget and rate limit exceptions

Other exceptions

Structured error messages

All blocking exceptions (ExecutionBlockedError, ActionEscalatedError, RateLimitExceededError, BudgetExceededError, TrustViolationError, CascadeDepthExceededError, ActionDeferredError) provide three structured fields:
  • what_happened — clear plain-English description
  • policy_triggered — name of the policy or evaluator
  • how_to_fix — concrete, actionable steps

Environment variables


Configuration schema

The YAML config file maps to the GuardConfig Pydantic model: