Skip to main content
The @gate decorator is the primary user-facing API for protecting function calls with Attesta approval. It intercepts every invocation, scores the risk, presents the appropriate challenge, and either allows or blocks execution.

Calling Styles

The decorator supports three equivalent calling styles:

Parameters

Sync and Async Behavior

The @gate decorator automatically detects whether the wrapped function is synchronous or asynchronous and handles each case correctly.
When a sync function decorated with @gate is called inside an already-running event loop (e.g., Jupyter notebooks), Attesta evaluates in a dedicated worker thread and waits up to sync_timeout seconds. Adjust this value if your approval flow involves long review times.

Denial Behavior

When the operator denies the action, fails a challenge, or the review times out, the decorator raises an AttestaDenied exception. The protected function is never executed.
The three verdicts that trigger AttestaDenied are:

Introspection

Every gated function has a __gate__ attribute attached to it, which holds a reference to the internal CoreAttesta orchestrator instance. This is useful for testing and debugging.

Risk Hints

Risk hints are key-value pairs that influence the risk scorer without hardcoding a risk level. They are more flexible than risk= because the scorer combines them with other factors.
Using risk="critical" bypasses the risk scorer entirely and always assigns CRITICAL risk. Use risk_hints instead when you want to influence the score while still allowing the scorer to consider other factors like function name, arguments, and novelty.

With the Attesta Instance

When using an Attesta instance (recommended for production), the instance-level gate() method inherits defaults from the instance’s policy, risk scorer, renderer, and audit logger. Per-gate overrides take precedence.

Type Signatures

The decorator preserves the original function’s type signature using functools.wraps (Python) or generics (TypeScript). Type checkers see the correct parameter and return types through the wrapper.
Python