Skip to main content

PikarcBlockedError

When Pikarc denies a run start, model call, or tool call, the SDK raises PikarcBlockedError. This happens before your function executes — no tokens are consumed, no tools are invoked.

Attributes

Deny Reason Codes

Where Denials Can Happen

At run start

When guard.run() is entered, Pikarc evaluates all 6 rules. If denied, the async with block is never entered:

At step creation

When run.model_call() or run.tool_call() is called, rules 1-4 are re-evaluated. If denied, fn is never called:

HTTP Errors

The SDK uses httpx under the hood. Network errors or non-2xx responses from the Pikarc API will raise httpx.HTTPStatusError:

Best Practices

  1. Always catch PikarcBlockedError — it’s expected behavior, not a bug. Return a user-friendly message.
  2. Always call guard.close() — use a finally block or async context manager to clean up the HTTP client.
  3. Catch at the right level — catch around guard.run() for run-start denials, or around individual model_call()/tool_call() for step-level denials.
  4. Log the deny reasone.deny_reason tells you exactly which guardrail triggered. Use it for monitoring and alerting.