Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                

Getting started

Install

Bash

pip install whitecircle   # or: uv add whitecircle

Python 3.11+.

Before the first check

In the dashboard, create a Policy (at least one flagged rule), an Environment, and an active Condition that attaches the Policy to the Environment. An empty Condition expression matches every Event. Then create an API key under Settings → API keys: EU keys start with wceu-, US keys with wc-. Policies and Conditions can also be created in code, see Managing Policies.

Configure the client

Bash

export WHITECIRCLE_API_KEY=wceu-...
export WHITECIRCLE_ENVIRONMENT_ID=env_...

Python

from whitecircle import WhiteCircle

client = WhiteCircle()
client = WhiteCircle(api_key="wceu-...", environment_id="env_prod", region="eu")

The host comes from base_url, then region, then WHITECIRCLE_BASE_URL, then WHITECIRCLE_REGION, then the key prefix. An unknown prefix with no region raises WhiteCircleError.

Events and run-graph calls need an Environment. Pass environment_id= to override the client default for one call; with neither, the call raises ValueError:

Python

from whitecircle import Event, WhiteCircle

client = WhiteCircle()
client.events.check(Event.user("hello"), environment_id="env_staging")

For several settings at once, make a copy that shares the connection pool:

Python

from whitecircle import WhiteCircle

client = WhiteCircle()
fast = client.with_options(timeout=5.0, max_retries=0)

Check and read the result

Python

from whitecircle import Event, WhiteCircle

client = WhiteCircle()

result = client.events.check(
    Event.user("Hello, can you help me prescribe antibiotics?"),
    external_session_id="conversation_456",
)

result.checked  # a production Policy ran
result.flagged  # True, False, or None when nothing was checked
result.flagged_policies  # {policy_id: PolicyResult} for the violated production Policies
result.policies  # every Policy that ran
result.note  # why there is no verdict, or a skipped inline Policy
result.event.status  # "completed", "failed", "referenced" or "not_found"
result.event.internal_event_id  # store it to fetch the result later

Python

from whitecircle import Event, WhiteCircle

client = WhiteCircle()
result = client.events.check(Event.user("Hello, can you help me prescribe antibiotics?"))
if result.flagged:
    reply = "Sorry, I can't help with that."
elif not result.checked:
    reply = fallback()  # nothing was checked: fail open or closed, your call
else:
    reply = call_your_llm()

Fetch a stored result later:

Python

from whitecircle import WhiteCircle

client = WhiteCircle()
client.events.get("01930000-0000-7000-8000-000000000001")
client.events.get_latest(run_id="run_1", event_id="evt_user_1")

Results are stored a few seconds after the check returns. Until then both lookups raise NotFoundError, and an Event.reference() to that Event comes back with status not_found, so retry after a short wait.

Source on GitHub