PikarcBlockedError
When Pikarc denies a run start, model call, or tool call, the SDK raisesPikarcBlockedError. 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
Whenguard.run() is entered, Pikarc evaluates all 6 rules. If denied, the async with block is never entered:
At step creation
Whenrun.model_call() or run.tool_call() is called, rules 1-4 are re-evaluated. If denied, fn is never called:
HTTP Errors
The SDK useshttpx under the hood. Network errors or non-2xx responses from the Pikarc API will raise httpx.HTTPStatusError:
Best Practices
- Always catch
PikarcBlockedError— it’s expected behavior, not a bug. Return a user-friendly message. - Always call
guard.close()— use afinallyblock or async context manager to clean up the HTTP client. - Catch at the right level — catch around
guard.run()for run-start denials, or around individualmodel_call()/tool_call()for step-level denials. - Log the deny reason —
e.deny_reasontells you exactly which guardrail triggered. Use it for monitoring and alerting.