Adapters & Exporters¶
Exporters¶
Exporters receive every ActionRecord after evaluation and route it to your observability stack.
StdoutExporter (default)¶
Logs to stdout in a structured format. Active by default — useful during development.
from plyra_guard.exporters import StdoutExporter
guard = ActionGuard(exporters=[StdoutExporter(level="INFO")])
Disable by passing an empty list:
OtelExporter¶
Ships actions as OpenTelemetry spans.
from plyra_guard.exporters import OtelExporter
guard = ActionGuard(exporters=[
OtelExporter(endpoint="http://localhost:4317")
])
DatadogExporter¶
Ships actions as Datadog custom events.
from plyra_guard.exporters import DatadogExporter
guard = ActionGuard(exporters=[
DatadogExporter(service="my-agent", env="production")
])
SidecarExporter¶
Streams actions to the local dashboard sidecar.
from plyra_guard.exporters import SidecarExporter
guard = ActionGuard(exporters=[
SidecarExporter(url="http://localhost:8765")
])
Multiple Exporters¶
guard = ActionGuard(exporters=[
StdoutExporter(),
OtelExporter(endpoint="http://otel-collector:4317"),
SidecarExporter(),
])
Custom Exporter¶
Implement the Exporter protocol:
from plyra_guard.exporters import Exporter
from plyra_guard.models import ActionRecord
class MyExporter(Exporter):
def export(self, action: ActionRecord) -> None:
# your logic here
my_db.insert(action.model_dump())
Exceptions¶
PolicyViolationError¶
Raised when a wrapped tool call is blocked.
from plyra_guard.exceptions import PolicyViolationError
try:
delete_file("/etc/passwd")
except PolicyViolationError as e:
print(e.reason) # "System config is off-limits"
print(e.rule_name) # "protect-system"
print(e.intent) # "/etc/passwd"
ActionGuardExecutionError¶
Raised in CrewAI context (subclass of PolicyViolationError). Same fields.