Skip to main content

Snapshot Resolver

The snapshot resolver defines the current system or business state available during policy evaluation in the Actra Python SDK.

It is the runtime bridge between Actra and your external state sources such as databases, caches, fraud engines, workflow systems, and deployment controls.

The resolver is configured using the real Python runtime API:

runtime.set_snapshot_resolver(
lambda ctx: {
"is_locked": ctx.account.locked,
}
)

This behavior maps directly to ActraRuntime.set_snapshot_resolver() and resolve_snapshot() from the Python SDK runtime implementation.


Core Mental Model

Snapshot = current world state at decision time

Typical snapshot data includes:

  • account lock status
  • balance
  • quota usage
  • deployment environment state
  • approval status
  • workflow stage
  • fraud flags
  • ownership

Policies reference these fields using the snapshot domain.

subject:
domain: snapshot
field: is_locked

Basic Resolver

The most common Python pattern maps business state from an already loaded context.

runtime.set_snapshot_resolver(
lambda ctx: {
"is_locked": ctx.account.locked,
"balance": ctx.account.balance,
"tier": ctx.account.tier,
}
)

Ideal for:

  • account controls
  • payment approvals
  • tenant plans
  • feature access

Database-backed Snapshot

A common Python service pattern is attaching DB-loaded state to request context.

runtime.set_snapshot_resolver(
lambda request: {
"order_status": request.order.status,
"owner_id": request.order.owner_id,
"total": request.order.total,
}
)

Best for:

  • order systems
  • resource ownership
  • document lifecycle
  • workflow routing

Redis / Cache Flags

Excellent for fast-moving operational controls.

runtime.set_snapshot_resolver(
lambda ctx: {
"is_fraud_suspected": ctx.flags.fraud,
"quota_exceeded": ctx.flags.quota_exceeded,
}
)

Useful for:

  • fraud systems
  • rate limits
  • quota enforcement
  • emergency kill switches

Deployment Safety Checks

A very strong Python DevOps governance use case.

runtime.set_snapshot_resolver(
lambda deploy_ctx: {
"environment_locked": deploy_ctx.prod_locked,
"active_incident": deploy_ctx.incident_open,
}
)

Great for:

  • CI/CD gates
  • production deploy safety
  • freeze windows
  • incident response

Workflow & Approval State

Perfect for multi-step business processes.

runtime.set_snapshot_resolver(
lambda workflow_ctx: {
"approval_stage": workflow_ctx.stage,
"already_approved": workflow_ctx.is_approved,
}
)

Ideal for:

  • finance approvals
  • HR workflows
  • procurement chains
  • release pipelines

Missing Resolver Behavior

If no snapshot resolver is configured, the Python runtime safely falls back to:

{}

This is safe, but most production policies should provide snapshot state for meaningful governance.


Best Practices

Keep snapshot state-focused

Use snapshot for:

  • balances
  • ownership
  • lifecycle stage
  • approval status
  • environment safety

Avoid caller identity here.


Prefer read-only state

Snapshot should represent the current state of the world, not mutable request intent.


Avoid duplicating actor fields

Use:

  • actor → who is calling
  • action → what is attempted
  • snapshot → current state

This keeps rules auditable and easy to reason about.


Production Mental Model

DB / Cache / Workflow / Deploy State
-> Resolve snapshot
-> Build state object
-> Runtime evaluation

This is how the Python SDK reasons about the world before execution.


Next Steps

Recommended next Python SDK pages:

  • Explain & Debugging
  • Testing Policies
  • Observability & Audit
  • Actor Resolver
  • Context Resolver