Skip to main content
ActionContext is a dataclass that captures everything Attesta needs to know about a single function invocation. The @gate decorator builds it automatically from the wrapped call, but you can also construct one manually for programmatic use with Attesta.evaluate().

Import

Fields

Construction

Automatic (via @gate)

When you use the @gate decorator, ActionContext is built automatically from the live function call. The decorator populates function_name from __qualname__, extracts the docstring with inspect.getdoc(), and captures the source code with inspect.getsource().

Manual Construction

For framework integrations (LangChain, MCP, etc.) or testing, construct ActionContext directly.

description Property

A computed property that returns a human-readable one-liner describing the function call, formatted as function_name(arg1, key=val).
The description property is used throughout Attesta:
  • Audit logs — as the action_description field in every audit entry
  • Terminal UI — displayed to the operator during challenges
  • Error messages — included in AttestaDenied exception messages
  • Logging — used in debug and info log lines

How Fields Influence Risk Scoring

The DefaultRiskScorer analyzes ActionContext fields across five weighted factors:
The environment field is checked separately from the hint-based scoring. Setting environment="production" adds +0.3 to the base risk score in the default scorer, in addition to any hint contributions.

Hints Reference

The hints dict is a flexible mechanism for caller-supplied risk metadata. The default risk scorer recognizes these patterns:
Boolean hint contributions are additive. Three True boolean hints (production, destructive, pii) would contribute 0.90 to the hints factor alone, which when weighted at 0.15 adds 0.135 to the overall score. Combined with a destructive function name, this can easily push into CRITICAL territory.

Serialization

ActionContext is a standard Python dataclass. You can convert it to a dictionary using dataclasses.asdict():
Python
The timestamp field contains a datetime object. If you need JSON serialization, convert it to an ISO 8601 string first: data["timestamp"] = data["timestamp"].isoformat().