@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 anAttestaDenied exception. The protected function is never executed.
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 thanrisk= because the scorer combines them with other factors.
With the Attesta Instance
When using anAttesta 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 usingfunctools.wraps (Python) or generics (TypeScript). Type checkers see the correct parameter and return types through the wrapper.
Python